# How to write diff() mathematically?

I am using R/Python diff() operation. e.g., https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.diff.html

I would like to know if there is a mathematical function that denotes what diff does?

In other words, assume I have a list of N numbers. How can I denote this using a methematical function?

mylist = [x1, x2, x2, ..., xN]

I am happy to provide more details if needed.

Assume you want to apply diff to a vector $$(x_1, \dots, x_n)$$ of length $$n$$. The result will be the vector $$(d_1, \dots, d_{n-1})$$ of length $$n-1$$ with entries

$$d_i = x_{i+1}-x_i.$$

Some people will use the notation $$x_{[i]}$$ or similar to indicate the vector $$x$$ with the $$i$$th component left out, i.e., $$x_{[i]}=(x_1, \dots, x_{i-1}, x_{i+1}, \dots, x_n)$$. With this, you can write more concisely in vector form

$$d = x_{[1]} - x_{[n]}.$$

• Thanks a lot for the great answer. Just wondering how to write this function sd(diff(x))/abs(mean(diff(x))) mathematically. Currently, I am having it as σ(diff(x))/|µ(diff(x))|. Please let me know your thoughts on this. I look forward to hearing from you. Thank you very much :)
– EmJ
Apr 21 '19 at 8:32
• That sounds useful enough. You can always write down the formulas for the mean and SD in terms of the differences $d_i$. And if you really want, you can substitute in the $x_i$, but it will get progressively less enlightening. Apr 21 '19 at 8:40
• Interesting notation for leaving out $i$; haven't seen that one before. I have often seen $x_{-i}$ for that Apr 21 '19 at 11:43
• @StephanKolassa I did not get what you said. It would be really great if you could show me what you said symbolically. I look forward to hearing from you. Thank you once again :)
– EmJ
Apr 21 '19 at 16:17