0
$\begingroup$

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

enter image description here

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

I am using RecurrenceTable, but have gotten very far.

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

$\endgroup$
2
  • 2
    $\begingroup$ 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. $\endgroup$ – Bill Apr 15 '20 at 3:04
  • $\begingroup$ 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[1] == \[ScriptCapitalI], F[2] == Fa ** \[ScriptCapitalI] ** Fs ** \[ScriptCapitalI]}, F, {n, 4}] $\endgroup$ – J. M.'s torpor Apr 15 '20 at 15:28
2
$\begingroup$

This recursive algorithm:

fss[i_] := {Subsuperscript["F", i, "*"], "(s)"};
fff[0, n_] = Join[fss[0], fss[s], fss[n]];
fff[i_, j_] := Join[fss[i], fss[s], fss[j], {"+"}, fff[i - 1, j + 1]];
equ[0] = Join[fss[0], {"\[LongEqual]I"}];
equ[1] = Join[fss[1], {"\[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:

enter image description here

$\endgroup$
3
  • $\begingroup$ 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... $\endgroup$ – PiE Apr 16 '20 at 9:23
  • 1
    $\begingroup$ 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: $\endgroup$ – uC-Harry Apr 16 '20 at 14:50
  • 1
    $\begingroup$ factorialSys[0] = 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. $\endgroup$ – uC-Harry Apr 16 '20 at 14:57
0
$\begingroup$

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.

$\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.