In Boolean logic, a truth assignment, f, maps each variable from the universe of possible variables, S, into the two-point set {0,1} (representing false and true):
f:S -> {0,1}
In Fuzzy logic, a truth assignment, f, maps each variable to a real number in the interval [0,1]:
f:S -> [0,1]
The intent is that if f(X)=1 then X is completely true; if f(X)=0
then X is completely false; and if f(X) is somewhere in between,
well, then X is neither wholly true nor false, but is true to the extent
indicated by f.
In Fuzzy logic, f can be used in interesting ways. For example, let's
talk about the property ``the person is tall.'' Suppose I write a statement
such as "Frank is Tall". Instead of simply saying this statement
is true or false, a more accurate characterization of the truthfulness of
this statement might be to develop a function like:
/ 0 if person.height < 5.5 ft., Tall(person) = | 2 * (person.height - 5.5) if 5.5 <= person.height <= 6.0, and \ 1 if person.height > 6.0 ft.
Now we can interpret "Frank is Tall" as "Tall(Frank)" and the function Tall (playing the role of f) indicates the degree to which "Frank is tall" should be regarded as a true statement.
OK, now that we understand what something like Tall(Frank) means, the question is how to we interpret something like
(Tall(Frank) and Short(Sue)) or (Young(Paul))
The standard definitions in fuzzy logic for these operators are:
truth (not X) = 1.0 - truth(X) truth (X and Y) = minimum (truth(X), truth(Y)) truth (X or Y) = maximum (truth(X), truth(Y))
(Some researchers have explored the use of other interpretations for AND and OR.) Note that if you plug just the values 0 and 1 into these definitions, you get the same truth tables as you would expect from conventional Boolean logic. Of course truth(f(X)) is defined as f(X).
We now describe what formulas look like. A letter is any of the symbols a,..., z, A,...,Z. A word is a sequence of 1 or more letters. A reserved word is any of the following words: not, and, or, and implies. A name is a word which is not a reserved word. For example, "John" and "Tall" are names. A non-empty string which is any sequence of spaces, tabs, and newlines is called whitespace. A statement is any name followed by a left parenthesis followed by a comma-separated list of names followed by a right parenthesis. A statement may also contain whitespace before or after a comma or parenthesis. For example, "Tall(John)" and "MARRIED(Alice, Bob)" are statements. For simplicity in your assignment, no statement may have more than two names (arguments) inside the parentheses. The following are formulas:
In addition, formulas may contain whitespace on either side of statements,
reserved words, or parentheses. We require a formula to contain whitespace
to separate a reserved word from an adjoining statement.
The order of precedence is: not (highest), then and, then or, then
implies. Parentheses can be used in the usual way. The
semantics of P implies Q is defined by not P
or Q.
In your input file, each formula will be terminated by a period. If
a formula does not parse correctly just print an error message and go on
to the next formula.
Here is an example of a valid input file:
age height weight. Bill 19 5.75 155 Yan 20 5.9 140 . Tall(Bill) and Tall(Yan). Tall(Bill) and not Tall(Bill). (SimilarHeight(Bill,Yan) and Tall(Yan)) implies Tall(Bill).
Above we have specified three attributes (called "age", "height" and "weight") for each of two people (named "Bill" and "Yan"). Notice the period at the end of the attribute list denotes the end of the list. Also, a period is used to denote the end of the person list. If the above were the input, C++ functions for the statements Tall() and SimilarHeight() would be provided to you. This will be done in files ~cs110/hw2/code/Functions.h and ~cs110/hw2/code/Functions.cpp. There is also a file ~cs110/hw2/code/Main.cpp to illustrate the use of the above. There is also a sample data file ~cs110/hw2/code/hw2-data which you can test with. In particular, you'll have to know the calling convention to get the statements evaluated at the desired points.
If you find it convenient, you may assume some maximal number of people (say 10, but use a const) and some maximal number of attributes (say 20, again, use a const).
You are to evaluate the fuzzy logic formulas. Each function will depend on the attribute(s) of each person in the call. Here is the output associated to the first formula (assuming our earlier definition of Tall:
Formula: Tall(Bill) and Tall(Yan) In postfix: Tall(Bill) Tall(Yan) and Truth value: .50
That is, echo each formula as you read it. Print it in postfix notation. Then, evaluate the formula, calling our functions as needed to get truth values for the statements.