Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #4444
| From | "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: What "Sort" option of :Values does? |
| Date | 2011-08-17 09:54 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j2g345$1dn$1@smc.vnet.net> (permalink) |
| References | <j2cv3a$hfg$1@smc.vnet.net> <op.v0a3f4vdqcgwdu@core2.lan> |
On Tue, 16 Aug 2011 13:25:06 +0100, Oleksandr Rasputinov
<oleksandr_rasputinov@hmamail.com> wrote:
> On Tue, 16 Aug 2011 06:27:06 +0100, Alexey Popkov <lehin.p@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.
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What "Sort" option of :Values does? "Alexey Popkov" <lehin.p@gmail.com> - 2011-08-16 05:27 +0000 Re: What "Sort" option of :Values does? "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-08-17 09:54 +0000 Re: What "Sort" option of :Values does? "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-08-17 09:53 +0000
csiph-web