sCASP: some amazing queries

I’ve playing around with sCASP again and don’t cease to be amazed at its beauty. Say we have this small program, just four facts:

:- use_module(library(scasp)).

bird(sam).
bird(tweety).
-bird(lion).
-bird(monkey).

Now look at the amazing queries we can do:

% okay, this one not so amazing
?- scasp(bird(X),[]).
X = sam ;     % sam is a bird
X = tweety ;  % tweety is a bird
false.

% maybe X is a bird?
?- scasp(not -bird(X),[]).
X ∉ [lion,monkey] ; % X may be a bird, if it is different from
                     % lion and monkey (wow!)
false.
% is there an X for which I am not sure whether it is a bird or not?
?- scasp((not -bird(X),not bird(X)),[]).
X ∉ [lion,monkey,sam,tweety] ; % if X is different from lion,monkey,
                                % sam or tweety then I am not sure
                                % whether it is a bird or not 
                                % (wow squared!)
false.

% maybe X is not a bird?
?- scasp((not bird(X)),[]).
X ∉ [sam,tweety] ; % X might not be a bird, if X is different from
                    % sam or tweety (wow!)
false.

% do I know for sure that X is not a bird?
?- scasp((-bird(X)),[]).
X = lion ;    %  yes, lion is not a bird
X = monkey ;  %  yes, monkey is not a bird
false.

This ability to handle uncertain knowledge is quite a beauty.

2 Likes

That’s cool :slight_smile:

I am having a bit of a hard time wrapping my head around what queries such as this one mean…

/JCR

Let’s look at it in parts.
First:

-bird(X).

It means that I am definitely sure that X is not a bird.

Second:

not bird(X)

This is different from -bird(X). Whereas -bird(X) means I am definitely sure X is not a bird, not bird(X) means I don’t have evidence that X is a bird: I think X is not a bird but I leave it open that it could be. In other words, it leaves the possibility open, it is uncertain knowledge.

Third:

not -bird(X)

Putting First and Second together, this means 'I don’t have evidence that X is not a bird, or in other words: X may be a bird, but I am not definitely sure. So the query:

% maybe X is a bird?
?- scasp(not -bird(X),[]).
X ∉ [lion,monkey] ; % X may be a bird, if it is different from
                     % lion and monkey (wow!)
false.

Means I ask: Is there a possibility that X is a bird?
and the answer "X ∉ [lion,monkey] means:

Yes, X could be a bird if X is different from lion and monkey, I am not definitely certain that X is a bird, but could be.

6 Likes

Great explanation, thanks! I suspected that the query meant something like this.