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.