13

The sequence is just $S_n=1, -2, -1, 2$ repeated indefinitely. The best I can do is:

$$S_n= \frac{(i - 2)\,i^n}{2i} + \frac{(i+2)\,(-i)^n}{2i} $$

where $i$ is the imaginary unit. In fact, this expression is where the sequence comes from. Can it be simplified, like using $(-1)^n$ for an alternating sequence of $1$ and $-1$? These values appear as part of a larger formula. Currently, I am simply using a more computational expression: V(n) = the (n modulo 4)'th element of [+1,-2,-1,+2], but this is rather hacky.

lazy dog
  • 251

8 Answers8

14

Expanding on my comment:

$$\cos(\pi n/2) -2\sin(\pi n/2)$$

JMoravitz
  • 79,518
  • Nice one. :) $\text{ }$ – layman Dec 14 '16 at 02:53
  • (+1) Didn't notice your answer before I answered. I started at $n=1$, but it was the same. – robjohn Dec 14 '16 at 09:21
  • This is really elegant, tidy, and fairly understandable at-a-glance given a sufficient familiarity with $cos$ and $sin$. Considering the full range of math functions, it best answers the question as stated. It is also easy to generalize to any alternation of 2 separating alternating integer sequences. That said, I probably wouldn't use this for my specific use-case, since trig functions are generally absent and would be unexpected and surprising. – lazy dog Dec 14 '16 at 19:42
5

Per the OP's request, given the sequence, $$\alpha_n=1,-2,-1,2,1,-2,-1,1,\dots$$ and $\alpha_0=1$, we are to generate it using $(-1)^n$ and well-defined sequences of integers. The unsigned version is easy to do, $$\beta_n = \tfrac{3-(-1)^n}2=1,2,1,2,1,2,1,2,\dots$$ So the problem really is to generate the signs, $$U_n = 1,-1,-1,1,1,-1,-1,1,\dots$$ and fortunately answered by this post and this, $$U_n =(-1)^{n(n+1)/2} = \sqrt{2}\cos\tfrac{(2n+1)\pi}4$$

$\color{blue}{Update:}$ We also have the rather exotic, $$U_n = (-1)^{T_n}$$ with tribonacci numbers $T_n$, $$T_n=\sum_{k=0}^{n-1}\sum_{j=0}^{n-k-1}\tbinom{n-k-1}{j}\tbinom{j}{k-j}=\color{blue}0,1, 1, \color{blue}{2, 4}, 7, 13, \color{blue}{24, 44}, 81, 149, \color{blue}{274, 504},\dots$$ and $T_0=0$.

Alternatively, we seek, $$V_n = \tfrac{2n+1-(-1)^n}4= 0,1,1,2,2,3,3,4,\dots$$ which this post has considered. It then gives us three ways to form $\alpha_n$ as,

$$\alpha_n = \beta_n \,U_n=\tfrac{3-(-1)^n}2\,(-1)^{n(n+1)/2}\,=\,\tfrac{3-(-1)^n}2\,(-1)^{T_n}\tag1$$

and

$$\alpha_n = \beta_n \,(-1)^{V_n} = \tfrac{3-(-1)^n}2\,(-1)^{\frac14\big(2n+1-(-1)^n\big)}\tag2$$

P.S. For a signed sequence with period $5$, see here.

  • Sorry if I was misleading. I did not mean to imply that a solution had to be generated using $(-1)^n$ (although, given the nature of the sequence, I would expect it to show up!). I simply meant that I seek a clear and succint mathematical way of expressing the sequence, like how $(-1)^n$ is so often used in formulas to cleanly express a pattern of alternating $1$'s and $-1$'s. – lazy dog Dec 14 '16 at 19:44
  • 1
    Nonetheless, excellent work! I like that you devised an expression using only integers and elementary arithmetic (no complex numbers, trig, transcendentals, conditionals, piece-wise definitions, floor/ceiling, etc.). I especially like the version using the triangular numbers $n(n+1)/2$ to produce a pattern of signs that alternate 2 at a time. That said, it's a bit too complicated and can take some time for a reader to parse what expression is doing and how it works. – lazy dog Dec 14 '16 at 19:44
  • 1
    @shiftydog: You're welcome. I liked the challenge of expressing the period $4$ using only integers and was glad it lead, among other things, to the tribonacci numbers, a sequence quite dear to me. :) – Tito Piezas III Dec 15 '16 at 02:20
  • 1
    @shiftydog: I've asked a question generalizing the phenomenon of using triangular numbers on $(-1)^n$. Kindly see this post. – Tito Piezas III Dec 15 '16 at 03:31
4

This can be done easily with Discrete Fourier Transform. Observe that $$ \operatorname{DFT}\begin{bmatrix}1\\-2\\-1\\2\end{bmatrix} = \begin{bmatrix} 0 \\ 1-2i \\ 0 \\ 1 + 2i \end{bmatrix} $$ Using the convention $$ \operatorname{DFT}(\mathbf{v})(\xi) = \frac{1}{\sqrt{n}} \sum_{x=0}^{n-1} \mathit{v}_x e^{2\pi i \xi x/n} $$ Hence the inverse DFT gives a periodic interpolation for your sequence: $$ f(x) = \frac{1 - 2i}{2} e^{-2\pi i x/4} + \frac{1 + 2i}{2} e^{-6\pi i x/4} $$ DFT

Henricus V.
  • 18,694
  • Great stuff! +1 –  Dec 14 '16 at 09:19
  • This looks very interesting. Unfortunately, I'm not familiar with the DFT, or even just the plain FT, so this is well beyond my current comprehension :) – lazy dog Dec 14 '16 at 19:42
3

Your expression can be slightly simplified if $n=2k$ we have, $$\frac{i^{2k}}{2i}[(i-2)+(2+i)]=i^{2k}=(-1)^k.$$ If $n=2k+1$ we have, $$\frac{1}{2i}[(i-2)i^{2k+1}-(2+i)i^{2k+1}]=2(-1)^{k+1}.$$ So $$a_n= \begin{cases} (-1)^k & n=2k \\ \\ 2(-1)^{k+1} & n=2k+1 \end{cases} ,$$ where k is an integer.

mike van der naald
  • 566
  • 1
  • 4
  • 14
  • 1
    I fixed a typo in your exponent. – Tito Piezas III Dec 14 '16 at 08:04
  • Here is an even greater "simplification": $a_n=1$ if $n=4k$, $-2$ if $n=4k+1$, $-1$ if $n=4k+2$ and $2$ if $n=4k+3$. IOW, I fail to see how this answers the question. – Did Dec 14 '16 at 08:06
  • How does it not answer this portion of the question, "In fact, this expression is where the sequence comes from. Can it be simplified, like using $(−1)^n$ for an alternating sequence of 11 and −1−1?"

    @Did ...?

    – mike van der naald Dec 14 '16 at 21:27
  • Thank you @TitoPiezasIII ! – mike van der naald Dec 14 '16 at 21:28
  • 1
    If your question is genuine, you might wish to read the OP's first comment to @Tito's answer. – Did Dec 14 '16 at 22:22
  • That comment did not exist when I posted this, sorry. – mike van der naald Dec 14 '16 at 23:37
  • 2
    This is a fine answer. In fact, I upvoted it earlier along with @Wood's answer, which combines both cases into a single expression. While not as economical as other expressions, it eliminates the use of the tricky use of $i$, and is arguably clearer and more straight-forward than most of the single-expression solutions--even the accepted answer. It is a nice balance between the compactness of a single-expression and the immediate clarity of the obvious 4-cased piece-wise definition. – lazy dog Dec 15 '16 at 00:43
  • @shiftydog First, why should a 2-cases piecewise definition be viewed as different from a 3-cases or a 4-cases definition? Please explain. Second, everything in your question points at no-cases definitions. But now you say you were after cases definition? Please explain. – Did Dec 15 '16 at 07:09
  • @Did Right, I definitely prefer a single unconditional expression, given that it's terse, clear, and uses simple operations, but I know sometimes those qualities are often at odds with each other, so I didn't (mean to) require a single-expression. I'm not against a multi-case solution in principle; such a solution simply weighs clarity and simplicity over brevity. So this answer is perfectly valid, but obviously I did not select it due to other considerations. I apologize that my question was unclear. Next time, I'll try to make the specifications less ambiguous. – lazy dog Dec 16 '16 at 01:25
2

You cannot write it using a function depending only of $(-1)^n$, because such a function takes only two values, and you need four. On the other hand a function of $i^n$ takes four values, so what you did is OK.

Momo
  • 16,027
  • We can eke out more periodic values from $(-1)^n$ if $n$ is more complicated than a linear function. Kindly see this post. – Tito Piezas III Dec 15 '16 at 03:39
  • @Tito Piezas III My answer referred strictly to the dependency on $(-1)^n$. But of course, if one is willing to allow dependencies on $(-1)^\text{something else}$, then it is possible to obtain longer periods. – Momo Dec 15 '16 at 03:59
2

You need a period of $4$, so powers of $-1$ won't help. As you select expressions you need to think about what the objective is. If you just want to compute the value, your $V(n)$ is a fine expression. It returns the value you want. What is wrong with that? Any other formula, like the one early in your post, is only valuable if it does something more. Maybe it simplifies with stuff later in your application, or maybe it impresses some reader. You could do powers of $-1$ and $-1^{n/2}$ where that is integer division, but that will be logically equivalent to what you found already.

Ross Millikan
  • 374,822
  • Surprisingly, for period $6$, one can use powers of $(-1)^k$ and, of all things, Fibonacci numbers $F_n$ as $$W_n = (-1)^{n+F_{n+1}} = 1,1,1,-1,-1,-1,1,1,1,\dots$$ Kindly see this post. But there doesn't seem to be a well-known sequence one can use for period $4$ though. – Tito Piezas III Dec 14 '16 at 09:50
  • Oh, I correct myself. It seems the Tribonacci numbers $T_n$ will work, $$W_n = (-1)^{T_n} = 1,-1,-1,1,1,-1,-1,\dots$$ and with $T_0 = 0$. – Tito Piezas III Dec 14 '16 at 09:53
  • 1
    @TitoPiezasIII: I would suggest that is more complicated that what we have, needing to define $F_n$. Yes, you can use Binet's formula to get something explicit in $n$, but it is a comparative mess. – Ross Millikan Dec 14 '16 at 14:51
2

In Python you can do this with ($n$ starting at $1$):

(2-n%2)*(-1)**(n//2)

Which doesn't require the math module.

Wood
  • 1,880
  • In more general, not Python-specific terms: this formula uses only rational numbers. – Kevin Reid Dec 14 '16 at 05:33
  • @KevinReid Only integers, actually. – Wood Dec 14 '16 at 05:35
  • @Did "n//2" means integer division in Python. It gives $0$ if $n=1$. It's the same as "math.floor(n/2)", or $\lfloor \frac{n}{2}\rfloor$. – Wood Dec 14 '16 at 20:43
  • https://repl.it/EqZ9 – Wood Dec 14 '16 at 20:52
  • OK, so no $i$ involved. – Did Dec 14 '16 at 22:25
  • I like this, although in actual Python code, I would probably just do (+1, -2, -1, +2)[n % 4] for clarity. For a mathematical formula, this is a nice, compact solution, and can be made more "math-like" rather than "code-like" (as well as shifted to have $n$ starting from 0) by replacing n%2 with Iverson brackets $[n , even]$ and n//2 with $\lceil \frac{n}{2} \rceil$. It is a bit opaque, though. – lazy dog Dec 15 '16 at 00:48
0

You can simply interpolate$(1,-2,-1,2)$, and then use $x=n\bmod4$:

$$S_n=-\frac{1}{3}(n\bmod4)^3+4(n\bmod4)^2-\frac{38}{3}(n\bmod4)+10$$

barak manos
  • 43,109