# \[QUIZ\] Inference Engine (#37)

**URL:** <https://rubytalk.org/t/quiz-inference-engine-37/19286>\
**Category:** ruby-talk\
**Created:** [1 July 2005 12:30 UTC](https://rubytalk.org/t/quiz-inference-engine-37/19286 "2005-07-01T12:30:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Edward\_Gray\_II](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@James\_Edward\_Gray\_II](https://rubytalk.org/u/James_Edward_Gray_II)\
**Post date:** [1 July 2005 12:30 UTC](https://rubytalk.org/t/quiz-inference-engine-37/19286/1 "2005-07-01T12:30:50Z")

</div>

The three rules of Ruby Quiz:

1. Please do not post any solutions or spoiler discussion for this quiz until  
48 hours have passed from the time on this message.

2. Support Ruby Quiz by submitting ideas as often as you can:

[http://www.rubyquiz.com/](http://www.rubyquiz.com/)

3. Enjoy!

> **···**
>
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> 
> There was an interesting thread on Ruby Talk recently about Truth Maintenance  
> Systems (TMS). One reason to use a TMS is to validate inferences, given certain  
> truths. We'll focus on that application here.
> 
> This week's Ruby Quiz is to build an inference engine that is capable of  
> answering questions based on the provided truths.
> 
> Note that our Perl friends have already done this quiz, with their own Perl Quiz  
> of the Week. It was an interesting problem that generated good solutions and  
> discussion. Because of that, I'm going to copy the format used there,  
> originally by Dan Sanderson and Mark Jason Dominus.
> 
> You should be able to teach your engine truths with the following inputs:
> 
> &nbsp;&nbsp;All PLURAL-NOUN are PLURAL-NOUN.  
> &nbsp;&nbsp;No PLURAL-NOUN are PLURAL-NOUN.  
> &nbsp;&nbsp;Some PLURAL-NOUN are PLURAL-NOUN.  
> &nbsp;&nbsp;Some PLURAL-NOUN are not PLURAL-NOUN.
> 
> You should also be able to query your engine with the following questions:
> 
> &nbsp;&nbsp;Are all PLURAL-NOUN PLURAL-NOUN?  
> &nbsp;&nbsp;Are no PLURAL-NOUN PLURAL-NOUN?  
> &nbsp;&nbsp;Are any PLURAL-NOUN PLURAL-NOUN?  
> &nbsp;&nbsp;Are any PLURAL-NOUN not PLURAL-NOUN?  
> &nbsp;&nbsp;Describe PLURAL-NOUN.
> 
> Here's a sample run straight out of the Perl Quiz to show how all of this fits  
> together:
> 
> &nbsp;&nbsp;\> All mammals are hairy animals.  
> &nbsp;&nbsp;OK.  
> &nbsp;&nbsp;\> All dogs are mammals.  
> &nbsp;&nbsp;OK.  
> &nbsp;&nbsp;\> All beagles are dogs.  
> &nbsp;&nbsp;OK.  
> &nbsp;&nbsp;\> Are all beagles hairy animals?  
> &nbsp;&nbsp;Yes, all beagles are hairy animals.  
> &nbsp;&nbsp;\> All cats are mammals.  
> &nbsp;&nbsp;OK.  
> &nbsp;&nbsp;\> All cats are hairy animals.  
> &nbsp;&nbsp;I know.  
> &nbsp;&nbsp;\> Are all cats dogs?  
> &nbsp;&nbsp;I don't know.  
> &nbsp;&nbsp;\> No cats are dogs.  
> &nbsp;&nbsp;OK.  
> &nbsp;&nbsp;\> Are all cats dogs?  
> &nbsp;&nbsp;No, not all cats are dogs.  
> &nbsp;&nbsp;\> Are no cats dogs?  
> &nbsp;&nbsp;Yes, no cats are dogs.  
> &nbsp;&nbsp;\> All mammals are dogs.  
> &nbsp;&nbsp;Sorry, that contradicts what I already know.  
> &nbsp;&nbsp;\> Some mammals are brown animals.  
> &nbsp;&nbsp;OK.  
> &nbsp;&nbsp;\> Are any mammals dogs?  
> &nbsp;&nbsp;Yes, some mammals are dogs.  
> &nbsp;&nbsp;\> Are any dogs brown animals?  
> &nbsp;&nbsp;I don't know.  
> &nbsp;&nbsp;\> Some dogs are brown animals.  
> &nbsp;&nbsp;OK.  
> &nbsp;&nbsp;\> All brown animals are brown things.  
> &nbsp;&nbsp;OK.  
> &nbsp;&nbsp;\> Are any dogs brown things?  
> &nbsp;&nbsp;Yes, some dogs are brown things.  
> &nbsp;&nbsp;\> Describe dogs.  
> &nbsp;&nbsp;All dogs are mammals.  
> &nbsp;&nbsp;All dogs are hairy animals.  
> &nbsp;&nbsp;No dogs are cats.  
> &nbsp;&nbsp;Some dogs are beagles.  
> &nbsp;&nbsp;Some dogs are brown animals.  
> &nbsp;&nbsp;Some dogs are brown things.  
> &nbsp;&nbsp;\> Are all goldfish mammals?  
> &nbsp;&nbsp;I don't know anything about goldfish.
> 
> In the discussion of the Perl Quiz, some very interesting examples were posted.  
> Here's my favorite, which we'll call extra credit:
> 
> &nbsp;&nbsp;\> All dogs are mammals  
> &nbsp;&nbsp;OK.  
> &nbsp;&nbsp;\> No octopuses are mammals  
> &nbsp;&nbsp;OK.  
> &nbsp;&nbsp;\> Are any octopuses dogs?  
> &nbsp;&nbsp;I don't know.
> 
> That's not the correct answer. See how your engine answers that question.

---

<div class="post-metadata">

**Author:** ![Pit](https://avatars.discourse-cdn.com/v4/letter/p/f14d63/32.png) [@Pit](https://rubytalk.org/u/Pit)\
**Post date:** [3 July 2005 13:24 UTC](https://rubytalk.org/t/quiz-inference-engine-37/19286/2 "2005-07-03T13:24:50Z")

</div>

Ruby Quiz schrieb:

> This week's Ruby Quiz is to build an inference engine that is capable of  
> answering questions based on the provided truths.
> 
> ...

Just out of curiosity, after entering

&nbsp;&nbsp;&nbsp;\> All Foos are Bars  
&nbsp;&nbsp;&nbsp;OK.

what should be the response to

&nbsp;&nbsp;&nbsp;\> No Foos are Bars

If the answer is "OK." it would mean that the set of "Foos" is empty, because no Foo can be a Bar and not be a Bar. Questions like

&nbsp;&nbsp;&nbsp;\> Are all Foos \<whatever\>?

should then be answered with Yes.

The other alternative would be to assume that when speaking of "Foos" the set of "Foos" isn't empty and there exists at least one Foo?

Regards,  
Pit

---

<div class="post-metadata">

**Author:** ![James\_Edward\_Gray\_II](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@James\_Edward\_Gray\_II](https://rubytalk.org/u/James_Edward_Gray_II)\
**Post date:** [3 July 2005 15:35 UTC](https://rubytalk.org/t/quiz-inference-engine-37/19286/3 "2005-07-03T15:35:43Z")

</div>

> Ruby Quiz schrieb:
> 
> > This week's Ruby Quiz is to build an inference engine that is capable of  
> > answering questions based on the provided truths.  
> > ...
> 
> Just out of curiosity, after entering
> 
> &nbsp;&nbsp;\> All Foos are Bars  
> &nbsp;&nbsp;OK.
> 
> what should be the response to
> 
> &nbsp;&nbsp;\> No Foos are Bars

Basically, whatever you are comfortable with.

> If the answer is "OK." it would mean that the set of "Foos" is empty, because no Foo can be a Bar and not be a Bar. Questions like
> 
> &nbsp;&nbsp;\> Are all Foos \<whatever\>?
> 
> should then be answered with Yes.

This is the correct logical interpretations, but...

> The other alternative would be to assume that when speaking of "Foos" the set of "Foos" isn't empty and there exists at least one Foo?

This makes more sense to me, so it's probably what I would choose. Given that, I would likely just print an error message to the user, in the example you give.

James Edward Gray II

> **···**
>
> On Jul 3, 2005, at 8:24 AM, Pit Capitain wrote:

---

<div class="post-metadata">

**Author:** ![Joost\_Diepenmaat](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@Joost\_Diepenmaat](https://rubytalk.org/u/Joost_Diepenmaat)\
**Post date:** [5 July 2005 13:19 UTC](https://rubytalk.org/t/quiz-inference-engine-37/19286/4 "2005-07-05T13:19:52Z")

</div>

> Ruby Quiz schrieb:  
> \>This week's Ruby Quiz is to build an inference engine that is capable of  
> \>answering questions based on the provided truths.  
> \>  
> \>...
> 
> Just out of curiosity, after entering
> 
> &nbsp;&nbsp;\> All Foos are Bars  
> &nbsp;&nbsp;OK.
> 
> what should be the response to
> 
> &nbsp;&nbsp;\> No Foos are Bars
> 
> If the answer is "OK." it would mean that the set of "Foos" is empty,  
> because no Foo can be a Bar and not be a Bar. Questions like
> 
> &nbsp;&nbsp;\> Are all Foos \<whatever\>?
> 
> should then be answered with Yes.
> 
> The other alternative would be to assume that when speaking of "Foos"  
> the set of "Foos" isn't empty and there exists at least one Foo?

I'd go with this last interpretation. I'm assuming the input is not  
talking about abstract concepts, but about sets of "real, existing" things.

In the same vein:

&nbsp;&nbsp;&nbsp;&nbsp;\> All dogs are mammals.  
&nbsp;&nbsp;&nbsp;&nbsp;\> All mammals are dogs.

Could be taken to mean that the set of dogs and the set of mammals are  
equivalent (so, basically dogs == mammals) OR it could be taken to be  
contradictory, if we assume a maximum amount of information conveyed by  
the input (i.e. if all dogs are mammals then mammals is a larger set  
than dogs and there are other mammals that are not dogs)

Going for the latter interpretation will probably simplify some inferences.

Joost.

> **···**
>
> On Sun, Jul 03, 2005 at 10:24:50PM +0900, Pit Capitain wrote:
