Sunday, September 28, 2014

Week#3

First of all, I would like to appreciate about this course is designed well to make us work and understand the concept / logic deeply and thoroughly. Without tutorials, I could get puzzled with this course.

In week-3 lectures & tutorials, I learned how to interpret English words to the symbols that computer scientists use. The tutorial this week made the paradox (or myth) I had much clearer.

I think I'm good this week with CSC165.

Now... I want to note about a mathematics' Law - De Margan's Law. This is sometimes critical when it comes to Python programming.

For example, (this is from my previous course in summer - CSC108), if there are two events in Python Class variables and we want to check if the two events overlap or not. Here is the code for checking the overlap (recall this is from my previous course in summer).


1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class Event:    
    """A new calendar event."""

    def __init__(self, start_time, end_time, event_name):
        """ (Event, int, int, str) -> NoneType

        Precondition: 0 <= start_time < end_time <= 23
        
        Initialize a new event that starts at start_time, ends at end_time,
        and is named event_name.

        >>> e = Event(12, 13, 'Lunch')
        >>> e.start_time
        12
        >>> e.end_time
        13
        >>> e.name
        'Lunch'
        """
        
        self.start_time = start_time
        self.end_time = end_time
        self.name = event_name

    def overlaps(self, other):
        """ (Event, Event) -> bool

        Return True iff this event overlaps with event other.

        >>> e1 = Event(6, 7, 'Run')
        >>> e2 = Event(0, 7, 'Sleep')
        >>> e1.overlaps(e2)
        True
        """
        
        return not ((self.end_time <= other.start_time) or \
        (other.end_time <= self.start_time))

When I was doing this exercise, I remember I put:


1
return (self.end_time <= other.start_time) and (other.end_time <= self.start_time)

in the def overlaps function. It is literally correct in English. However, Python does not check the right hand side of  and if the left hand side fails.

A and B
For example in this statement, if A is false, then this whole statement is false whether or not B is true. Therefore, Python program will never get to B when A fails.

This line needs to be checked both ways from the right to left and from the left to right. In order to do this, De Morgan's Law kicks in.
A and B <=> Not (A or B)
This is beautiful! This is very simple, but quite important in programming language.



Saturday, September 20, 2014

Week#1 & Week#2

The Week-1 material wasn't so difficult, but I still needed to re-cap "set theory" which I learned in my former university. (I have BA in Economics from Glendon College, York University.) Since my BA was completed for a while ago, the math part of the lecture was a bit challenging until I organize my brain to pull out my math memory from the cortex. But the tutorial helped me understand the basics and Venn Diagram which clarifies the problems.

Now, the Week-2 material is something that I have to note it here in my blog, because "implication" is new discovery for me.

Universal claim is verified when there are no counterexamples, and is falsified when there is at least on counterexample. Existential claim is verified when there is at least one example, and is falsified when there is no example at all. This is clear to me.

Once it comes to "implication", the fun part begins (as I'm a computer geek or nerd haha). I actually have my own business in Web Hosting and IT Solution since 1999 and I sometimes have to create a program. There is always at least one if then statement when programming for a client. Well... that's because if statement is the most useful one to control/prohibit/allow several arguments within the program, and it's quite logical or I would say it's simple But when it comes to a plain English statement, things are more complicated (and also fun).

If you eat vegetables, then you can get a snack.

This is something I always tell my daughter and son. If my son does not eat vegetables, the function called eat_snack won't be executed. But then... as I'm a good daddy, I execute the eat_snack function even though my son didn't eat the vegetables. Well... this is the biggest difference between computer language and natural language. So this statement can be falsified in a real world, but it cannot be falsified in Python program (I mean, of course U of T is good at AI, so this may be programmable in computer world, but... anyways, usually it's not doable in the simple Python program). I've enjoyed a lot in thinking about "implication" like this. I believe I've got some idea to this course.

One another fun part I want to note here is "Vacuous Truth".

So, what is vacuous?

By the way, my first language is Japanese even though I was born in Canada. I've spent my childhood up to high school in Tokyo.

Anyways, vacuous means emptied of or lacking content ("Merriam-Webster.com"). Okay, this is very intriguing.


This equation implies x is bigger than x + 5 . Okay, it sounds astronomical to me. If the number gets larger and larger, it could happen at some point of time. But it doesn't exist in real numbers. But vacuous truth holds for this equation because there is no counterexample. Now CSC165 is getting more serious and becoming a "U of T" course. My first impression was "what?", but now it's getting more comfortable to me.

I still don't know how this course relates to "programming" yet. But I at least enjoy this course means that I should be able to handle (or I would say do well) on this course.

Now it's time to prepare myself for the next tutorial...


Monday, September 15, 2014

sLog sLog sLog....

This is a slog for CSC165H1 Fall 2014.
There will be numerous posts during the term.

Thank you.

Spencer Ogawa