Omari Celestine
Omari Celestine

Reputation: 1435

Prolog: Implement Rule with Optional Facts

If I have a disease disease1 which has five symptoms; symptom1, symptom2, symptom3, symptom4 and symptom5 but symptom5 is optional. Would this be the best way to write the rule:

symptom('John', symptom1).
symptom('John', symptom2).
symptom('John', symptom3).
symptom('John', symptom4).

has_disease1(Person) :-
    symptom(Person, symptom1),
    symptom(Person, symptom2),
    symptom(Person, symptom3),
    symptom(Person, symptom4),
    symptom(Person, symptom5).

has_disease1(Person) :-
    symptom(Person, symptom1),
    symptom(Person, symptom2),
    symptom(Person, symptom3),
    symptom(Person, symptom4),
    not(symptom(Person, symptom5)).

Is there a way that the rule shoule be written?

Upvotes: 1

Views: 91

Answers (1)

Evgeny
Evgeny

Reputation: 3274

Logically if a symptom is optional then it is basically irrelevant. So your rule would be

has_disease1(Person) :-
    symptom(Person, symptom1),
    symptom(Person, symptom2),
    symptom(Person, symptom3),
    symptom(Person, symptom4).

Upvotes: 1

Related Questions