MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: When Wolfram's technical support cannot help

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105286] Re: [mg105255] When Wolfram's technical support cannot help
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Wed, 25 Nov 2009 23:04:08 -0500 (EST)
  • References: <200911251114.GAA13425@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

rule = {___, Shortest[x__], x__} :> {x};
{1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3} /. rule
{5, 9, 11, 8, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3} /. rule

{1, 2, 3}

{1, 2, 3}

You can experiment with Longest, if this doesn't satisfy all your needs.

rule2 = {___, Longest[x__], x__} :> {x};
{1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3} /. rule2
{5, 9, 11, 8, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3} /. rule2

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

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

Or:

rule2 = {___, Longest[x__], x__} :> {x};
{1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3} //. rule2
{5, 9, 11, 8, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3} //. rule2

{1, 2, 3}

{1, 2, 3}

Bobby

On Wed, 25 Nov 2009 05:14:07 -0600, Ant King <mathstutoring at ntlworld.com>  
wrote:

> Hi
>
> I sent this email to technical support (as I hold a premier licence)
>
> I am looking for a single function that will extract the cyclic part of  
> (a)
> a completely cyclic sequence and (b) an eventually cyclic sequence. So if
>
> data1={1,2,3,1,2,3,1,2,3,1,2,3} then cyclicpart[data1] should return  
> {1,2,3}
>
> And if
>
> data2={5,9,11,8,1,2,3,1,2,3,1,2,3,1,2,3} then cyclicpart[data2] should  
> also
> return {1,2,3}
>
> And this was the reply that I got
>
> Here is one way to extract out the cyclic part:
>
> lis = Flatten[Join[Table[{1, 2, 3}, {8}]]]
>
> p = Position[Table[BitXor[lis, RotateLeft[lis, i]], {i, 1, 10}],
>     ConstantArray[0, Length[lis]]][[1]] /. {a_} -> a
> lis[[1 ;; p]]
>
> The above however will only work for case where the list always contains
> the repeated pattern.
>
> There is no built-in function as such that will extract out the pattern
> automatically. I have filed a suggestion with our developers and you will
> be notified when this suggestion gets implemented. Again, my apologies  
> for
> the delay and my thanks for your patience.
>
> Now I don't believe that. I think that it should be quite achievable.  
> Anyone
> got any ideas
>
> Thanks a lot
>
> Ant
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: How to make large graphics object fit within a plot?
  • Next by Date: computing expectations for probability distributions in mathematica
  • Previous by thread: When Wolfram's technical support cannot help
  • Next by thread: Re: When Wolfram's technical support cannot help