Q:

How to use Strings and Functions With Conditions

Very new to Mathematica so this might be really simple.
I have the function
pow[x_,r_]:= x^r

where r is rational due to
rationalQ[r_] := IntegerQ[Numerator[r]] && IntegerQ[Denominator[r]]

I'm trying to use conditions so that when I test pow[0,0] where x=0 and r=0, the output uses the string "undefined" instead of Indeterminate.
Any idea how it works? 

A:

You want to do something like this,
pow[x_,r_?rationalQ]:= x^r
pow[___] := "Undefined"

These function definitions are called DownValues in Mahtematica, and they are applied in order of increasing generality.
So what is going on here, if you evaluate pow with two variables, and the second variable gives True when fed to rationalQ, then that definition is used.  Otherwise the evaluator will continue to look for other matching patterns.  The pow[___] is the most general pattern, and so anything that doesn't match the first pattern will match it.
For more information, see https://mathematica.stackexchange.com/a/1852/9490.

