In Magma a single variable functions can be created for use, say,
f:= func< n | n lt 2 select 2 else Self(n-1)*Self(n)+1 >;
[f(n): n in [0..12]];
These are easily modified and ready to use. This question is about either creating a function of two variables or an if-then statement. For example
f:= func< n, k | (n eq 0 and k eq 0) select 1 else (k eq 0) select 2 else (k eq n) select 4 else Self(n-1, k-1) + Self(n-1, k) >;
and (this example gives the error message " User error: syntax error at end of input ")
f:= function(n,k);
if n eq 0 and k eq 0 then 1;
elif k eq 0 then 2;
elif k eq n then 4;
else Self(n-1, k-1) + Self(n-1, k);
end if;
[[f(n,k): k in [0..n]]: n in [0..5]];
should work but it seems that maybe Magma does not compute two variable (index) self referenced (recurrence) function. Is this the case or is there a workable model in which the if-then/function can be computed?
Some things to note: the
Selfcommand is used when recursively constructing a sequence, to refer to entries in the sequence under construction. But it is not used in creating recursive functions. You want to either name the function (using the alternatefunction fconstruction method below), or when you are constructing a function that has not yet been assigned a name you can refer to it using$$.Third function should be
or
or
Using the function definition you were using previously, you could also write