5
$\begingroup$

How to put mathematically sequence that changes sign like:

$n = 0\quad f = 1$

$n = 1 \quad f = -1$

$n = 2 \quad f = -1$

$n = 3 \quad f = 1$

$n = 4 \quad f = -1$

$n = 5 \quad f = -1$

$n = 6 \quad f = 1$ .....

In the form of (-1)^(something) or similar analytical expression.

$\endgroup$
  • $\begingroup$ Is there closed form analytical expression ? $\endgroup$ – Anonymous Jun 7 '16 at 18:39
  • $\begingroup$ @Anonymous That is the closed form expression for the sequence $\{ 1, -1, 1, -1, \dots \}$, which is not your sequence. $\endgroup$ – Axoren Jun 7 '16 at 21:06
  • $\begingroup$ This is easy if the use of modulus is permitted. $\endgroup$ – PM 2Ring Jun 8 '16 at 7:10

11 Answers 11

9
$\begingroup$

This formula works: $$f(n)=-\frac13+\frac43\cos\left(\frac{2\pi}3n\right)$$ Here's a graph of what that looks like.

Since the sum of any three consecutive values is $-1$, it satisfies this recurrence relation: $$f(x+2)=-f(x+1)-f(x)-1$$ It also satisfies the recurrence relation $f(x+3)=f(x)$, though that's less interesting.

(Geometrically, think of a circle of radius $4/3$ centered on the point $(-1/3,0)$. This circle passes through the three equidistant points $(1,0)$, $(-1,2/\sqrt3)$, and $(-1,-2/\sqrt3)$ (they form the corners of an equilateral triangle inscribed in the circle). The function $f$ alternately takes the $x$-coordinate of each of these points.)

$\endgroup$
8
$\begingroup$

\begin{align} a_1 &= 1 \\ a_2 &= -1 \\ a_n &= a_{n-1}a_{n-2} \end{align}

Using a product recurrence relation, we have

$$ a_n = a_2^{F_{n-1}}a_1^{F_{n-2}} $$

Where $F_k$ is the $k$'th Fibonacci number. Given a closed form for $F_k$, we can simplify $a_n$.

$$ F_k = \frac{(1 + \sqrt{5})^k - (1 - \sqrt{5})^k}{2^k\sqrt{5}} $$

$$ a_n = (-1)^{F_{n-1}} = (-1)^{\frac{(1 + \sqrt{5})^{n-1} - (1 - \sqrt{5})^{n-1}}{2^{n-1}\sqrt{5}}} $$

This was solved so that the starting index of the sequence was $1$. If you want to start at $0$, we simply shift the index by $+1$.

$$ a_n = (-1)^{F_{n}} = (-1)^{\frac{(1 + \sqrt{5})^{n} - (1 - \sqrt{5})^{n}}{2^{n}\sqrt{5}}} $$


Using Euler's Formula, we can get a far more (or less) elegant solution:

$$ a_n = (-1)^{F_n} = \cos(\pi F_n) + i\sin(\pi F_n) = e^{i\pi F_n} $$

$\endgroup$
  • 1
    $\begingroup$ LOL. (+1) ${}{}$ $\endgroup$ – Micah Jun 8 '16 at 0:41
  • 3
    $\begingroup$ Upon closer inspection, $$ a_n = (-1)^{F_n} = e^{i\pi F_n} = \cos(\pi F_n) + i\sin(\pi F_n) $$ $\endgroup$ – Axoren Jun 8 '16 at 4:29
4
$\begingroup$

$$ {1 \over 3}\left[4\cos\left({2n\pi \over 3}\right) - 1\right]\,,\qquad n = 0,1,2,\ldots $$

$\endgroup$
4
$\begingroup$

Another possibility (closer to the $(-1)^k$ that you claim to have played with) is: $$ (-1)^{1+\left\lfloor\frac{2(k-1)}{3}\right\rfloor} $$

(and I won't be surprised if I managed to get one of the shifts wrong).

$\endgroup$
  • $\begingroup$ This seems like imaginary. $\endgroup$ – Anonymous Jun 7 '16 at 23:35
  • $\begingroup$ @Anonymous - that $\lfloor \cdot \rfloor$ is the floor function - the greatest integer $\le$ to what is inside. So the exponent is always an integer, and the value is always $1$ or $-1$. However, it could be simplified to $(-1)^{\left\lfloor \frac{2k+1}3\right\rfloor}$ $\endgroup$ – Paul Sinclair Jun 8 '16 at 3:02
  • $\begingroup$ I chose not to simplify the expression as I believed having both shifts made it a little clearer how I got from $(-1)^{\lfloor2k/3\rfloor}$ which I believe is a quite natural thing to try. I should probably have written something about that. $\endgroup$ – Henrik Jun 8 '16 at 6:50
4
$\begingroup$

Here's a negative result: $f(n)$ cannot be written in the form $$ f(n) = (-1)^{g(n)} $$ where $g$ is a polynomial function.

The relevant condition on $g$ is that its values form the period 3 sequence

$$ g(n) \equiv 0, 1, 1, 0, 1, 1, \ldots \pmod{2} $$

The difference sequence of a sequence is defined by $\Delta h(n) = h(n+1) - h(n)$. We can compute the differences of $g$:

$$ \Delta g(n) \equiv 1, 0, 1, 1, 0, 1, \ldots \pmod{2} $$ $$ \Delta^2 g(n) \equiv 1, 1, 0, 1, 1, 0, \ldots \pmod{2} $$ $$ \Delta^3 g(n) \equiv 0, 1, 1, 0, 1, 1, \ldots \pmod{2} $$

and so forth. If $g$ were a polynomial function, then by taking enough differences we would arrive at the zero sequence; but that clearly cannot happen.

$\endgroup$
  • $\begingroup$ This proves is that $g(n)$ cannot be a polynomial. An analytic function is not limited to this, it can be any function described by a convergent power series. Polynomials are such functions, but not all such functions are polynomials. $\endgroup$ – Axoren Jun 8 '16 at 18:36
3
$\begingroup$

with $r = -\frac12 + \frac{\sqrt{3}}{2} i$

$$a_k = \frac{2(r^k + \overline{r^k} ) -1}{3} $$

should work.

I'm sorry for posting a wrong answer before.

$\endgroup$
  • $\begingroup$ That doesn't work, the desired sequence is $1,-1,-1,1,-1,-1,1,-1,-1, \cdots $ and your sequence is $1,-1,-1, 1, 1,-1,-1, 1,1,-1,-1, 1,\dots $ $\endgroup$ – zhw. Jun 7 '16 at 19:40
  • $\begingroup$ r=(-1+1i*sqrt(2))/2; k=[0 1 2 3 4];(2*(r.^k+(conj(r.^k)))-1)/3 ans = 1.0000 -1.0000 -0.6667 0.5000 -0.9167 Matlab $\endgroup$ – Anonymous Jun 7 '16 at 20:35
  • $\begingroup$ @Anonymous r = (-1 + sqrt(3)*i)/2, sorry $\endgroup$ – 0x539 Jun 7 '16 at 21:04
  • $\begingroup$ awesome thanks! $\endgroup$ – Anonymous Jun 7 '16 at 23:34
2
$\begingroup$

The sign changes every 3 steps. So basically you've got a + if $n = 0$ and then $n = 3$ and $n = 6$ etc. Therefore it's an alternating sequence given as such: $a_n = 1$ if $n$ mod $3 = 0 $ and $-1$ otherwise.

Edit: The answer using the floor function was wrong as pointed by Erick Wong. Here is another way to write down the general term of the sequence : $$a_n = (-1)^{\mathbb{1}_{n \ mod \ 3 \ \neq \ 0}}.$$

$\endgroup$
  • $\begingroup$ Is there closed form analytical expression ? $\endgroup$ – Anonymous Jun 7 '16 at 18:42
  • $\begingroup$ I've edited my answer. $\endgroup$ – user242756 Jun 7 '16 at 18:46
  • $\begingroup$ @bgsk Your exponent certainly looks like it has period $4$, not $3$. $\endgroup$ – Erick Wong Jun 7 '16 at 21:47
  • $\begingroup$ I see. Thank you for the correction. $\endgroup$ – user242756 Jun 7 '16 at 22:03
2
$\begingroup$

The function $\lceil x \rceil - \lfloor x \rfloor$ is $1$ except for integers, where it vanishes. If we scale it to miss only $3$-integers and put as exponent onto $-1$: $$ (-1)^{\lceil n/3 \rceil - \lfloor n/3 \rfloor} $$ or similarly, but with the floor function only: $$ (-1)^{\lfloor -n/3 \rfloor + \lfloor n/3 \rfloor} $$ we get your desired sequence for $n=0$, $1$, $2\ldots$

$\endgroup$
2
$\begingroup$

$$\ (-1)^{n^2\,\rm mod\,3}\ $$

$\endgroup$
2
$\begingroup$

If you allow yourself other roots of unity, you can use the discrete fourier transform.

I presume you want the sequence to have period $3$. So, we use the cube root of unity $\zeta = \frac{-1 + i \sqrt{3}}{2}$. The DFT $\hat{f}$ is given by

$$ \hat{f}(n) = \sum_{k=0}^2 f(k) \zeta^{kn} $$

which we can tabulate as

  • $\hat{f}(0) = -1$
  • $\hat{f}(1) = 2$
  • $\hat{f}(2) = 2$

Then, we can recover $f$ by

$$ f(n) = \frac{1}{3} \sum_{k=0}^2 \hat{f}(k) \zeta^{-kn} $$

which works out to

$$ f(n) = \frac{1}{3} \left(-1 + 2 \zeta^n + 2 \zeta^{-n} \right) $$

which can be expressed in a variety of forms; e.g. since $\zeta = \exp(2 \pi i / 3)$, we have

$$ \cos\left( \frac{2 \pi n}{3} \right) = \frac{\zeta^n + \zeta^{-n}}{2} $$

and thus

$$ f(n) = \frac{1}{3} \left( -1 + 4 \cos\left( \frac{2 \pi n}{3} \right) \right) $$

More generally, you could solve this by picking any three linearly independent functions with period $3$, then solving a system of equations to recover what coefficients you need on them to construct $f$; the DFT is just a direct way to obtain such a solution when the three functions are $1$, $\zeta$, and $\zeta^2$.

$\endgroup$
1
$\begingroup$

A meta-answer: if you already have the sequence $0,1,1,0,1,1\ldots$, then you may take the power of $-1,$ but you actually don't need exponentiation at all (similarly for other periodical sequences): \begin{align} a_n &=1 - 2(n^2 \bmod 3)\\ &=1 - 2n^2 + 6\lfloor n^2/3\rfloor\\ &=1 - 2\cdot \lvert (n-1) {\bmod} 3 -1\rvert\\ &= 1 - 2(\lceil n/3 \rceil - \lfloor n/3 \rfloor) \\ &= 1- 2\cdot \mathbf{1}_{\{n: \, 3\not\mid n\}}\\ &=\ldots \end{align} which I think is neater. Also: $$ a_n= (-1)^{2k+1 \bmod 3} $$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.