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

  • SEARCH
  • Home
  • 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 7937887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:38:43+00:00 2026-06-03T22:38:43+00:00

Here is my knowledge base: a(b,c). a(X,Y):-a(Y,X). Here is my query: a(c,b). I am

  • 0

Here is my knowledge base:

a(b,c). 
a(X,Y):-a(Y,X). 

Here is my query: a(c,b).

I am using SWI-Prolog. I thought that this query would lead to the program printing “true”. However, instead it prints “true” and continues to print true if I hit the semicolon… until FOREVER.

Why doesn’t it stop?

My thoughts: First, X is bound to b and Y is bound to c. Then, Prolog tests a(b,c) and finds that this is true. Therefore, a(c,b) is true as well and SWI-Prolog should print true once. However, since it prints true forever as long as I keep hitting that semicolon, this leads me to think that something recursive is going on. Where is this happening? Help!

EDIT: More specifically my question is why does the program pause after each “true” and wait for me to press the semicolon or another key instead of just being done? If I have two predicates human(socrates) and mortal(X):-humans(X), the response to the query mortal(socrates) will be a single “true”. (Sorry if I failed to make this clear above.)

  • 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-03T22:38:45+00:00Added an answer on June 3, 2026 at 10:38 pm

    Prolog first proves a(c,b) by means of the second rule followed by the first. Then, it proves a(c,b) by means of three invocations of the second rule followed by the first. Then, by five invocations of the second rule, etc. Prolog’s inference algorithm is a depth-first search without a closed set, i.e. it doesn’t keep track of what it has already proved and happily proves it again.

    If you don’t want this behavior, you should either rewrite the rules as, e.g.,

    a_fact(b, c).
    a(X, Y) :- a_fact(X, Y).
    a(Y, X) :- a_fact(X, Y).
    

    … or use some kind of tabling execution. I don’t think SWI-Prolog supports tabling, though.

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

Sidebar

Related Questions

Complete prolog beginner here. Let's say I have a prolog knowledge base which contains
I am following this tutorial http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-5-magento-models-and-orm-basics . As per this tutorial,when i pass a
About catalog images I found smth here http://www.magentocommerce.com/knowledge-base/entry/resizing-catalog-images/ . But it has a path
I'm working on a knowledge base project using SQL Server 2008 Full Text Search
I've got a little gap in my knowledge here and I want to make
I'm experiencing some strange behavior for which I can't find any documented knowledge. Here's
Here is a complete example. I want to forbid using A::set from objects casted
Here's the deal: I'm in the process of planning a mid-sized business application that
Here's the problem, you include multiple assemblies and add 'using namespaceX' at the top
Question So I've recently came up with some new possible projects that would have

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.