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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:29:31+00:00 2026-05-23T15:29:31+00:00

Suppose you have a disease diagnosis Prolog program that starts with many relations between

  • 0

Suppose you have a disease diagnosis Prolog program that starts with many relations between diseases and symptons:

causes_of(symptom1, Disease) :-
    Disease = disease1;
    Disease = disease2.
causes_of(symptom2, Disease) :-
    Disease = disease2;
    Disease = disease3.
causes_of(symptom3, Disease) :-
    Disease = disease4.

has_symptom(person1, symptom1).
has_symptom(person1, symptom2).

How can I create a rule with the head ‘has_disease(Person, Disease)’ that will return true if the person has all the symptoms from that disease? Using the example above the following would a sample output:

has_disease(person1, Disease).
   Disease = disease2.
  • 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-23T15:29:31+00:00Added an answer on May 23, 2026 at 3:29 pm

    Well, there is probably a much simpler way to do this, as my Prolog skills are minor at best.

    has_disease(Person, Disease) :- atom(Disease),
        findall(Symptom, has_symptom(Person, Symptom), PersonSymptoms),
        findall(DSymptom, causes_of(DSymptom, Disease), DiseaseSymptoms),
        subset(DiseaseSymptoms, PersonSymptoms).
    
    has_diseases(Person, Diseases) :-
        findall(Disease, (causes_of(_, Disease), has_disease(Person, Disease)), DiseaseList),
        setof(Disease, member(Disease, DiseaseList), Diseases).
    

    To be called as follows:

    ?- has_diseases(person1, D).
    D = [disease1, disease2, disease3].
    

    The findall/3 predicate is used first to find all symptoms a person has, then again to find all symptoms a disease has, then a quick check to see if the disease’s symptoms are a subset of the person’s.

    The way I have written the has_disease/2 predicate prevents it from giving a list of diseases. So I created has_diseases/2, which performs another findall on any disease it can find, using has_disease/2 as the check. A setof/3 call is used last to get unique results on the disease list and order it for convenience.

    NB. The atom/1 on the has_disease/2 primitive is just to ensure a variable is not passed in for Disease, as it does not work in that case, at least not for me.

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

Sidebar

Related Questions

Suppose I have a stringbuilder in C# that does this: StringBuilder sb = new
Suppose I have: Toby Tiny Tory Tily Is there an algorithm that can easily
Suppose I have a table called Companies that has a DepartmentID column. There's also
Suppose i have a dropdownlist in which whole months are there in that dropdown.I
Suppose I have a vector of ints, std::vector<int> numbers; that is populated with a
Suppose i have one table that holds Blogs. The schema looks like : ID
Suppose i have an XML file, that i use as local database, like this):
Suppose I have a stream of [acme] objects that I want to expose via
Suppose we have buyers and sellers that are trying to find each other in
suppose i have label and button on textbox and i want that if i

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.