# How do I determine the 15th Lucas term in the 3rd order?

I want to implement the Lucas n-Step Number.

This command taken from here doesn't seem to work, am I using the right command?

ClearAll[LnStepN];
LnStepN[2, n_] = 0; LnStepN[1, n_] = 1; LnStepN[3, n_] = 1;

LnStepN[k_Integer, n_Integer] :=
LnStepN[k, n] = Sum[LnStepN[k - i, n], {i, 1, Min[k, n]}]

• Can you not add the code in plain text? This would make people more likely to help you. – J. M. will be back soon Oct 12 '15 at 14:25
• Its from this answer. It does work for me :) – rhermans Oct 12 '15 at 14:40
• @rhermans Notice that the code you added does NOT have the same starting conditions as the code the OP posted. I think therein lies the problem... – MarcoB Oct 12 '15 at 15:19
• @MarcoB fixed, thanks! – rhermans Oct 13 '15 at 17:35

Based on the definition from Wolfram Mathworld, the "Lucas n-Step Number" is define by:

ClearAll[LnStepN];
LnStepN[k_, n_] := -1 /; k < 0;
LnStepN[0, n_] = n;
LnStepN[1, n_] = 1;
LnStepN[k_Integer, n_Integer] :=
LnStepN[k, n] = Sum[LnStepN[k - i, n], {i, 1, n}]


To verify the solution:

Table[
LnStepN[k, n]
, {n, 2, 7}
, {k, 1, 12}
] // TableForm


Now the requested 15th Lucas term in the 3rd order.

LnStepN[15, 3]

9327

• thanks for helping me, you really are a pro at this :) – Charles Oct 13 '15 at 23:20

You can take a look at OEIS for more formulas: http://oeis.org/A001644

Lucas3[n_]:=Last[LinearRecurrence[{1, 1, 1}, {3, 1, 3}, n + 1]];

Lucas3[15]
(* 9327 *)


This is experimental, but seems to work:

Lucas[k_Integer, n_Integer]:=Last[LinearRecurrence[ConstantArray[1,k], Array[(2^#-1)&, k], n]];

Lucas[3, 15]