07 Midterm Review

Document Sample

```					                     Programming Languages

• Syllogisms and Proof by Contradiction

• Midterm Review

Dr. Philip Cannata                                1
Notions of Truth
Propositions:
Statements that can be either True or False

Truth:
Are there well formed propositional formulas (i.e., Statements) that return True when their input is
True

truth1 :: (Bool -> Bool) -> Bool
truth1 wff = (wff True)

truth2 :: (Bool -> Bool -> Bool) -> Bool
truth2 wff = (wff True True)

( \ p -> not p)
( \ p q -> (p && q) || (not p ==> q))
( \ p q -> not p ==> q)                       If it was never possible for it not to be True that something was going to
exist, and it will never be possible for it not to be True that something existed
( \ p q -> (not p && q) && (not p ==> q) )    in the past then it is impossible for Truth ever to have had a beginning or
ever to have an end. That is, it was never possible that Truth cannot be
conceived not to exist.
If R is something that can be conceived not to exist and T is something that
cannot be conceived not to exist and T is greater than R and God is that, than
which nothing greater can be conceived, then God exists and is Truth.

Dr. Philip Cannata                                                                                                                  2
Facts
1.      A is an Animal.
2.      A Barks.                                     Database
3.      A is a Dog :- A is an Animal, A Barks.   (A is a Dog IF A is and Animal AND A Barks)
:-                    ,
Rule
4.      -(A is a Dog)                                             Query (If you want to know if A is a
A is not a Dog                                       Dog based upon the Facts and Rules in the
Database try to see if A is not a Dog.)

Therefore A is a Dog

Can this reasoning be automated?
Dr. Philip Cannata                                                                                               3
Syllogisms
Note: this is Prolog notation. In ―standard‖ notation, this
would be P  Q.

P implies Q (i.e., Q is True if P is True or If P is True then Q is True)

Syllogism – e.g., Modus Ponens – 1). P is True; 2). P  Q is True, therefore Q is True.

Green – assume 2 things; the implied Result is in Red; if the result is just True, then the
syllogism is Valid, if the results are True and False, then the syllogism is Invalid.
Dr. Philip Cannata                                                                                    4
P1             P2

1). Let P = It’s raining, I’m outside (comma means “&&”)
Database

2). P1. (P1 is True, i.e., it’s raining) Facts  Rule
3). P2. (P2 is True, i.e., I’m outside)                                               Pattern 1:       P
4). Q :- P = I’m wet :- It’s raining, I’m outside. (if it’s raining and I’m
outside then I’m wet)
Q :- (P1, P2).
5). –Q    (To answer the Query “Am I wet” against the Database, assume I’m not wet)
-Q
6). –(It’s raining, I’m outside)                   ( From 4 and 5 and Pattern 1 )
 -(P1, P2)
7). –I’m outside                                   ( From 2 and 6 and Pattern 2 )
8). Contradiction – Therefore I’m wet              ( From 3 and 7 and Pattern 3 )
Pattern 2:
P1.              R
-(P1, P2)
 -P2            S

Pattern 3:
P2.
-P2

Dr. Philip Cannata                                                                                                    5

1.      A is an Animal.
2.      A Barks.                                 Database
3.      A is a Dog :- A is an Animal, A Barks.

4.      -(A is a Dog)                                        Query (If you want to know if A is a
Dog based upon the Facts and Rules in
5.      3 and 4 and Pattern 1  -(A is an Animal, A Barks)   the Database try to see if A is not a Dog.)

6.      1 and 5 and Pattern 2  -A Barks
7.      2 and 6 and Pattern 3  Contradiction
8.      Therefore A is a Dog

Dr. Philip Cannata                                                                                           6
Midterm Review

What we cannot speak about we must pass over in silence.
• The world consists of independent atomic facts—existing states of affairs—out of which larger facts are built.
• Language consists of atomic, and then larger-scale, propositions that correspond to these facts by sharing the same "logical form".
• Thought, expressed in language, "pictures" these facts.
Tractatus

Dr. Philip Cannata                                                                                                                                       7
Previous Midterm Exam

Dr. Philip Cannata                           8
Study the Homework and Quizzes

Dr. Philip Cannata                                    9
You should
now know
the concepts
highlighted
in green.

Dr. Philip Cannata   10
Javacc Parsers
PARSER_BEGIN(Parser)

import java.io.*;
import java.util.*;                                                     Javacc uses these to build a Lexical
public class Parser {
public static void main(String args[]) throws ParseException {        Analyzer (Token Manager) and a
Parser parser = new Parser (System.in);

}
parser.ae();                                                        Syntactic Analyzer (Parser)
}

PARSER_END(Parser )

SKIP :
{
""
| "\t"
| "\n"
| "\r"
| <"//" (~["\n","\r"])* ("\n"|"\r")>                                         Grammar Production Rules and Actions
}

TOKEN:
{
< LCURLY: "{" >
| < RCURLY: "}" >                                                        void ae() :
{ Token n; }
| < MINUS: "-" >
{
| < PLUS: "+" >
n = <INTEGER> { System.out.print("(num " + n +")"); }
| list()
}
Tokens, Terminals                 }
TOKEN: /* Literals */
void list() :
{
{}
< INTEGER: (["0"-"9"])+ >
{
}
ae() )* <RCURLY> { System.out.print(") "); }
TOKEN:
|          <LCURLY> <MINUS> { System.out.print(" (sub ");} ( ae() )*
{
<RCURLY> { System.out.print(") "); }
<ERROR: ~[] >
}
}
Dr. Philip Cannata                                                                                                                                    11
Example Javacc Parser Input and Output

Input
Relation X Y Z
Relation a
Compose Y with X
Compose a with Z

Output
\$ cat test.r | java Rel
Saw IDENTIFIER X
Saw IDENTIFIER Y
Saw IDENTIFIER Z
Saw a RELATION
Saw IDENTIFIER a
Saw a RELATION
Saw Composiiton of Y with X
Saw Composiiton of a with Z

Dr. Philip Cannata                                            12
PARSER_BEGIN(Rel)                                                  void program() :
{}                              Example Javacc Parser
import java.io.*;                                                  {
import java.util.*;                                                  ( rels() )+ ( comps() )*
}
public class Rel {
public static void main(String args[]) throws ParseException {   void rels() :
Rel parser = new Rel(System.in);                               { String id; }
parser.program();                                              {
}                                                                  <RELATION> ( id = identifier() { System.out.println("   Saw IDENTIFIER "
}                                                                  + id); } )+
{ System.out.println("Saw a RELATION"); }
PARSER_END(Rel)                                                    }

SKIP :                                                             String identifier() :
{                                                                  { Token t; }
""                                                             {
| "\t"                                                             t = <IDENTIFIER>
| "\n"                                                             { return new String(t.image); }
| "\r"                                                           }
| <"//" (~["\n","\r"])* ("\n"|"\r")>
}                                                                  void comps() :
{ String id1, id2; }
TOKEN:                                                             {
{                                                                    <COMPOSE> id1 = identifier() <WITH> id2 = identifier()
< RELATION: "Relation" >                                         { System.out.println("Saw Composiiton of " + id1 + " with " + id2); }
| < COMPOSE: "Compose" >                                         }
| < WITH: "with" >
}

TOKEN: /* Literals */
{
< IDENTIFIER: [ "A"-"Z", "a"-"z" ]
( [ "A"-"Z", "a"-"z", "0"-"9", "_"] )*
>
}

TOKEN:
{
<ERROR: ~[] >
}
Dr. Philip Cannata                                                                                                                                  13

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 2 posted: 6/22/2011 language: English pages: 13
How are you planning on using Docstoc?