I don't know if this is the correct sub-forum for this question. If it isn't, I'm sorry.

I have this expression that expands based on the variables given:

\line

\line

\line\line\line

\line\line

\line

What I want to do is generalize this expression, i.e.: , but I don't know how to go about this. I think I have to use recursion but I don't see how it should be done.

Any help with this would be appreciated.