TITLE: Mathematical formal notation of a dictionary
QUESTION [8 upvotes]: I was wondering how to express a dictionary or associative array (as known in programming) formally in mathematical notation. A dictionary is basically a set of ordered pairs of keys and values, but each key must appear only once.
Now, if $K$ is the set of all possible keys and $V$ the set of all possible values, my first idea of how to express a dictionary over $(K,V)$ was:
$$D \subseteq \{(k,v)\mid k \in K \land v \in V\}$$
The problem is that this allows for repeated keys. So my second idea was this:
$$D \subseteq \{(k,v)\mid k \in K \land v \in V \land \forall (q, w) \in D: k=q \to v=w \}$$
Is this a sensible definition of a dictionary or am I missing something crucial?

REPLY [7 votes]: Yes, it's sensible and it amount precisely to a function $f:K\to V$. That is what a dictionary is, it's a function from the set of keys to the set of values.