2

For example,

{1,2,3,4,5,6,7,8}

has period 1, the base is {1}

{1,2,4,5,7,8,10,11}

has period 3, the base is {1,2}

I notice there is a built-in function FunctionPeriod, but it doesn't work. eg

l[n_]:={1,2,4,5,7,8,10,11}[[n]]
FunctionPeriod[l[n],n,Integers]

So how to write a function period to find the period of discrete sequence.

ps: The sequence could be non-integers, for example sqrt, reals,

matheorem
  • 17,132
  • 8
  • 45
  • 115

1 Answers1

3

Let

list={1, 2, 4, 5, 7, 8, 10, 11}

then Differences[list] transform is list to periodic form

{1, 2, 1, 2, 1, 2, 1}

Length@FindLinearRecurrence@Rationalize@Differences[list] gives the periodicity is 2

Rationalize is necessary for real number list

But we want the translation period, so we can make the following

list[[2+1]]-list[[1]]

this gives the result 3

So the function that serves this purpose can be defined as

Clear[discreteperiod];
discreteperiod[list_] := Module[
  {recurrence = FindLinearRecurrence@Rationalize@Differences@list},
  If[Head[recurrence] === FindLinearRecurrence, 
   Print["The period contained in the list is not enough"]; 
   Abort[], (list[[# + 1]] - list[[1]]) &@Length[recurrence]]]
matheorem
  • 17,132
  • 8
  • 45
  • 115