MathGroup Archive 2010

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

Search the Archive

Re: Behavior of Longest

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107949] Re: [mg107909] Behavior of Longest
  • From: Patrick Scheibe <pscheibe at trm.uni-leipzig.de>
  • Date: Wed, 3 Mar 2010 05:54:13 -0500 (EST)
  • References: <201003021254.HAA14195@smc.vnet.net>

Hi,

your pattern doesn't match like you want it because List[1,2] is not  
of the form
__Integer but the subexpressions are. Read the documentation of  
ReplaceAll:

"applies a rule or list of rules in an attempt to transform each  
subpart of an expression  expr."

your subexpressions are the single parameters to your {1,2} list  
namely 1 and 2.
so what is

1/.Longest[x__Integer]:>{x}

?

Your last example is right because you match the whole expression as  
you intended.
What you wanted in the first cases is

{1, 2} /. {Longest[x__Integer]} :> Boing[x]
{1, 2} /. _[Longest[x__Integer]] :> Boing[x]

and the same with Shortest.

Cheers
Patrick


Am Mar 2, 2010 um 1:54 PM schrieb dh:

> Hello,
> can somebody give an explanation for the following behavior of Longest
> (Mathematica version 7.0.1):
> {1, 2} /. Longest[x__Integer]:>{x}    gives {{1}, {2}}
>
> the same as Shortest:
> {1, 2} /. Shortest[x__Integer]:>{x}  gives {{1}, {2}}
>
> However, it works like expected in the following case:
> {a, 1, 2, b} /. {x1___, Longest[x__Integer], x2___} :> {x1, {x}, x2}
> gives: {a, {1, 2}, b}
>
> looks like a bug to me.
>
> Daniel
>
> -- 
>
> Daniel Huber
> Metrohm Ltd.
> Oberdorfstr. 68
> CH-9100 Herisau
> Tel. +41 71 353 8585, Fax +41 71 353 8907
> E-Mail:<mailto:dh at metrohm.com>
> Internet:<http://www.metrohm.com>
>
>



  • Prev by Date: Re: Select Maximum Value
  • Next by Date: Re: Behavior of Longest
  • Previous by thread: Re: Behavior of Longest
  • Next by thread: Re: Behavior of Longest