Is it possible to define a function "Numerator" in the following way? $$N(a/b) = a$$
Or likewise is it possible to define a function "Denominator" like this? $$D(a/b) = b$$
These functions take a rational number, and match it against the pattern $a/b$, thus assigning the numerator to $a$ and the denominator to $b$.
This is common practice in functional programming languages like Haskell, and I am just dying to do similar in my standard mathematical escapades. Having access to this style of function would make my life much easier in a particular problem I'm working on right now.
If this is not possible (I haven't seen it done before), could someone kindly provide me with a formula or algorithm for working out the numerator of a rational number? (And the denominator for bonus points)
So given the number $1/2$, I want to know how to get at the $1$, and more generally, given $a/b$ I want to know how to get the $a$
You might wonder why I can't just do it by inspection: I'm dealing with a function which returns a rational number, and I only want the numerator, but because I only can see the function I can't see the numerator. In this way, I only have my number in the form $f(x)$ so I am unable to work out the numerator by inspection, I need some algorithm or formula for extracting it.
That isn't a well-defined function, unless you specify some further conditions. Since $1/2 = 2/4$, we should have $f(2/4) = f(1/2) = 1$, not $2$.
But we can define a function $f$ such that $f(x) = a$, where $x = a/b$ in lowest terms. Because this uniquely specifies what $a$ is, this defines a function.
However, I don't think it's possible to express $f$ in terms of $+, -, \times, \div$.
Edit: you want $f$ expressed in "mathematical notation". The above is a valid mathematical definition of $f$, but I assume you're looking for a more algorithmic definition.
Such a thing will be hard to produce, unless you implement it inside the "rational" object. I would have said impossible earlier today, but I came across a result by Julia Robison, stating that you can tell if a rational number is an integer just using $+,\times,<$. That being said, it's wildly impractical to implement it using this.
If you're doing a proof, you can simply declare that the function exists, and move on.
Julia Robinson, Definability and Decision Problems in Arithmetic. The Journal of Symbolic Logic, Vol. 14, No. 2 (Jun., 1949) , pp. 98-114