Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8798733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:09:38+00:00 2026-06-14T00:09:38+00:00

I want to know how I would get something like this to work. It

  • 0

I want to know how I would get something like this to work.
It seems like a simple concept, but I’m very new to Prolog and I can’t seem to figure out how I would do this correctly.

For example, here are two tables. Each animal, regardless of the category, has two facts.

Mammal:

tiger – striped, powerful

hippo – large, dangerous

elephant – large, gentle

Insect:

fly – black, winged

caterpillar – green, slow

snail – slimy, slow

How would I write all of these statements in Prolog code such that the fly and its characteristics will be categorized under insect and the hippo and its characteristics under mammal?

Then, what if I inserted a rule such as this?

guess(mammal, large) 

After consulting the code, I would write out this command:

possibleanimal(mammal, X) 

and the conclusion to that command would be:

X = hippo 
X = elephant 

since both the hippo and the elephant have the large characteristic.

Another example:

guess(insect, slow) 
guess(insect, green)

Command asked after consulting:

possibleanimal(insect, Y) 
Y= caterpillar 

We can omit the snail because even though it is slow, it is not green.

Please help me out in any way you can, thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:09:40+00:00Added an answer on June 14, 2026 at 12:09 am

    The first example looks like transitivity,
    so try this:

    % animal(Animal, Property)
    animal(tiger, striped).
    animal(tiger, powerful).
    animal(hippo, large).
    animal(hippo, dangerous).
    animal(elephant, large).
    animal(elephant, gentle).
    
    % guess(Category, Property)
    guess(mammal, large).
    
    % possibleanimal(Category, Animal)
    possibleanimal(C, A) :-
           guess(C, P),
       animal(A, P).
    
    ?- possibleanimal(mammal, X).
    X = hippo ;
    X = elephant
    

    Now the tricky part is the second example, since
    we have multiple guess/2.

    And I guess you would like them to simultaneously hold.
    So you need a kind of forall.

    Forall can be defined in Prolog as follows:

    % forall(Goal,Goal)
    forall(A, B) :- \+ (A, \+ B).
    

    See for example:
    http://www.swi-prolog.org/pldoc/man?predicate=forall%2F2

    So you can try this:

    % possible(Animal)
        possible(fly).
        possible(caterpillar).
        possible(snail).
    
        % animal(Animal, Property)
    animal(fly, black).
    animal(fly, winged).
    animal(caterpillar, green).
    animal(caterpillar, slow).
    animal(snail, slimy).
    animal(snail, slow).
    
    
    % guess(Category, Property)
    guess(insect, green).
    guess(insect, slow).
    
    % possibleanimal(Category, Animal)
        possibleanimal(C, A) :-
            possible(A),
            forall(guess(C,P), animal(A,P)).
    
    ?- possibleanimal(insect,X).
    X = caterpillar ;
    No
    

    Hope this helps.

    Bye

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies if this seems like I want my problem saved for me, but I
I would like to know a way (of course I want to know the
I would like to deepen my understanding of data types and want to know
Hello I would like to know if my script is good; I want to
I would like to know what I can offer to clients when they want
Basically I'd like to get this command to work: $sql = SELECT (EntryDate +
I know that with a large site you would want to separate footers, menus,
i want know if is possible, to get a specific element value of a
I know this is a task that can't be unique, but I can't seem
I'm starting in the Rails world and i want to know how to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.