Re: List difference using patterns and substitutions.

*To*: mathgroup at smc.vnet.net*Subject*: [mg71350] Re: List difference using patterns and substitutions.*From*: Bill Rowe <readnewsciv at sbcglobal.net>*Date*: Wed, 15 Nov 2006 06:44:41 -0500 (EST)

On 11/14/06 at 5:06 AM, ncc1701zzz at gmail.com (Nacho) wrote: >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? While there may be a fast way to do this with pattern matching, there already is a built-in function to do this. Specifically ListConvolve For example, In[1]:= ListConvolve[{1,-1},{a,b,c}] Out[1]= {b-a,c-b} Alternatively In[2]:= ListCorrelate[{-1,1},{a,b,c}] Out[2]= {b-a,c-b} -- To reply via email subtract one hundred and four