Friday, December 5, 2008

Problem Solving: Recursively-defined Functions

*Note: This question is taken from problem set #3. I will present my solution to the assignment.

Q:

Consider the following recursively-de ned function:
\forall n \in N G(n) = 1, if n = 0
3G(n - 1) + 1, if n > 0

Gain some insight into G(n) through unwinding (also called repeated substitution). Make a conjecture about a closed-form for G(n), and then prove your conjecture.

1. UNDERSTANDING THE PROBLEM
First. Given the definition of G(n) for some natural number n, my tasks are
1) finding a closed-form for G(n) using unwinding
2) constructing a conjecture about (1)
3) proving (2)

2. DEVISING A PLAN
Second. Find the connection between G(n) and the closed-form of G(n). I am instructed to apply unwinding in the question. Thus, the closed-form of G(n) should be driven from the repeated substitution. Once I succeed in obtaining the closed-form of G(n), make a conjecture regarding G(n) and its closed form. I have seen similar questions before asking for a conjecture as well. In this type of question, a conjecture can be constructed by comparing the data and the unknown or by indicating the upper/lower bound of the unknown. In this case, it is very likely to a relation such as G(n) = closed-form of G(n).

3. CARRYING OUT THE PLAN
Third.
1) Unwinding G(n):
G(n) = 3G(n - 1) + 1
= 3[3G(n - 2) + 1] + 1 = 9G(n - 2) + 3 + 1
= 9[3G(n - 3) + 1] + 3 + 1 = 27G(n - 3) + 9 + 3 + 1
= 27[3G(n - 4) + 1] + 9 + 3 + 1 = 81G(n - 4) + 27 + 9 + 3 + 1
= [make a guess] 3^n + 3^(n - 1) + ... + 3^0
= (3^(n + 1) - 1) / 2
2) P(n): G(n) = (3^(n + 1) - 1) / 2
3) Claim: \forall n \in N, P(n)
Proof by simple induction
Base Case
When n = 0, G(0) = 1 [by the definition of G(n)] and (3^(0 + 1) - 1) / 2 = 1 as well.
Thus, P(0) is true.
Induction Step
Assume n \in N. Also assume that P(n) is true. So G(n) = (3^(n + 1) - 1) / 2. Then,
G(n + 1) = 3G(n + 1 - 1) + 1
= 3G(n) + 1
= 3[(3^(n + 1) - 1) / 2] + 1 # by IH
= [3(3^(n + 1)) - 3] / 2 + (2 / 2)
= (3^(n + 2) - 3 + 2) / 2
= (3^(n + 2) - 1) / 2
= (3^((n + 1) + 1) - 1) / 2
Therefore P(n) => P(n + 1). Conclude \forall n \in N, P(n).

4. LOOKING BACK
Fourth. Check the result.
G(1) = 3G(0) + 1 = 4 = (3^(2) - 1) / 2
G(2) = 3G(1) + 1 = 13 = (3^(3) - 1) / 2
G(3) = 3G(2) + 1 = 40 = (3^(4) - 1) / 2
G(4) = 3G(3) + 1 = 121 = (3^(5) - 1) / 2
G(5) = 3G(4) + 1 = 364 = (3^(6) - 1) / 2

Monday, December 1, 2008

Ice Age III

Dec. 1-08

The final term test is going to be held this Friday. Moreover, we have our CSC236 exam next week along with other exams for other CSC courses. I want to get over with this quickly.

I have learned to reason and justify various types of problems in this half year. I could see the strength of logic; however, it was really frustrating when I try to prove something very obvious yet not able to phrase it properly. If that happens, I would get paranoid and think: "Why do I think it is obvious?" Then I could hold my head for 30 minutes.

For my fellow students, good luck on you final exams.

Friday, November 28, 2008

Walking Towards the End

Nov. 28-08

It is almost the end of the term. Everybody is hunted by their assignments, tests and projects. My schedule has turned into a chaos as well. Anyway, I have handed in the assignment #3 this Monday. At first sight it looked easy, but it was actually pretty tough. On top of that, the assignment was extremely time consuming. I wonder how long it would cost me if I did that assignment alone.

Wednesday, November 19, 2008

FSA Continued

Nov. 19-08

I didn't go to the Monday lecture, therefore I had to catch up with the class. My friends told me that they were taught how to prove a DFSA. I reviewed Monday slides, but was confused at some details of the DFSA proof. Then, I traced the proof provided on the slides with paper and pen, but didn't work out. I think I need to clear my mind once, then come back to stare at the slides again. If it still doesn't solve my problem, then I will go and ask a TA.

Assignment #3 was released last week. I was determined to start the assignment earlier this time, so I did some brainstorm on it. It didn't look hard, but I could tell it would take me a while to complete it. Final problem set was posted as well on the bulletin board, and it is due this Friday. I have skimmed over the problem set and thought it could be considered as the warming up for assignment #3.

Friday, November 14, 2008

FSA

Nov. 14-08

We have proceeded to the topic of FSAs. I was delighted to know that we were going to work with diagrams and graphs. State invariant had to be clarified before constructing a DFSA. However once we have a working machine, we can easily confirm the correctness of the DFSA. That was what I really liked about this subject.

Problem set #5 was due today. Apparently, problem sets are more helpful than the textbook. Questions on the problem sets were well-designed and encouraged me to do more work.

Wednesday, November 5, 2008

Ice Age II

Nov. 5-08

The second term test is approaching. I haven't regained my confidence yet, and I cannot help myself being nerves about the test. Hopefully, I can stay calm on Friday.

Regular expressions was something completely new to me. I didn't even know there exists such a way to express languages. I didn't realize the significance of regular expressions until I was forced to face it in my CSC207 class. Now, I see the benefits of taking CSC236 and CSC207 together. The thing is that people cannot prove something that they are not aware of. Without a good understanding of the usage of regular expressions, I cannot possibly reason them properly. Thanks to the second assignment of CSC207 where I had some room to play with regular expressions, now I can concentrate more on its theoretical aspect. Again, I was very glad that I have managed to have both CSC207 and CSC236 in the same semester.

Wednesday, October 29, 2008

Happy Halloween

Oct. 29-08

Time passed very fast. I can hardly believe it is the end of October already.

Proving the program correctness is not terribly difficult to do, even through the proof can be tedious when justifying a program with tons of loops and if statements. When proving the accuracy of a program with double loops, I had a hard time to keep track of what exactly I was trying to prove at that moment. One of the TAs suggested me to list out the steps of the proof in the beginning and keep the solution for each phase in separate papers. I will definitely do what he said next time.

We handed in our assignments this Monday. The second assignment was harder than the first one, but it was a great enhancement on the lecture materials.