TITLE: What is the relationship between sets, sequences, and functions?
QUESTION [5 upvotes]: There's a practice problem I've been working on that's been bothering me. I've been searching for answers here and elsewhere online but I can't the answer I'm looking for. The question is as follows:
"Consider the abstract data types Sequence and Set, paying attention to how objects are treated mathematically. What is the relationship between sets, sequences, and functions?"
So far I know that sequences and sets can both consist of collections of elements, and functions are the operations that can be done on them, but that isn't enough to answer the question. What else am I missing?

REPLY [4 votes]: A set is a collection of distinct elements.  That is fine.  That is what we learned early on, it is correct and we can use it as our basic concept.  The only thing we can say about a set is whether specific elements are or are not members of it.  Order is neither significant or meaningful and number of times an element appears in a set is meaningless; either an element is or is not a member of a set.  Period.  Okay, every thing we were taught is good.
We learned that a sequence was an ordered set in which elements may appear multiple times (or not) but the order or position matters.  That is what we were taught.  It is pure garbage.  It's not our fault but --- it's garbage.  Let's put pin in sequence and get back to them.
Functions.  We were taught functions were a mapping from one set $X$ called the domain to another set $Y$ called the range (or codomain or image-- depends on your age and whether you went to a high school in California or not-- I kid... {I don't kid...}).  That's fine as far as it goes.  But the idea of "mapping" is not defined and doesn't bear any weight of scrutiny.
Given two sets $X$ and $Y$ then an ordered pair $(a,b)$ is a listing of an element from set $X$ listed in conjunction with an element of set $Y$.  $X\times Y$ is the set of all possible ordered pairs.  
A function $f:X\to Y$ is a subset $K$ of $X\times Y$ with the two condition that for ever $x \in X$ there is one and only one $(a,b)\in K$ so that $a = x$.
A sequence $S$ of elements of a set $X$ is a function $f:\mathbb N \to X$.  That's it.