Welcome to Shaun Luttin's public notebook. It contains rough, practical notes. The guiding idea is that, despite what marketing tells us, there are no experts at anything. Sharing our half-baked ideas helps everyone. We're all just muddling thru. Find out more about our work at bigfont.ca.

# From Zip to Convolution to Tuple

Reading about Linq's `Enumerable.Zip` lead me to read about convolution, which led me to read about the tuple.

Zip is often a synonym for convolution. Convolution

• is a function
• which maps a tuple of sequences `(seq01, seq02, ..., seqN)`
• into a sequence of tuples `[tup01, tup02, tup03, ...]`

So what's a tuple?

As someone with C# experience, I think of a tuple as a struct with unnamed properties. While the analogy eventually breaks down, it succeeds at developing intuition. Note: a tuple is more like a struct than a class, because we generally make a struct immutable.

Couple rhymes with tuple. The word tuple comes from the suffix of numbers of grouped things. For example, when we reach five items we have a quintuple. Eventually we just say n-tuple, which is like multiple.

Tuples differ from sets in that:

• tuples are ordered and sets are not;
• tuples can contain duplicates and sets cannot;
• tuples are finite whereas sets are not.

Tuples differ from (ordered) lists too, because we attach more meaning to the index of a tuple item than we do to a list item. In an ordered list, for instance, we might interpret the item at index two as coming before the item at index three. In a tuple, though, an item's index acts more like a struct's property; for instance, a 3-tuple that represents a sentence might have the Subject at index one, the Verb at index two, and the Object at index three. The semantics of a list is called homogenous (an item is an item is an item) and the semantics of a tuple is called heterogenous (because an item is a Subject, or an Object, or a Verb, or a whatever...)

In addition to having richer semantics than lists do, tuples are immutable whereas lists are mutable. For all those reasons, the following struct and tuple could have the same meaning.

``````var sentence = new Sentence // Sentence is a struct
{
Subject = "Shaun";
Verb = "eats";
Object = "papaya";
};

var sentence = Tuple.Create("Shaun", "eats", "papaya");
``````

Now, it's time for me to head back to learning about `Enumerable.Zip`.