Selasa, 15 April 2008

Scope

Warning : This posting may contains the spoiler of the quiz, read on your own risk ... :)

After we set the facts & rules, we must define the predicate, scope of each stament.
Predicate is a relation between an object to another.
Scope is the set of valid / possible values for the variables in a statement.

For example :

Position(x,y)

have the predicate Position and scope for x & y as :

x : set of possible countries : {Norwegian,Dane,Brit,German,Swede}
y : set of possible numbers : {1,2,3,4,5}

So, if we evaluate the statement :

Position(German,2)

It is a valid statement, but :

Position(France,7)

is not a valid statement (we can call it a negative statement, which value is FALSE)
because one or more values on the statement is not in the scope.

A true statement (fact) is also a valid statement.
But if a statement is valid does'nt mean it is a true statement.
For example, if we know that Norwegian house is the first house then

Position(Norwegian,1) => TRUE

If there is another statement says that German house is the first house then

Position(German,1)

The above statement is valid because the values is in the scope but we know it is not a fact, because the first position is already been filled by the Norwegian.

So :

Position(German,1) => FALSE

The predicate "Position" have a one-to-one relation, that means that one object can only related to one other object and cannot be related again to other object
So, if the Norwegian is placed #1 then the other countries cannot take the place

If the relation is not a one-to-one relation then some object can be related to more than one other object.

For example :

LivesNext(Brit,Dane) & LivesNext(Brit,German)

The Brit is lives next to Dane & the Brit is also lives next to German

$$$

Let's we see the list again :

Facts
LessOne(1,2)
LessOne(2,3)
LessOne(3,4)
LessOne(4,5)
HouseColor(Brit,Red)
Pet(Swede,Dogs)
Beverage(Dane,Tea)
Position(Norwegian,1)
Cigar(German,Prince)

Rules
LivesNext(x,y) -> LeftSide(x,y) v RightSide(x,y)
LeftSide(x,y) -> Position(x,v) ^ Position(y,z) ^ LessOne(v,z)
RightSide(x,y) -> Position(x,v) ^ Position(y,z) ^ LessOne(z,v)
HouseColor(x,Green) ^ HouseColor(y,White) -> LeftSide(x,y)
HouseColor(x,Green) -> Beverage(x,Coffee)
Cigar(x,PallMall) -> Pet(x,Bird)
HouseColor(x,Yellow) -> Cigar(x,Dunhill)
Position(x,3) -> Beverage(x,Milk)
Cigar(x,BlueMaster) -> Beverage(x,Beer)
Cigar(x,Blend) ^ Pet(y,Cat) -> LivesNext(x,y)
Pet(x,Horse) ^ Cigar(y,Dunhill) -> LivesNext(x,y)
HouseColor(x,Blue) -> LivesNext(x,Norwegian)
Cigar(x,Blend) ^ Beverage(y,Water) -> LivesNext(x,y)

so we can define the scope based from statements above &
the question (WHO KEEPS FISH? :)) :

Scope
LessOne(x,y)
1-1 Relation
x: {1,2,3,4}
y: {2,3,4,5}
HouseColor(x,y)
1-1 Relation
x: {Norwegian,Dane,Brit,German,Swede}
y: {Yellow,Blue,Red,Green,White}
Pet(x,y)
1-1 Relation
x: {Norwegian,Dane,Brit,German,Swede}
y: {Bird,Dog,Horse,Cat,Fish}
Beverage(x,y)
1-1 Relation
x: {Norwegian,Dane,Brit,German,Swede}
y: {Milk,Beer,Tea,Water,Coffee}
Position(x,y)
1-1 Relation
x: {Norwegian,Dane,Brit,German,Swede}
y: {1,2,3,4,5}
Cigar(x,y)
1-1 Relation
x: {Norwegian,Dane,Brit,German,Swede}
y: {PallMall,BlueMaster,Blend,Dunhill,Prince}
LivesNext(x,y)
x: {Norwegian,Dane,Brit,German,Swede}
y: {Norwegian,Dane,Brit,German,Swede}
LeftSide(x,y)
1-1 Relation
x: {Norwegian,Dane,Brit,German,Swede}
y: {Norwegian,Dane,Brit,German,Swede}
RightSide(x,y)
1-1 Relation
x: {Norwegian,Dane,Brit,German,Swede}
y: {Norwegian,Dane,Brit,German,Swede}

$$$

The scope is useful to check the validity of a rule & check the available values that is not yet used

When we have some facts and the 1-1 relation scope, then the available values is the set of scope exclude the values used in facts.

For example :

Position(Norwegian,1)
Position(Brit,3)
Position(German,4)
Position(Swede,5)

The scope is :

Position(x,y)
1-1 Relation
x: {Norwegian,Dane,Brit,German,Swede}
y: {1,2,3,4,5}

The available values is :

Position(x,y)
1-1 Relation
x: {Dane}
y: {2}

So we can get a new fact :

Position(Dane,2)

$$$

Maybe we are not always get available values with only one combination left, but we can make a solution with the help of some rules

For example :

Beverage(x,y) : (3 combination left)
1-1 Relation
x: {Norwegian,German,Swede}
y: {Beer,Water,Coffee}

Related Rules (Have a predicate "Beverage") : (2 Rules)

HouseColor(x,Green) -> Beverage(x,Coffee)
Cigar(x,BlueMaster) -> Beverage(x,Beer)

Related Facts : (Related in predicate to 2 Rules above)
HouseColor(Norwegian,Yellow)
Cigar(Norwegian,Dunhill)

We can conclude that :
Beverage(Norwegian,Coffee) => FALSE
Beverage(Norwegian,Beer) => FALSE

So, for x = Norwegian, then :

Beverage(Norwegian,y) :
1-1 Relation
y: {Beer,Water,Coffee}

Exclude the Coffee & Beer from the list of Beverage :

Beverage(Norwegian,y) :
1-1 Relation
y: {Water}

So, we got a solution :

Beverage(Norwegian,Water)

$$$

Tidak ada komentar: