Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion modules/SequencesExt.tla
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,11 @@ Interleave(s, t) ==
ELSE u[i-1] \o << <<s[i]>> >> \o << <<t[i]>> >>
IN Last(u)
\* error "Interleave: sequences must have same length"
[] Len(s) = Len(t) /\ Len(s) = 0 -> << <<>>, <<>> >>
\* <<>> is the identity of \o, which is what the arm above builds the
\* result with, so Len(Interleave(s, t)) = 2 * Len(s) holds for the empty
\* sequence as well. It also matches the other operators of this module
\* on an empty argument, such as Zip, FlattenSeq, and Reverse.
[] Len(s) = Len(t) /\ Len(s) = 0 -> << >>

(**************************************************************************)
(* The set of all subsequences of the sequence s . Note that the empty *)
Expand Down
10 changes: 9 additions & 1 deletion tests/SequencesExtTests.tla
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ ASSUME FlattenSeq(<<"a", "b">>) = "ab"

-----------------------------------------------------------------------------

ASSUME Interleave(<<>>, <<>>) = << <<>>, <<>> >>
ASSUME Interleave(<<>>, <<>>) = << >>
ASSUME Interleave(<< <<>> >>, <<1>>) = << << <<>> >>, <<1>> >>
ASSUME Interleave(<<1>>, << <<>> >>) = << <<1>>, << <<>> >> >>
ASSUME Interleave(<<2>>,<<2>>) = << <<2>>, <<2>> >>
Expand All @@ -184,6 +184,14 @@ ASSUME AssertEq(FlattenSeq(Interleave(<<1,3>>,<<2,4>>)), <<1, 2, 3, 4>>)
ASSUME Interleave(<<"a", "c">>, <<"b", "d">>) = <<<<"a">>, <<"b">>, <<"c">>, <<"d">>>>
ASSUME AssertEq(FlattenSeq(Interleave(<<"a", "c">>, <<"b", "d">>)), <<"a", "b", "c", "d">>)

\* Two entries per position of s, the odd ones from s and the even ones from
\* t. The empty case is the one this used to fail, with a length of 2.
ASSUME \A s \in BoundedSeq(1..3, 3) :
\A t \in {u \in BoundedSeq(1..3, 3) : Len(u) = Len(s)} :
/\ Len(Interleave(s, t)) = 2 * Len(s)
/\ \A i \in 1..Len(s) : /\ Interleave(s, t)[2*i - 1] = <<s[i]>>
/\ Interleave(s, t)[2*i] = <<t[i]>>

-----------------------------------------------------------------------------

ASSUME Zip(<<>>, <<>>) = << >>
Expand Down
Loading