CS 100 - Week 2 Lecture 2 - August 30, 2012

*   (started by discussing Boolean operations and, or, and not a bit
    more in the context of DrRacket, and going over their truth tables;
    also gave a truth table for a more complex compound Boolean expression)

*   ONE way of looking at Prolog:

    you have a KNOWLEDGE BASE that holds
    everything that Prolog knows at a given
    time; (facts and rules...)

    then, you start the Prolog interpreter,
    load a knowledge base,
    give it queries, and it tells you whether
    it can prove that query given its
    knowledge base (using deductive reasoning)
 
*   in Prolog, you indicate the AND operation
    with a , (comma character)
*   in Prolog, you indicate the OR operation
    with a ; (semicolon character)
*   ...and you indicate the NOT operation (which
    is a little different...) with \+
    (but some Prologs define not

*   true and false are the Boolean literals;
    and there are plain numbers 3, 3.1, etc.

*   Prolog can be viewed from several different perspectives,
    and some of these use different terms for the same thing;

    ...but we're going with the perspective that in Prolog, you have
    predicates, facts, and rules
    [reference: http://www.amzi.com/AdventureInProlog/a1start.php]

    *   a predicate looks like a function call in math -- a name, and arguments in
        parentheses (and if more than 1 argument, they are separated by commas)

        cool(arcata)
        mother_of(thomas, sharon)

        *   note: it matters (syntax) that these DON'T have spaces in the names, and that 
            these start with lowercase letters --

	    we'll see that, in Prolog, variables -- expressions that represent values --
            start with an Uppercase letter;

    *   from Amzi tutorial: each predicate in a Prolog program is defined by the 
        existence of one or more clauses in a Prolog knowledge base,

        where a clause can either be a fact or a rule.

    *   a fact in a Prolog knowledge base is just a predicate followed by a period --
        the above predicate examples would be proper facts in a Prolog knowledge base 
        if each was ended with a period:

        cool(arcata).
        mother_of(thomas, sharon).

        and a Prolog knowledge base is a plain text file, whose name ends in .pl,
        containing such facts, and also rules (which we'll discuss next week)

    *   When you start the Prolog interpreter, you then type in QUERIES,
        and Prolog tries to prove each, letting you know if it can prove them (if it
        can be proven to be true given the current knowledge base,
        or if it cannot;

        IF a query includes a variable -- a word that starts with an uppercase
        letter -- then IF Prolog can prove it, it lets you know what value it
        had to set, or BIND, that variable to in order to prove it;

        *   a query should end with a period, too

        *   you can use variables as the arguments within predicates in a query

        *   you can use , and ; to write queries involving Boolean AND and Boolean
            OR operations

        *   (indeed, if you want to see if Prolog can prove something in more than
	    one way -- say, by setting the variable to a different value --
	    type a semicolon, for a Boolean OR, after the first result, to get another
	    attempt;)

    *   you can start the SWI-Prolog interpreter by typing swipl,
        and you can start it and load an initial knowledge base by starting it using:
	swipl -f desired_knowledge_base.pl

        (you can load the contents of ANOTHER knowledge base while within swipl
        by using the special query:

        ['desired_knowledge_base.pl'].

    *   (you'll see me using another special query,
        protocol('desired_log_file.txt').

        ...which is always true, and has the side-effect of echoing the Prolog session
        from that point onward into a text file with the specified name)

*   (also note: you can end/exit swipl with the special query:
    halt.
    )