When writing recursive code that computes the least value at which a condition is true and various other scenarios it is often necessary to specify a base case. What I have done to supply this is create a function parameter that must always have the specified base case passed into it:
least2nbigger[x_, n_] := If[2^n >= x, 2^n, least2nbigger[x, 1 + n]]
This is used with a structure like
Where the 1 is the start value for the recursion. x is the only parameter of interest to someone using the function; n is always to be passed as 1.
In SML I would do something like this:
fun least2nbigger x = least2nbigger (x, 1) | least2nbigger (x, n) = let p = pow (2, n) in if p > x then p else least2nbigger (x, n+1) end;
(My SML is a bit rusty, that might not be entirely valid but the idea is clear).
There is an alternative definition provided for the recursive case; the function can be called without the tuple.
The only way I see to do this in Mathematica would be to make two functions, the recursive case and a dummy function that calls the recursive case with is base parameter. Is there a better way to accomplish this?