# Trying to generate strings using Recurrence Table

I'm trying to generate strings recursively that look like this:

 Expand[RecurrenceTable[{F[n] == Fa*F[n - 1]*Fs*F[n - 2] + Fa*F[n - 2]*Fs*F[n - 1], F == 1, F == Fa*F*Fs*F}, F, {n, 4}]]


I am using RecurrenceTable, but have gotten very far.

Can someone help me get started? Thanks for your help.

• Since you are multiplying and adding your expressions Mathematica is going to reorder everything into the default order that algebraic expressions is put into. For example, changed your {n,4} to {n,12} and see what you get. I think it is more common when trying to generate strings that you expect all the symbols to be concatenated and not have the order changed. Perhaps if you can clearly explain what you really want to accomplish then someone might be able to explain another way of doing this.
– Bill
Apr 15, 2020 at 3:04
• Why aren't you using NonCommutativeMultiply[]? RecurrenceTable[{F[n] == Fa ** F[n - 1] ** Fs ** F[n - 2] + Fa ** F[n - 2] ** Fs ** F[n - 1], F == \[ScriptCapitalI], F == Fa ** \[ScriptCapitalI] ** Fs ** \[ScriptCapitalI]}, F, {n, 4}] Apr 15, 2020 at 15:28

This recursive algorithm:

fss[i_] := {Subsuperscript["F", i, "*"], "(s)"};
fff[0, n_] = Join[fss, fss[s], fss[n]];
fff[i_, j_] := Join[fss[i], fss[s], fss[j], {"+"}, fff[i - 1, j + 1]];
equ = Join[fss, {"\[LongEqual]I"}];
equ = Join[fss, {"\[LongEqual]"}, fss[a], fff[0, 0]];
equ[n_] := Join[fss[n], {"\[LongEqual]"}, fss[a], {"〈"},fff[n - 1, 0], {"〉"}];
Column[Table[Row[equ[i]], {i, 0, 4}]]


gives you the output you wanted: • Is there any easier way to implement recursive functions in Mathematica? It's almost like better to utilize another language to do stuff like this...
– PiE
Apr 16, 2020 at 9:23
• Recursive functions are easy as anywhere else. You need some kind of finalization and the recursion. The easiest example is factorial. One way as one line with finalization by If is: factorialIf[n_] := If[n > 1, n*factorialIf[n - 1], 1]; and just one line. In Mathematica the If can be done by the system but now we have two lines like: Apr 16, 2020 at 14:50
• factorialSys = 1; factorialSys[n_] := n*factorialSys[n - 1]; Please keep in mind that we have a function (fss) used for subsuperscript formatting. A function for the recursion (fss) with system finalization. And the function (equ) for equation building as three types for your exeptions. Apr 16, 2020 at 14:57

If $$F$$ is not a matrix then one can factor $$F_{s}$$ out of the set and use

F[n_, x_] := F[n, x] = F[a, x]*F[s, x]*Sum[F[n-j-1, x]*F[j, x], {j, 0, n-1}];
Table[F[n, x], {n, 0, 10}]


with the necessary conditions for $$F_{n}[0, x]$$.

As a note: The form of the proposed equation set uses the notation of $$F_{s}(s)$$ which would require special care in defining what $$F$$ is and to create code to compute it.