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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:12:50+00:00 2026-06-03T15:12:50+00:00

I’m having trouble wrapping my head around how I would return a list of

  • 0

I’m having trouble wrapping my head around how I would return a list of everyone related to a certain person. So, if I say relatives(A,B), A would be a person and B is a list of all of the people related to that person. I can write any additional rules needed to assist in doing this. Here is what I have so far.

man(joe).
man(tim).
man(milan).
man(matt).
man(eugene).

woman(mary).
woman(emily).
woman(lily).
woman(rosie).
woman(chris).

parent(milan, mary).
parent(tim, milan).
parent(mary, lily).
parent(mary, joe).
parent(mary, matt).
parent(chris, rosie).
parent(eugene, mary).
parent(eugene, chris).

cousins(A, B) :- parent(C, A), parent(D, B), parent(E, C), parent(E, D), not(parent(C, B)), not(parent(D, A)), A \=B.

paternalgrandfather(A, C) :- man(A), man(B), parent(B, C), parent(A, B).

sibling(A, B) :- parent(C, A), parent(C, B), A \= B.

Can someone guide me as to how I would go about doing this? Thanks.

  • 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-03T15:12:53+00:00Added an answer on June 3, 2026 at 3:12 pm

    I think that you should concentrate on the ‘true’ relation, i.e. parent(Old,Jung), other predicates are irrelevant here. The obvious assumption it’s that atoms occurring in parent/2 are identifiers (i.e. names are unique). From this picture seems that all persons here are relatives:

    enter image description here

    Then your problem should be equivalent to find all connected vertices in parent relation. You can implement a depth first visit, passing down the list of visited nodes to avoid loops (note that you need to go back to parents and down to children!), something like

    relatives(Person, Relatives) :-
        relatives([], Person, [Person|Relatives]).
    
    relatives(Visited, Person, [Person|Relatives]) :-
        findall(Relative, immediate(Person, Visited, R), Immediates),
        ... find relatives of immediates and append all in relatives.
    
    immediate(Person, Visited, R) :-
        (parent(Person, R) ; parent(R, Person)),
        \+ member(R, Visited).
    

    See if you can complete this snippet. Note the order of arguments in relatives/3 is choosen to easy maplist/3.

    If you are willing to study more advanced code, SWI-Prolog library(ugraph) offers a reachable(+Vertex, +Graph, -Vertices) predicate that does it on a list based graph representation.

    Here the SWI-Prolog snippet to get the image (a file to be feed to dot):

    graph(Fact2) :-
        format('digraph ~s {~n', [Fact2]),
        forall(call(Fact2, From, To), format(' ~s -> ~s;~n', [From, To])),
        format('}\n').
    

    you can call in this way:

    ?- tell('/tmp/parent.gv'),graph(parent),told.
    

    and then issue on command line dot -Tjpg /tmp/parent.gv | display

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to run a str_replace or preg_replace which looks for certain words
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.