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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:40:55+00:00 2026-06-02T07:40:55+00:00

I have a very simple program in swi-prolog, which in I define all predicates

  • 0

I have a very simple program in swi-prolog, which in I define all predicates for family relations. I also defined some facts (based on bible’s Abraham’s family).
So I defined a predicate “mother_in_law” like this:

mother_in_law(X,Y):- female(X),mother(X,Z),married(Z,Y).

and some facts:

female(sarah).
mother(sarah,isaac).
married(rebekah,isaac).

So now, when I type in the program

?- mother_in_law(sarah,X).

it should give me only X=rebekah. But it gives me some other values for X which do not stand in the condition that I defined.

Can someone tell me what am I doing wrong?

thanks a lot

I add the whole text part:

father(X,Y). % Define Predicates%
mother(X,Y).
married(X,Y).
male(X).
female(X).
parent(X,Y).
diff(X,Y).
male_cousin(X,Y).
brother_in_law(X,Y).
mother_in_law(X,Y).
cousin_three(X,Y).
cousin(X,Y).
sib(X,Y).

%Define Facts%
male(terah). male(abram). male(nahor). male(haran). male(isaac).
male(lot). male(moab). male(ben_ami). male(bethuel). male(laban).
male(esau). male(jacob). male(reuben).
female(sarah). female(milcah). female(lot_daughter_1). female(lot_daughter_2).
female(rebekah). female(leah). female(dinah).
father(terah,abram). father(terah,nahor).  father(terah,haran).
father(abram,isaac).  father(haran,lot). father(nahor,bethuel).
father(bethuel,laban). father(laban,leah). father(isaac,jacob).
father(isaac,esau).
father(jacob,reuben).
mother(sarah,isaac). mother(milcah, bethuel). mother(rebekah,jacob).
mother(rebekah,esau). mother(leah,reuben).
mother(lot_daughter_1,moab). mother(lot_daughter_2,ben_ami).
married(abram,sarah). married(nahor,milcah).
married(isaac,rebekah). married(jacob,leah).
married(sarah,abram). married(milcah,nahor).
married(rebekah,isaac). married(leah,jacob).



%Define complicated predicates%
    parent(X,Y) :- father(X,Y).
    parent(X,Y) :- mother(X,Y).
    diff(X,Y) :- not(X=Y).
    sib(X,Y):- parent(Z,X), parent(Z,Y), diff(X,Y).  %define sibling %
    mother_in_law(X,Y):- female(X),mother(X,Z),married(Z,Y). %question 1%
    male_cousin(X,Y):- male(X),father(W,X),parent(Z,Y),sib(W,Z).    %question 2%
    cousin(X,Y):- parent(Z,X), parent(W,Y), sib(W,Z).       %question 3%
    cousin_three(X,Y):- parent(Z,X),parent(G,Z),parent(H,Y),parent(K,H),cousin(G,K).
    brother_in_law(X,Y):- male(X),married(X,Z),sib(Y,Z). %question 5-X is married to Y's sibling%
    brother_in_law(X,Y):- male(X),sib(X,Z),married(Y,Z).  %X's sibling is married to Y%
    brother_in_law(X,Y):- male(X),married(X,W),married(Y,Z),sib(W,Z).  % Y is married to the sibling of X's spouse%
  • 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-02T07:40:57+00:00Added an answer on June 2, 2026 at 7:40 am

    The problem with your solution is due to the following fact

    mother_in_law(X,Y).
    

    stating that anybody is a mother in law of anybody else.

    Drop

    father(X,Y). % Define Predicates%
    mother(X,Y).
    married(X,Y).
    male(X).
    female(X).
    parent(X,Y).
    diff(X,Y).
    male_cousin(X,Y).
    brother_in_law(X,Y).
    mother_in_law(X,Y).
    cousin_three(X,Y).
    cousin(X,Y).
    sib(X,Y). 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple test program, running on Solaris 5.8: #include <stdio.h> #include
I have a very simple question. I have a program that accepts an integer
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
I have a very simple problem which requires a very quick and simple solution
I have a very simple WPF application in which I am using data binding
So I have a very simple program that reads the 3 first bytes of
I have a very simple program that I am trying to improve performance. One
I have a very simple print program called print.c: #include <stdio.h> int main(void){ printf(Random
I have a very simple SDL program that uses only 1MB of memory with
I have very simple C program: int foobar(int a) { int b = a;

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.