Finding a single equation without use of words, only functions and math, that solves outputs patterns within patterns

378 Views Asked by At

If you were given a sequence that went something like $$1,1,3,2,5,3,7,4,9,5....$$ You would notice that there are two patterns alternating, one being 1,3,5,7,9... and the other being 1,2,3,4,5...

How would you define this sequence with one single function, $k(n)$,without the use of words or extra functions such as "If n is even, apply the function $f(n)=\frac{n}{2}$ and if n is odd, apply the function $f(n) = n$"

Is there an elegant way to output such a sequence? I tried to do it and have my own way using a lot of terms but want to know if there is a much simpler solution

Furthermore, if your particular equation works for this equation, would it work for $p=3,4,5,6...$ patterns within a pattern. In addition, the patterns rotate uniformly meaning if there were 4 patterns, every 4 terms the same function is used to output a number based on the term number: An example of 4 patterns in a pattern that follow the following functions $f(n)=n,f(n)=n^2,f(n)=3n,f(n)=\lfloor{\sqrt{n}}\rfloor$, a certain function $k_p(n)$ where $p=4$ would output $$1,4,9,2,$$$$5,36,21,2$$$$9,100,33,3...$$ (The spacing is just for visual purposes and makes it easier to see how each pattern rotates every 4 terms)

Whatever solution that outputs such a pattern should also be able to change or be manipulated easily to accommodate more or less patterns with functions for each pattern varying in complexity

Update: A common way that people are trying to use to solve the first example with only two simple patterns is through the use of the properties of $(-1)^n$ which outputs -1 or 1, an alternating sequence between two values, perfect for the first example. I hope that further answers to this question should somehow expand to the next part of it as I know there are more than enough equations that output the first pattern.

My Work: I tried using modulus arithmetic to output the values I wanted that would sort of turn off or turn on certain functions depending on the term $n$. For the first example, I made the equation $k_2(n)= (mod(n,2))*n + (mod(n+1,2))*(\frac{n}{2})$ I think further work can be done in improving the modulus method as there is a common number between the mod sections of $k_2(n)$ and the number of patterns $p$ which is 2

5

There are 5 best solutions below

7
On BEST ANSWER

Note that

$$f(x)=\frac12((-1)^x+1)$$ is zero when $x$ is odd and $1$ when $x$ is even, similarly, we can make such function that is zero when $x$ is even and $1$ when odd.

Thus,

$$1,1,3,2,5,3,7,4,9,5,...$$

Could be written as

$$k(x)=(x+1)\left(\frac12(1-(-1)^x)\right)+\frac{x}{2}\left(\frac12(1-(-1)^x)\right)$$

Which simplifies to

$$k(x)=\frac12+\frac{3x}4-\left(\frac12+\frac{3x}4\right)(-1)^x$$


In fact, you can do this with every power of $2$; simply take that first function $f$, and apply it on $f$, so that we have a function that is $1$ only if $x$ is divisible by $4$, etcetera. If we wish to do this with $k=3$, then it already becomes more complicated. We need a number that cycles with period $3$ when raising it to a power; well, an easy one would be $\omega_3=e^{\frac23i\pi}$, a cube root of $1$. Then we see

$$f_3(x)=\frac13\left(\omega_3^x+\omega_3^{2x}+\omega_3^{3x}\right)$$

has the exact property we want; it is $1$ only if $x$ is a multiple of $3$, and $0$ otherwise. We can in fact do this for every prime number $p$; define $\omega_p=e^{\frac 2pi\pi}$ such that

$$f_p(x)=\frac1p\left(\omega_p^x+\omega_p^{2x}+\cdots+\omega_p^{px}\right)$$

and then $f_p$ is $1$ only if $x$ is divisible by $p$, and $0$ otherwise. We can now create such function for every $n$, since if $n=p_1p_2\cdots p_k$, then $f_n(x)=(f_{p_1}f_{p_2}\cdots f_{p_k})(x)$.

2
On

For this particular question : $$T_n=\frac{3n}{4} + (-1)^{n-1}\frac{n}{4}$$

0
On

Using trigonometric functions:

$$f(n) = |\sin(\frac{n\pi }{2})|n + |\cos(\frac{n\pi }{2})| \frac{n}{2}$$

0
On

$$f(n)=\frac{n}{2-n+2\lfloor\frac{n}2\rfloor}$$ Not very elegant, though.

0
On

$$n\cdot\frac{n\bmod2+1}{2}.$$