Skip to content

Commit e6a3954

Browse files
committed
Add SequencesExt!Snoc and SequencesExt!AllSubSeqs.
1 parent 243fa67 commit e6a3954

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

modules/SequencesExt.tla

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,15 @@ Cons(elt, seq) ==
195195
(************************************************************************)
196196
<<elt>> \o seq
197197

198+
Snoc(elt, seq) ==
199+
(************************************************************************)
200+
(* Reverses the operands of Sequences!Append for better compatibility *)
201+
(* with FoldFunction below. *)
202+
(* Example: *)
203+
(* FoldSeq(LAMBDA x,y: {x} \cup y, {}, <<1,2,1>>) = Range(<<1,2,1>>) *)
204+
(************************************************************************)
205+
Append(seq, elt)
206+
198207
Front(s) ==
199208
(**************************************************************************)
200209
(* The sequence formed by removing its last element. *)
@@ -386,6 +395,21 @@ SubSeqs(s) ==
386395
(**************************************************************************)
387396
{ SubSeq(s, i+1, j) : i, j \in 0..Len(s) }
388397

398+
AllSubSeqs(s) ==
399+
(**************************************************************************)
400+
(* SubSeqs(s) *)
401+
(* \cup *)
402+
(* { subsequences of s, with arbitrarily many elts removed } *)
403+
(* *)
404+
(* Example: *)
405+
(* AllSubSeqs(<<1,2,3,4>>) = *)
406+
(* {<<>>, <<1>>, <<2>>, <<3>>, <<4>>, *)
407+
(* <<1, 2>>, <<1, 3>>, <<1, 4>>, *)
408+
(* <<2, 3>>, <<2, 4>>, <<3, 4>>, *)
409+
(* <<1, 2, 3>>, <<1, 2, 4>>, <<1, 3, 4>>, <<2, 3, 4>>, *)
410+
(* <<1, 2, 3, 4>>} *)
411+
(**************************************************************************)
412+
{ FoldFunction(Snoc, <<>>, [ i \in D |-> s[i] ]) : D \in SUBSET DOMAIN s }
389413

390414
IndexFirstSubSeq(s, t) ==
391415
(**************************************************************************)

tests/SequencesExtTests.tla

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,24 @@ ASSUME \A seq \in BoundedSeq(1..5, 5) :
227227

228228
-----------------------------------------------------------------------------
229229

230+
ASSUME AllSubSeqs(<<>>) = {<<>>}
231+
ASSUME AllSubSeqs(<<1>>) = {<<>>, <<1>>}
232+
ASSUME AllSubSeqs(<<1,1>>) = {<<>>, <<1>>, <<1,1>>}
233+
ASSUME AllSubSeqs(<<1,1,1>>) = {<<>>, <<1>>, <<1,1>>, <<1,1,1>>}
234+
235+
ASSUME AllSubSeqs(<<1,2,3,4>>) = {<<>>, <<1>>, <<2>>, <<3>>, <<4>>,
236+
<<1, 2>>, <<1, 3>>, <<1, 4>>, <<2, 3>>, <<2, 4>>, <<3, 4>>,
237+
<<1, 2, 3>>, <<1, 2, 4>>, <<1, 3, 4>>, <<2, 3, 4>>, <<1, 2, 3, 4>>}
238+
239+
ASSUME AllSubSeqs(<<"a","c","b","d","b">>) =
240+
{ <<>>, <<"d">>, <<"a">>, <<"c">>, <<"b">>,
241+
<<"d","b">>, <<"a","d">>, <<"a","c">>, <<"a","b">>, <<"c","d">>, <<"c","b">>, <<"b","d">>, <<"b","b">>,
242+
<<"a","d","b">>, <<"a","c","d">>, <<"a","c","b">>, <<"a","b","d">>, <<"a","b","b">>, <<"c","d","b">>,
243+
<<"c","b","d">>, <<"c","b","b">>, <<"b","d","b">>, <<"a","c","d","b">>, <<"a","c","b","d">>, <<"a","c","b","b">>, <<"a","b","d","b">>,
244+
<<"c","b","d","b">>, <<"a","c","b","d","b">> }
245+
246+
-----------------------------------------------------------------------------
247+
230248
ASSUME ReplaceFirstSubSeq(<<>>,<<>>,<<>>) = <<>>
231249
ASSUME ReplaceFirstSubSeq(<<4>>,<<>>,<<>>) = <<4>>
232250
ASSUME ReplaceFirstSubSeq(<<4>>,<<4>>,<<>>) = <<>>

0 commit comments

Comments
 (0)