Math · Note 2
Functions, and why subscripts are functions
What the arrow in f from A to B means, why every column of a table is a function from a row to a value, and why a subscript is the same thing written differently. Short, and it removes most of the fear of the notation that follows.
A function takes something and returns something.
Say it: f from A to B, or f maps A to B. is what it accepts, is what it returns, and is the thing it returns for .
That is the whole definition. There is no requirement that a function be a calculation, or a formula, or anything you could compute. A lookup table is a function. A column is a function.
Every column is a function
For a table, each column is a function from a row to a value:
So if is the row then and .
This is just dot notation — `line.qty` — written the way mathematicians write it. Nothing has been added except the habit of putting the name on the outside.
Once you accept that, a formula stops looking like algebra and starts looking like code, which is what it is.
Subscripts are the same thing in disguise
When you see , read it as : a function applied to an index. means — the O belonging to c.
The subscript is used when the thing being looked up feels more like an index than an argument, and that is the only difference. There is no mathematical distinction. Anyone who writes could have written and often does, in the same paper, on the same page.
This matters because subscripts are where most people decide the notation is beyond them, and they are the easiest part of it.
Naming the sets you will need
With that, two definitions that the rest of the series uses constantly:
Say it: O sub c is the set of orders o in Order such that the cust_id of o equals c. It is the set of that customer's orders.
And that is the set of lines belonging to order .
Both are ordinary set-builder from the first note, with a name attached. Naming a set is always allowed, and it is usually what turns an unreadable formula into a readable one. If an expression is getting away from you, the fix is almost never a cleverer symbol; it is to pull a piece out and give it a name.
For the running example: , , and , because Cy has never ordered anything.
Exercises
Say out loud.
Answer
"unit_price is a function from Line to the rationals" — every line has a unit price, and it is a number that can have decimals.
What is ? What is ?
Answer
and .
Write out .
Answer
The two lines of order 10: .
What is ?
Answer
.
Rewrite without a subscript.
Answer
. They mean the same thing; the subscript is a typographic habit, not a different operation.
Define , the set of customers in a given city .
Answer
. Any letter will do for the parameter; avoids colliding with for a customer.
Questions
What does f : A to B mean?
It says f is a function that accepts something from A and returns something in B. A is called the domain and B the codomain. Nothing in the notation requires f to be computable or given by a formula; a lookup table is a perfectly good function.
Is a subscript different from a function call?
No. Writing a with subscript i means the same as a of i. The subscript form is used when the argument feels like an index into a collection rather than an input to a calculation, but there is no mathematical difference between them.
Why treat a database column as a function?
Because it behaves as one: give it a row and it returns exactly one value. Writing it as qty of l rather than l.qty lets column access appear inside a formula in the same shape as everything else, which is what makes larger expressions readable.