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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:25:50+00:00 2026-05-17T18:25:50+00:00

first off thanks for helping. I am writing a prolog program describing family relationships,

  • 0

first off thanks for helping. I am writing a prolog program describing family relationships, including all versions of in-laws. The logic is all there, what I need help with is some prolog problems as I am not very experienced with it. I am trying to set up multiple possibilities for each rule through use of semicolons.

The way I am treating in-laws is so that my brother in law is also my brother, so I need multiple checks to see which is true. I want prolog to return true, and only true, if any of the options are true. However, it returns true and false as possible options, since of course one of the options is always going to be false and the other is always going to be true. Either they are my brother in law, or my natural brother. I cant get prolog to return true only, and not have the option of false as another answer. If anyone has any advice it would be great. Relevant code is included below. So, if I type “brother(baby,dad).” I get true and false as possible answers when all I want is false. However, “brother(dad,baby).” only returns true. But I am rambling now. Sorry if any of the code is confusing with the baby dad stuff. Thanks!

/*facts for relationships*/

female(widow).
female(redhair).

spouse(i,widow).
spouse(widow,i).
spouse(dad,redhair).
spouse(redhair,dad).

child(i,dad).
child(redhair,widow).
child(baby,i).
child(onrun,dad).

male(onrun).
male(baby).
male(dad).
male(i).

/*rules*/
daughter(D,P):-
    female(D), (child(D,P);(spouse(P,S),child(D,S))).
son(D,P):-
    male(D), (child(D,P);(spouse(P,S),child(D,S))).
mother(X,Y):-
    female(X),
    child(Y,X).
father(X,Y):-
    male(X),
    child(Y,X).
son_in_law(C,P):-
    male(C),spouse(C,S),
    (child(S,P);(spouse(P,W),child(S,W))).
daughter_in_law(C,P):-
    female(C),spouse(C,S),
    (child(S,P);(spouse(P,W),child(S,W))).
brother(S1,S2) :- male(S1), 
    (child(S1,P) = child(S2,P2));
    (child(S1,P),child(S2,P2),spouse(P,P2));
    ((child(S1,P),son_in_law(S2,P));(child(S2,P),son_in_law(S1,P))).
  • 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-05-17T18:25:50+00:00Added an answer on May 17, 2026 at 6:25 pm

    These multiple answers can be preventing with the meta-predicate once/1:

    ?- once(brother(baby,dad)).
    true.
    
    ?-
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off thanks to all the users who have made my android developing adventure
first post. So first off, thanks for all the help over the years as
First off, thanks in advance for your help. This issue is driving me nuts.
and first off thanks for your time to look at this. For a research
First off good day and thanks for taking the time to answer my question.
First off, a big thanks to the people behind the new boost::geometry library! This
First off, I am new to programming (especially with C#) and thanks for your
First off thanks for any help provided. I have an array/loop issue. I'm trying
(First off, thanks so much. Stackoverflow has been very helpful to me in the
First off, thank you to everyone for your help!!! All I'm trying to do

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.