Friday, November 21, 2014

SLOG #10

    This week the professor talked about the idea that not all problems of mathematical nature can be solved using computers programs that humans can write. We were given an example that involved predicting if a program will terminate, whether reaching the end of its algorithms or raising an exception during execution. The function navel_gaze was used to demonstrate that such a prediction is probably impossible. I was very confused when I read navel_gaze(navel_gaze), because I couldn't read and follow the code at all. I think the message isn't to understand exactly what's going on inside the function (know what H(f, f) will produce when f = navel_gaze()), but to make two assumptions and look at the result from those assumptions. First, assume that H(f, f) is true when f = navel_gaze(), then the program will be stuck on the while loop, therefore navel_gaze(navel_gaze) does not halt. Second, assume that H(f, f) is false when f = navel_gaze(), then the program will simply return 42. In each of the result I see a contradiction, the first assumption suggests that navel_gaze(navel_gaze) will eventually stop, but the result shows otherwise. The second assumption suggests that navel_gaze(navel_gaze) will not stop, whereas the result clearly shows an end to the program.
    The professor also talked about counting in a way that is 1 to 1 and onto, which was fairly straightforward, but things got strange when he talked about a set being countable. A method called diagonalization was used to show that the size of the set of rational numbers is the same as the size of the set of natural numbers, and that the size of the set of real numbers is bigger than the size of the set of natural numbers, but I didn't quite understand the method, and googling diagonalization made it seem more confusing. Hopefully, professor Heap will go through the proof more thoroughly in the next lecture.

Friday, November 14, 2014

SLOG #9

    This week we worked on more proofs involving big-Oh, big-Omega, and saw a glimpse of big-Theta, which probably aims to prove that a function has the same growth rate as another function, since it involves both the lower and upper bound with two different coefficients. 
    I had the most difficulty trying to understand Monday's lecture about incorporating L'Hôpital's rule into a proof. When we are asked to prove that 2^n is not in big-Oh of  n^2, it is easy to think that an exponential function with base greater than 1 probably outgrows any sort of polynomial at some point, but it's hard to intuitively view it as a limit of a ratio (2^n) / (n^2) as n approaches infinity. Using L'Hôpital's rule we were able to evaluate the limit to be positive infinity, which suggests that there is no positive real number C such that when multiplied with n^2 will produce a value that is definitely larger than 2^n on the domain of this ratio. But the result of the limit made me wonder, what if n^2 were changed to -(n^2)? Then the limit would evaluate to negative infinity. Graphically, there is no doubt that 2^n is not upper-bounded to -(n^2), since one lies above and one lies below the x-axis. So then, does the negative infinity mean we have to find some number C that is less than negative infinity (although certainly there isn't any)? What if some other limit of ratio evaluates to a negative finite number, does that mean we automatically get the disproof, given that C must be a positive real number? What if the ratio were inverted, so limit as n approaches infinity of (n^2) / (2^n)  evaluates to zero, how should we start looking for C and B?

Friday, November 7, 2014

SLOG #8

    This week we focused on calculating the upper bound of the worst case scenario for a function and of the other polynomials. The material expanded to proofs involving big-Oh of a polynomial with multiple (3) terms as the upper bound. So first we looked to simplify the original function (also a polynomial) down to one term, by raising every term contained in that function to the highest degree. We then looked to simplify the upper bound by finding new polynomials that are both smaller and contain fewer terms than the original. Eventually we were able to have the upper bound be represented by only one term, and the rest of the proof was done automatically.
    The tutorial questions from this week caused some confusion for me, because we used a formula to sum up the numbers in a sequence when counting the steps of a program, but professor Heap did not used that formula on a similar question during lecture. The example in lecture appeared as follows:
def IS(A):
    i = 1
    while i < len(A):
        t = A[i]
        j = i
        while j < 0 and A[j - 1] > t:
            A[j] = A[j - 1]
            j = j -1
        A[j] = t
        i = i + 1
    When calculating the number of times the inner loop is executed, professor Heap wrote (n - 1)(i), n being the length of the input list, and later simplified it to (n)(n). But in the tutorial, we had to find exactly how many times, for each iteration of the outer loop, the inner loop is executed. For example, the inner loop executed once when i is 1, and five times when i is 5 (that is, if i can go up to and including 5). I was quite confused by these two different methods of calculation, because I thought they served the same purpose. However, it turns out that the example in lecture was an overestimate, and the question in tutorial asks for a very precise answer. So when doing proofs of big-Oh of some program, we can quite lazily (perhaps irresponsibly?) add a few more loops to the execution of the original program as long as the result does not exceed the growth rate of the same order, for example, x^2. However, when we are asked to computer the number of steps performed by an algorithm in the worst-case, we have to make sure that the number or expression we produce actually points to the number of steps for the worst case, not some vague overestimation.