[Tex/LaTex] Writing sequence terms


What would be the best way to write out the terms of a sequence, somehow like this, but preferably aligned?

Is there a way to automatically generate the terms from an equation i.e. with n² for sequence (3)?

If so, how could one write the relation between the terms and their indexes like so:

Best Answer

The following is for automated generation. It wasn't clear what "aligned" was supposed to mean. Thus I have applied various methods.






  \xinttheexpr seq(2^n, n=0..15)\relax, \dots\\
  \xinttheexpr seq(2n+1, n=2..17)\relax, \dots\\
  \xinttheexpr seq(n^2, n=1..16)\relax, \dots\\
\edef\L{\xinttheiiexpr seq(subs((n=m^2)?{m}{-n}, m=sqrt(n)), n=1..16)\relax}%
  \xintFor #1 in \L\do{\ifnum #1<0 \sqrt{\gobble #1}\else #1\fi, }\dots\\
\edef\L{\xinttheexpr seq(n/(n+1), n=1..16)\relax}%
  \xintFor #1 in \L\do{\xintFrac {#1}, }\dots\\
  \xinttheexpr rseq(2; @-2, i=1..15)\relax, \dots\\
\edef\L{\xinttheexpr seq(1/n, n=1..16)\relax}%
  \xintFor #1 in \L\do {\xintFrac{#1}, }\dots\\
\edef\L{\xinttheexpr seq(n, n=1..16)\relax}%
  \xintFor #1 in \L\do{\ifodd #1 #1\else\xintFrac{1/#1}\fi, }\dots\\
\edef\L{\xinttheexpr seq((1/n,-1/n),n=1..[2]..16)\relax}%
  \xintFor #1 in \L\do{\xintSignedFrac{#1}, }\dots\\
\edef\L{\xinttheexpr seq((1/n,(n+1)/(n+2)), n=1..[2]..16)\relax}%
  \xintFor #1 in \L\do{\xintFrac{#1}, }\dots\\
\edef\L{\xinttheexpr seq(x, x=1..12)\relax}%
\xintFor #1 in \L\do
      \xinttheexpr 2^(#1-1)\relax\\\uparrow\\ #1
   \dots\\ \\\dots
   2^{n-1}&\dots&\text{ (terms of the sequence)}\hfill\\
   \uparrow &&\\ 
   n&\dots&\text{ (position numbers of the terms)}
\edef\L{\xinttheexpr rseq(1; @+i^2, i=2..16)\relax}%
\edef\M{\xinttheexpr seq(reduce(n(n+1)(2n+1)/6), n=1..16)\relax}%
\edef\N{\xinttheexpr seq(n, n=1..16)\relax}%
  \xintFor #1 in \L\do{#1&}\sum_{i=1}^n i^2\\
  \xintFor #1 in \M\do{#1&}\frac{n(n+1)(2n+1)}{6}\\
  \xintFor #1 in \N\do{#1&}n\\


The \xintFor is used only when some formatting is needed, for example printing fractions as A/B is not enough one wants \frac{A}{B}, or when one wants to replace the commas by tab stops for alignment.

Technical note: \xintFor works with comma separated values; the list may be encapsulated in a macro, but this macro is expanded only once. Hence, for simplicity we first construct the list by an \edef (we could have use a \romannumeral-`0 prefix rather).

Second technical note: the list (4) of square roots uses the trick to prefix the number with a sign if it is not found to be a perfect square. Then the formatting checks for this sign.

The list numbered (10) in OP seems to have an issue. I don't understand the 4/4. A 4/5 fits well with the rest, though.

enter image description here