I am not entirely sure if the title is the correct way to phrase what is occurring. There is a recurring process which I decided to attempt to model using production rules similar to those used in a context-free grammar.The real world process is a production line. It takes 1 unit, after 2 weeks, produces 1 unit, after 4 weeks, that unit will produce another unit - and also 2 of the starting units. After 4 weeks the another unit will produce that unit - and also 3 of the starting units. This continues semi indefinitely, but the range I am looking at is roughly 52 weeks.I came up with this model of production rules$S\rightarrow A$$A\rightarrow S^2B$$B\rightarrow S^3A$I attempted to expand this so that I could formulate a generating function and solve for n=52 (52 being the 1 year mark).$S$,$A$,$S^2B$,$S^5A$,$S^7B$, ...However, I was unable to determine if I was taking the correct approach to solving this situation. I believe that an error here lies in the fact that the duration of time is ignored. Namely that from $S\rightarrow A$ 2 weeks elapse, from $A\rightarrow S^2B$ 4 weeks elapse, and from $B\rightarrow S^3A$ 4 weeks elapse.In order to better understand this situation, I decided to code an example so I could at least see the totals. However, it did not lend itself to producing a summation function.So, given all this, how is it possible to come up with a summation function instead of having to manually iterate through it like this c# approach does? Or, is there a similar/alternate approach to modeling this which will allow an easier summation process?Please feel free to correct any misunderstandings I may have.editsFor example:Week 1: We have 1 unit (S). It sits for 2 weeks until it is ready to become 1 of the next type(A).Week 3: The first unit is now here. It sits for 4 weeks until it is ready to become 1 of the next type(A). At that time, it also becomes 2 of the first type(S).Week 7: The unit from Week 3 has now become 2 of the first type of unit(S). It also created 1 of the second type(A). The 2 units of type S will now sit for 2 weeks until they make 2 units of type A. The 1 unit of type A will now sit for 4 weeks until it makes 1 unit of type B and 2 units of type S.Week 9: The 2 units of type S from week 7 have now sat for 2 weeks. Now they have become 2 units of type A. These two units of type A will sit for 4 weeks and produce 4 units of type S and 2 units of type B.Week 11: The 1 unit of type A from week 7 has now sat for 4 weeks and has now made 1 unit of type B and 2 units of type S. The 1 unit of type B will sit for 4 weeks and then make 1 unit of type A and 3 units of type S. The 2 units of type S will now sit for 2 weeks and make 2 units of type A.Also, the 2 units of type S from week 9 have now sat for 2 weeks and become 2 units of type A. These two units will sit for 4 weeks and become 2 units of type B and will also become 6 units of type S.etc.This can perhaps be represented by a series of recurring relations$s(n) = a(n) + b(n) + c(n)$$a(n) = 2*b(n-4) + 3*c(n-4)$$b(n) = a(n-2) + c(n-4)$$c(n) = b(n-4)$where$s(n) = a(n) = b(n) = c(n) = 0$ for $n < 1$$a(1) = 1$
How can I produce a summation function from this set of production rules for a grammar?
context free;formal grammars;combinatorics
OK, so the question now has a set of recurrence relations.  To solve these, you can plug them in to each other until you get a single recurrence relation.  First, substitute $c(n)=b(n-4)$ to get rid of all of the $c$'s:$$a(n) = 2 b(n-4) + 3 b(n-8)$$$$b(n) = a(n-2) + b(n-8).$$Now substitute in to get rid of the $a$'s:$$b(n) = 2 b(n-6) + 3 b(n-10) + b(n-8).$$So, you've gotten down to a single recurrence relation for the $b$'s.  Solve this using standard methods; see Solving or approximating recurrence relations for sequences of numbers for details.  Then, once you have a solution for the $b$'s, you can reverse the substitutions and obtain a solution for the $a$'s, $c$'s, and finally $s$'s.If you want to find an exact equation for the $b$'s (rather than an asymptotic estimate), the method of generating functions will probably be useful.  You'll have to find the roots of a 10th-degree polynomial ($x^{10} - 2 x^4 - x^2 - 3$, I think), and the solution will likely be an expression of the form $c_1 r_1^n + \dots + c_{10} r_{10}^n$ where $r_1,\dots,r_{10}$ are the roots and $c_1,\dots,c_{10}$ are the appropriate constants.  This might get a bit messy, but it should be doable.Or: You can ask Wolfram Alpha to solve the recurrence relation for you.  Sometimes it is able.  Unfortunately, for this one it seems to have failed: output.