MathGroup Archive 2011

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

Search the Archive

Re: What "Sort" option of :Values does?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120932] Re: What "Sort" option of :Values does?
  • From: "Oleksandr Rasputinov" <oleksandr_rasputinov at hmamail.com>
  • Date: Wed, 17 Aug 2011 05:53:08 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j2cv3a$hfg$1@smc.vnet.net> <op.v0a3f4vdqcgwdu@core2.lan>

On Tue, 16 Aug 2011 13:25:06 +0100, Oleksandr Rasputinov  
<oleksandr_rasputinov at hmamail.com> wrote:

> On Tue, 16 Aug 2011 06:27:06 +0100, Alexey Popkov <lehin.p at gmail.com>  
> wrote:
>
>> All the ...Values functions have undocumented option Sort:
>>
>> In[1]:= Options /@ {OwnValues, DownValues, UpValues, SubValues,
>>   DefaultValues, FormatValues, NValues}
>>
>> Out[1]= {{Sort -> True}, {Sort -> True}, {Sort -> True}, {Sort ->
>>    True}, {Sort -> True}, {Sort -> True}, {Sort -> True}}
>>
>> What this option does?
>>
>
> Sort -> True (the default) sorts *Values into lexicographic order in the  
> output of these functions, acting as if they were Orderless (which  
> actually they are not). Sort -> False, on the other hand, keeps them in  
> the same order that they appear internally, which is to say the order in  
> which they will be applied (and usually also the order in which they  
> were defined). A simple example:
>
> In[1] :=
> a[2] = 2;
> a[1] = 1;
>
> In[3] :=
> DownValues[a]
>
> Out[3] =
> {HoldPattern[a[1]] :> 1, HoldPattern[a[2]] :> 2}
>
> In[4] :=
> DownValues[a, Sort -> False]
>
> Out[4] =
> {HoldPattern[a[2]] :> 2, HoldPattern[a[1]] :> 1}
>
> In the case of OwnValues the meaning of this is not readily apparent at  
> first glance. However, a symbol can actually have multiple OwnValues if  
> Condition is used, and sorting becomes meaningful in such a case.
>

On second thought, the analogy I made above to Orderless is so loose as to  
be potentially confusing, so perhaps it is best not to think of it this  
way. The point is simply that if *Values were maintained internally as a  
sorted list then they would be pattern matched in the same way as the  
arguments of Orderless functions are. However, clearly this is not the  
case in practice, despite the impression given by the default behaviour of  
these functions with Sort -> True.




  • Prev by Date: Re: Treat subscripted variables as symbols
  • Next by Date: Re: Simple Doppler effect
  • Previous by thread: Re: What "Sort" option of :Values does?
  • Next by thread: Parameter optimizatrion in modified diffusion equation