Re: List difference using patterns and substitutions.

• To: mathgroup at smc.vnet.net
• Subject: [mg71342] Re: [mg71306] List difference using patterns and substitutions.
• From: gardyloo <gardyloo at mail.wsu.edu>
• Date: Wed, 15 Nov 2006 06:44:09 -0500 (EST)
• References: <200611141006.FAA06710@smc.vnet.net>

```Not sure about the rule substitutions (I haven't thought about it much
at all, but it seems to me there will be at least two levels of rules
applied to get it to work). However, one can actually use a built-in
function (probably fast!):

In[1]:=

testList = Table[IntegerPart[10*Random[]], {10}]

Out[1]=

{9,2,5,9,4,3,4,0,5,3}

In[2]:=

ListCorrelate[{-1, 1}, testList]

Out[2]=

{-7,3,4,-5,-1,1,-4,5,-2}

Nacho wrote:
> Hello.
>
> I'm trying to figure how can I build a difference list from another
> using only patterns and rule substitutions.
>
> The idea is to get from a list, another, one element shorter, where
> each value is the substraction of two consecutive elements in the
> original list, that is, from {1,2,3,5,5} get {1,1,2,0}.
>
> I've been thinking about it for a while, and I know several methods
> using a more traditional programming style (with For, for example), but
> I have no idea if it is possible to make it simple and fast with rule
> substitutions.
>
> Any idea?
>
>
>
>

--
==========================================================
Curtis Osterhoudt
gardyloo at mail.remove_this.wsu.and_this.edu
PGP Key ID: 0x088E6D7A
Please avoid sending me Word or PowerPoint attachments
See http://www.gnu.org/philosophy/no-word-attachments.html
==========================================================

```

• Prev by Date: FindInstance returning incorrect results
• Next by Date: Vandermonde Matrix/Optimization question
• Previous by thread: Re: List difference using patterns and substitutions.
• Next by thread: Re: List difference using patterns and substitutions.