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

// Enough if the predicate is true is any one world



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

// 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:

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

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

// Enough if the predicate is true is any one world



These operators are defined as part of common knowledge.

Let us check these 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.