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 7826943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:37:56+00:00 2026-06-02T09:37:56+00:00

as a beginner to Prolog, I found the commutative expression in Prolog are quite

  • 0

as a beginner to Prolog, I found the commutative expression in Prolog are quite not intuitive.

for example if I want to express X and Y are in one family, like:

family(X,Y) :-
      married(X,Y);
      relative(X,Y);
      father_son(X,Y).

I should also add the following to the definition, in order to make it “commutative”:

      married(Y,X);
      relative(Y,X);
      father_son(Y,X).

But we use Prolog, because we want to write elegant code… so, I’d hope to add only one line(instead of the above three) to the original :

      family(Y,X).

Here is the POINT. it leads to untermination! why is prolog no so “logical”? and is there an alternative to this neat one line expression that doesn’t lead to untermination?

Nice weekends!
watt

  • 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-02T09:37:57+00:00Added an answer on June 2, 2026 at 9:37 am

    The problem with family(X,Y) :- family(Y,X). part of the rule is that it keeps unifying unconditionally with itself at each level, and keeps recursing down; there is no exit condition out of this recursion.

    You should make the argument swap at the level above:

    family(X,Y) :-
        is_family(X,Y);
        is_family(Y,X).
    
    is_family(X,Y) :-
        married(X,Y);
        relative(X,Y);
        father_son(X,Y).
    

    Alternatively, you could make underlying rules below symmetric where it makes sense:

    is_married(X,Y) :-
        married(X,Y);
        married(Y,X).
    
    is_relative(X,Y) :-
        relative(X,Y);
        relative(Y,X).
    

    You could now rewrite your family rule as follows:

    family(X,Y) :-
        is_married(X,Y);
        is_relative(X,Y);
        father_son(X,Y);
        father_son(Y,X).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python beginner here. I've looked around and found similar questions but can't quite cobble
Beginner Node question. I'm running a Node/Express app, and I want to send client-side
I'm a beginner in Prolog, and I came across a question that I couldn't
Beginner help needed :) I am doign an example form a php book which
Absolute beginner question: I have a template file index.html that looks like this: ...
(R beginner here...) I have a dataset like: > head(q) Date Time System User
Beginner rails question: How does one return a file from a controller in rails?
(Beginner to HTML) I have made a Photoshop mock-up of the website I want
Beginner here See - http://www.w3schools.com/js/tryit.asp?filename=try_dom_tablerow_cells In this example, when change content is pressed, new
Complete prolog beginner here. Let's say I have a prolog knowledge base which contains

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.