COMP SCI 731 - Programming Assignment 1 - Due 7 July 2000
A letter is any of the symbols a-z.
A digit is any of the symbols 0-9.
A variable is a letter followed by zero or more digits.
A string is said to be whitespace if it is a sequence of
characters, these characters being spaces, tabs, or newlines.
The following strings are the boolean formulaes:
- A variable is a boolean formulae.
- If s and t are boolean formulaes, then so are:
- s | t
- s & t
- s = t
- s > t
- !s
- (s)
- If s is a boolean formula and w and w' are whitespace,
then wsw' is a boolean formula.
Here are some examples of boolean formulaes.
The period marks the end of the formulae.
- b | !b.
- p & q = !(!p | !q).
- a & (a>b) > b.
- (p & q) | !p.
- (x1 | x2 | x3) & (!x1 | x4 | !x5) &
(x3 | x1 | x4).
Each variable of a formulae can be true or false.
A setting of each of the variables of a formulae to true
or false is called a truth assignment.
A truth assignment makes the entire formulae true or false where one
one interprets:
- or: s | t is true iff s or t is true
- and: s & t is true iff s and t are
both true.
- iff: s=t is true iff
s and t are both true, or
s and t are both false.
- implication: s>t is true iff
s is false or t is true.
We understand & to have highest precedence, then |, then
>, and finally =. Parenthesis can be used to override the precedence.
Boolean formulae f is a tautology if every truth assignment to
f makes it come out to be true. Above, the first three formulaes were
tautologies, but the next two weren't.
Your job is to write a program to decide if a boolean formulae f is
a tautology. Don't worry about making your program run fast; nobody knows
how to do that. Your program goes into a loop which does the following:
read a formulae; convert it into an internal representation;
print out the formulae;
decide if the formulae is tautological; and display the answer.
When the formula
is not tautological, print a truth assignment which demonstrates this fact.
Each formuale is terminated by a period.
When your program reaches the end of the file, have it terminate.
Here is an input file for you to run your program
on.
Your program should work on an input. If it detects an error in some formulae,
have your program read until the next period, consume it, and continue.
Report the formuale as a syntax error.
You should turn in your program, its execution on the test file,
and a brief description, in English, of how your program works.
You make work with a partner, if you wish. Have fun!