WOLFRAM

Differences[list]

gives the successive differences of elements in list.

Differences[list,n]

gives the n^(th) differences of list.

Differences[list,n,s]

gives the differences of elements step s apart.

Differences[list,{n1,n2,}]

gives the successive nk^(th) differences at level k in a nested list.

Details

Examples

open allclose all

Basic Examples  (2)Summary of the most common use cases

First differences:

Out[1]=1

Second differences:

Out[1]=1

Scope  (3)Survey of the scope of standard use cases

Differences of rows, within each column:

Differences of columns, within each row:

Differences of a regularly sampled TimeSeries:

Out[1]=1
Out[2]=2
Out[3]=3
Out[4]=4

Compare to differencing the values:

Out[5]=5

Applications  (3)Sample problems that can be solved with this function

Deduce the degree of a sequence by seeing when successive differences become constant:

Out[1]=1
Out[2]=2

Finite difference approximation to the Laplacian of a Gaussian:

Out[2]=2

Prices of a stock at close:

Out[1]=1
Out[2]=2

Find the daily differences between stock values at close:

Out[3]=3
Out[4]=4

Find the proportion of days with increase in price at close:

Out[5]=5
Out[6]=6

Properties & Relations  (4)Properties of the function, and connections to other functions

First differences are constant for a linear function:

Out[1]=1
Out[2]=2

Second differences are constant for a quadratic function:

Out[1]=1
Out[2]=2
Out[3]=3

Successive differences are progressively shorter:

Out[1]=1

FoldList acts as an inverse of Differences:

Out[1]=1
Out[2]=2

Possible Issues  (1)Common pitfalls and unexpected behavior

Differences of an irregularly sampled TimeSeries may differ from differences of the values:

Out[3]=3
Out[4]=4
Out[5]=5
Out[6]=6

Compare with Differences of the values:

Out[7]=7

Set TemporalRegularity to True and compute differences of the new time series:

Now the value differences agree:

Out[10]=10

Neat Examples  (2)Surprising or curious use cases

Successive differences mod 2 of a sequence based on the primes:

Out[1]=1

Pattern resembling Pascal's triangle:

Out[1]=1
Wolfram Research (2007), Differences, Wolfram Language function, https://reference.wolfram.com/language/ref/Differences.html (updated 2012).
Wolfram Research (2007), Differences, Wolfram Language function, https://reference.wolfram.com/language/ref/Differences.html (updated 2012).

Text

Wolfram Research (2007), Differences, Wolfram Language function, https://reference.wolfram.com/language/ref/Differences.html (updated 2012).

Wolfram Research (2007), Differences, Wolfram Language function, https://reference.wolfram.com/language/ref/Differences.html (updated 2012).

CMS

Wolfram Language. 2007. "Differences." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2012. https://reference.wolfram.com/language/ref/Differences.html.

Wolfram Language. 2007. "Differences." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2012. https://reference.wolfram.com/language/ref/Differences.html.

APA

Wolfram Language. (2007). Differences. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Differences.html

Wolfram Language. (2007). Differences. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Differences.html

BibTeX

@misc{reference.wolfram_2025_differences, author="Wolfram Research", title="{Differences}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/Differences.html}", note=[Accessed: 19-May-2025 ]}

@misc{reference.wolfram_2025_differences, author="Wolfram Research", title="{Differences}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/Differences.html}", note=[Accessed: 19-May-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_differences, organization={Wolfram Research}, title={Differences}, year={2012}, url={https://reference.wolfram.com/language/ref/Differences.html}, note=[Accessed: 19-May-2025 ]}

@online{reference.wolfram_2025_differences, organization={Wolfram Research}, title={Differences}, year={2012}, url={https://reference.wolfram.com/language/ref/Differences.html}, note=[Accessed: 19-May-2025 ]}