Simulating Possible Worlds in Flora-2

Written by on November 12, 2018 in Flora-2, Knowledge Representation, Programming with 0 Comments

The idea of encountering different worlds with varying truths is an interesting one. It has deep connections to philosophy and logic. For a nice discussion, see this article.

Today, we are going to take advantage of Flora-2‘s module system to simulate possible worlds. Flora-2 allows us to dynamically associate any knowledge base (KB) with any module; when loading a KB, we can specify the module name to be associated with that KB (this approach is different from most conventional programming languages such as C++ and Java, where the namespace or package name is statically associated with the file). If module name is not specified, it is assumed to be the main module.

We can thus partition a huge knowledge base into manageable chunks and work with them as needed. This can facilitate efficient reasoning as well.

For our discussion, we are going to consider two possible worlds:

1) A child’s world, where all living beings are friendly with one another
2) An adult’s world, where discrimination exists

We also have some common knowledge that is shared by adults and children.

// Rangarajan Krishnamoorthy - 12/11/2018

// This KB contains world knowledge (common knowledge)
// ['G:/Flora-2/Examples/ModuleExample/Common-knowledge.flr'].

{Man, Woman} :: Human :: LivingBeing.
{Bird, Animal} :: LivingBeing.

{Lion, Tiger, Cat, Dog} :: Animal.
{Parrot, Pigeon} :: Bird.

// Instances of Birds
Parrot1 : Parrot.
Pigeon1 : Pigeon.

// Instances of Animals
Lion1 : Lion.
Tiger1 : Tiger.
Cat1 : Cat.
Dog1 : Dog.

// Men and Women
{Peter, Joe, Phyllis} : Man.
{Sylvia, Mary, Teresa} : Woman.

// Predicate must be true in all the worlds
Necessarily(?p) :- ?p@child, ?p@adult.

// Enough if the predicate is true is any one world
Possibly(?p) :- ?p@child; ?p@adult.

In the above, we define a hierarchy and various instances of classes that belong to the hierarchy. For instance,

Joe is a Man.
Mary is a Woman.
Dog1 is a specific Dog.

Let us now peek into the child world:

// Rangarajan Krishnamoorthy - 12/11/2018

// This should be loaded into a module called "child"
// ['G:/Flora-2/Examples/ModuleExample/World-of-Child.flr' >> child].


// World knowledge is assumed to be available in "main" module

// All living beings are friendly with one another
friendly(?x, ?y) :- {?x, ?y}:LivingBeing@main.

We see that according to the child, everyone is friendly with everyone else. No discrimination at all. What an ideal situation!

Notice how I have referenced the class LivingBeing defined in main module while defining the friendly predicate.

Now let us look at the adult world:

// Rangarajan Krishnamoorthy - 12/11/2018

// This should be loaded into a module called "adult"
// ['G:/Flora-2/Examples/ModuleExample/World-of-Adult.flr' >> adult].


// World knowledge is assumed to be available in "main" module

friendly(?x, ?y) :- ?x \in [Peter]@main, ?y \in [Joe, Mary, Teresa]@main.
friendly(?x, ?y) :- {?x, ?y}:Bird@main.

// "Friendship" is a bi-directional relationship. 
friendly(?x, ?y) :- friendly(?y, ?x).

In this world, all Birds are friendly with one another. Among Humans, the only set of friends are Peter, Joe, Mary, and Teresa. There are no other friends.

Let us check these possible worlds in Flora-2. First we have to load the different KBs into their respective modules:

Loading Modules

Loading Modules

If a module name is not specified while loading a KB, it is assumed to be main, the default module.

Let us pose a few queries based on these possible worlds. Look at the Child’s world first:

Querying Child's World

Querying Child’s World

Here is the adult’s world:

Querying Adult World

Querying Adult’s World

What this clearly demonstrates is that different truth conditions can prevail in different worlds. For example, Dog1 and Cat1 are friends in the world of the child, but not in the world of the adult!

Modal Operators

Modal logic includes two additional operators namely, Necessarily and Possibly. Something is necessarily true if and only if it is true in all possible worlds, and something is possibly true if and only if it is true in some possible world.

I have tried to model these operators thus:

// Predicate must be true in all the worlds
Necessarily(?p) :- ?p@child, ?p@adult.

// Enough if the predicate is true is any one world
Possibly(?p) :- ?p@child; ?p@adult.

These operators are defined as part of common knowledge.

Let us check these operators:

Modal Operators

Modal Operators

The operators seem to work as expected!

The module system of Flora-2 thus allows us to elegantly partition knowledge bases and use that idea to simulate varying truth conditions across different possible worlds. I think this is a very useful feature.

You can download the KB files here: Common-Knowledge.flrWorld-of-Adult.flrWorld-of-Child.flr.

That is it for today. Have a wonderful week ahead!

Tags: , ,

Subscribe

If you enjoyed this article, subscribe now to receive more just like it.

Subscribe via RSS Feed

Leave a Reply

Your email address will not be published. Required fields are marked *

Top