Re: Why does the order of down values come back?

• To: mathgroup at smc.vnet.net
• Subject: [mg124881] Re: Why does the order of down values come back?
• From: Christoph Lhotka <christoph.lhotka at fundp.ac.be>
• Date: Fri, 10 Feb 2012 05:57:07 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• References: <jgo0e9\$a2k\$1@smc.vnet.net> <jgtj0n\$6dc\$1@smc.vnet.net> <201202091037.FAA18309@smc.vnet.net>

```hi,

On 02/09/2012 11:37 AM, Oleksandr Rasputinov wrote:
> A very good point. To tell the truth, the only time I've ever had to worry
> about the order of DownValues is when there is some ambiguity in their
> ordering, so I had never noticed the ordering based on position in the
> hash table of those values for which the hash is sufficient to completely
> specify the way in which they are applied. It would be interesting to know
> to what extent the hash table (or tables, if multiple levels of hashing
> are applied, as one might anticipate from the statements about ordering
> based on specificity) is used in the resolution of more complicated
> DownValues and at which point the process reduces to a sequential test for
> applicability by pattern matching (i.e., when the ordering begins to
> matter). Perhaps this can be determined by experiment?

It is an interesting problem to find out how the order of downvalues
changes the results. You can make your own experiments like I did below:

f[0] := 0; f[1] := 1; f[n_] := f[n - 1] + f[n - 2]
dvl = Permutations[DownValues[f]] /. f -> cf;

cf[n] /. dvl
{cf[-2 + n] + cf[-1 + n], cf[-2 + n] + cf[-1 + n],
cf[-2 + n] + cf[-1 + n], cf[-2 + n] + cf[-1 + n],
cf[-2 + n] + cf[-1 + n], cf[-2 + n] + cf[-1 + n]}

cf[1] /. dvl
{1, cf[-1] + cf[0], 1, 1, cf[-1] + cf[0], cf[-1] + cf[0]}

cf[0] /. dvl
{0, 0, 0, cf[-2] + cf[-1], cf[-2] + cf[-1], cf[-2] + cf[-1]}

As you see, I produced a table of all possible permutations
of the internal rules for f named dvl and replaced f by a copy
of it called cf to avoid the acting of the internal evaluation
chain (you could also clear f after the definition of dvl).

The output shows in which way the ordering matters for
cf[n], cf[1], cf[0] (i.e. also for f[n], f[1], f[0]).

Wolfram did a good choice.

Best,

Christoph

```

• Prev by Date: Re: plotting
• Next by Date: Re: The simple command x=0;Dynamic[x=x+1]
• Previous by thread: Re: Why does the order of down values come back?
• Next by thread: Re: Why does the order of down values come back?