How does it work?

Categories

Deduce lives and breathes on the information it's provided. Deduce calls these individual bits of data facts. To explain how Deduce is able to reason, we'll start with some simple examples and work our way up from there. Suppose we enter the fact, "Spot is a dog." Deduce begins by breaking down the sentence into its components. In this case, we have a subject, a verb, and an object:
Subject: Spot
Verb: is
Object: a dog
Since the verb is a form of the verb "to be", this statement is treated specially. Deduce understands this verb as a way of categorizing one thing as a type of something else. The object, "a dog" can be thought of as the category, and the subject, "Spot" is a member of that category. Deduce represents this internally as a graph:
SPOT --> DOG
Now let's add another fact, "A dog is an animal":
SPOT -->DOG -->ANIMAL
Now we ask the question: "Is Spot an animal?" To answer this, Deduce starts with the word "Spot" and looks for a path to "animal". In our example, this can be done by passing through "dog" and then to "animal". Since a path can be found, the answer to the question will be yes. If no path could be found, the answer would have been "I don't know".

More categories

Let's try an example that has more data in it. Suppose we have the following set of facts:
Spot is a dalmatian.
A dalmatian is a dog.
A dog is an animal.
A dog is a canine.
A canine is a dog.
Felix is a cat.
A cat is an animal.
This will generate the following graph:
FELIX --> CAT --- |
V
SPOT --> DALMATIAN --> DOG --> ANIMAL
v ^
CANINE

One thing worth noting is that there's a loop in this graph between dog and canine. What this means is Deduce has to be careful when tracking through the graph not to end up in an infinite loop. It accomplishes this by leaving a trail as it searches, and removing the trail as it backtracks.

Looking at the graph, there are a number of questions that can be answered by following the arrows. Here are some examples:

Is Spot a canine?
Is a canine an animal?
Is Felix an animal?
Some questions that can't be answered (and will return "I don't know") include:
Is Spot a cat?
Is Felix a dog?
Is an animal a cat?
There are a few things worth noting at this point. We've seen that arrows, by default, only point in one direction. So a dog may be an animal, but that doesn't mean an animal will necessarily be a dog. It could be argued that if the former statement is true, the latter will be true at least some of the time. However, at this point in time, Deduce doesn't understand things that are true only some of the time (but this is on my todo list). Also, given the types of input we've discussed so far, Deduce will never answer a question with "No". To do this, we must introduce the concept of negatives.

Negatives

In order to express a relationship that's not true, we must make a fact negative. This is accomplished with the word "not" (or similar words, like "no" and "never"). So, we might say something like:
A cat is not a dog.
An animal is not a plant.

What's interesting to note here is that negatives work both ways: if a cat is not a dog, it can be inferred that a dog is not a cat. The reason for this will be explained later.

To represent a negative statement in a graph, we'll draw a line through the arrow like this:

CAT -+> DOG
If we have a graph with negatives, we can't just freely follow the arrows the way we did with positive statments. Negative arrows represent a sort of stopping point. Once we follow one, we can go no further (we must backtrack). The following example should make this a little clearer.
Spot is a dog.
A dog is an animal.
A dog is not a cat.
A cat is a mammal.
A cat is a feline.

SPOT --> DOG --> ANIMAL
X
CAT --> MAMMAL
V
FELINE
From this example, we can follow the arrows to find that Spot is not a cat. However, no inferences can be made beyond that point. "Cat" belongs to two categories: feline and mammal. Logically, we can't make any conclusions about whether Spot is a feline or mammal. Hopefully this example makes it clear, since Spot is obviously not a feline, but he is a mammal.

Actions

When interacting with Deduce, we often want to describe things based on what they do rather than just what they are. Examples include:
A dog will bark.
A bird can fly.
Water will evaporate.
Taking this one step further, a fact can contain an object after ther verb:
A dog will eat food.
A bird can fly south.
A flower will grow petals.
To represent an action, we'll write the verb as a label on the arrow. If there is no object after the verb, it will point at nothing.
A dog will bark.
A flower will grow petals.

DOG --bark-->  

FLOWER --grow--> PETALS
Because Deduce doesn't understand the meaning of verbs other than forms of "to be", it can't deduce anything from them. It can, however, deduce things about the subject and object. When we ask a question that involves a verb, Deduce first tries to match up the subject with the verb. If there is an object in our question, it will then try to match that up as well. For example:
Spot is a dog.
A dog will drink water.
Evian is water.

SPOT --> DOG --drink--> WATER <-- EVIAN

Will Spot drink Evian?

To answer the question, we start at spot, and follow the non-labeled arrows until we come across the verb "drink". In this case, we pass through "dog" to "drink". If the question were simply, "will Spot drink," we would be done, since if Spot drinks water, it means that he drinks. Of course, if he didn't drink water, it wouldn't necessarily mean he doesn't drink.

Anyway, we now know that Spot will drink water, but the question asks if Spot will drink Evian. To answer this, we pose the question, "Is Evian water?" Since the answer to this is "yes", we can conclude that Spot will drink Evian. Had the answer been "no" or "I don't know", we would've had to continue our search.

Contradictions

Sometimes it's possible to know something based on a subject's properties and classifications. Take the following two facts:
A bird can fly.
A dog can not fly.

bird --fly-->  
dog --fly-+>  

Since a dog can't fly, it obviously can't be a bird. Likewise, a bird can't be a dog for the same reason. However, using the techniques we've seen so far, there's no way for Deduce to pick up on this. To make it work, we can compare all the attributes of each subject and see if any of them contradict. Since one can fly and the other can't, they can't be directly related.

In the section on negatives, we learned that if a negative is true, the opposite can be assumed to be true as well. So:

A cat is not a dog.
Therefore, a dog is not a cat.
Let's see why the conclusion can be made based on what we've seen.
A dog is a dog.
A cat is not a dog.
The first statement is a symmetry, and can always assumed to be true (how could a dog not be a dog?) The second statement is what we were given above. Notice that dog belongs to the category "dog", whereas cat does not. Since they have this difference in classification, a dog can't be a cat. No matter what subjects we use in place of cat and dog, we'll find the same thing to be true. This is why we can say that if a negative statement is true, the opposite is true as well.

Future

This is where Deduce stands now. I have plans to add more distinction than just black and white. As a result, you may ask a question and get back a reply of "Maybe". Doing this will force me to revisit how everything else is handled, and will take a considerable amount of work. I have the basic idea of how it should work in my head, but I don't want to spend a lot of time writing up the theory here since it may change as I work out the details. I'm also working on adding synonyms, which will allow different forms of the same word to be recognized as the same word.

Further ahead, I may try to tackle prepositional phrases and infinitives, but English tends to be rather ambiguous with regards to these, so I'm not sure how they will be handled.