Search code examples
prologlogic

Why do we call a disjunction of literals of which none is positive a goal clause?


I think I know the meaning of goal clauses and horn clauses, but I'm quite confused about why people name a disjunction of literals of which none is positive a goal clause?

What's the goal here?


Solution

  • There are three types of Horn clauses

    definite clause: ¬ p ∨ ¬ q ∨ ⋯ ∨ ¬ t ∨ u
    fact: u
    goal clause: ¬ p ∨ ¬ q ∨ ⋯ ∨ ¬ t

    which relate to Prolog.
    Example Prolog from Adventures in Prolog

    A definite clause is a Prolog rule:

    where_food(X,Y) :-  
      location(X,Y),
      edible(X).
    

    A fact is a Prolog fact:

    room(kitchen).
    

    A goal clause is a Prolog query:

    location(X, kitchen), edible(X).
    

    Another way of looking at three common with Prolog uses head, body and :-.

    A rule is head :- body.
    A fact is head.
    A query is body.

    A body is made up of calls to predicates (head), so a body can look like this A,B,C.

    When you use a query it is really

    goal :- body. 
    

    or

    goal <- A,B,C
    

    or

    location(X, kitchen), edible(X) ⊃ goal
    

    A Prolog example

    Facts

    location(apple, kitchen).
    location(crackers, kitchen).
    location(flashlight, desk).
    
    edible(apple).
    edible(crackers).
    

    Goal clause

    location(X, kitchen), edible(X).
    

    Answer

    X = apple
    X = crackers
    

    Earlier answer

    Starting with a predicate in Prolog

    ancestor(X,Y) :- parent(X, Z) , ancestor(Z,Y).
    

    where ancestor(X,Y) is know as the head clause and parent(X, Z) , ancestor(Z,Y) is known as the body.

    Converting the Prolog to an implication
    :- is
    , is
    and the implication is reversed.

    (parent(X,Z) ∧ ancestor(Z,Y)) ⊃ ancestor(X,Y) 
    

    converting the conjunction (∧) of literals into a disjunction (∨) of literals

    not parent(X,Z) ∨ not ancestor(Z,Y) ∨ ancestor(X,Y) 
    

    results in not parent(X,Z) ∨ not ancestor(Z,Y) which is the Prolog body or in your question the goal clause.

    In other words the goal clause are the statements that need to be satisfied in order to achieve the goal which is the Prolog head ancestor(X,Y).

    To see an example of using the Prolog ancestor see Prolog/Recursive Rules. Note that the rule given in this example is only one of the two that are used to define ancestor with the missing Prolog rule being ancestor(A, B) :- parent(A, B).

    References

    The University of Edinburgh Course: Prolog Programming for Automated Reasoning students - Lecture 10 - Logic Programming

    Goal clause definition from Wikipedia -

    a Horn clause without a positive literal is sometimes called a goal clause
    or ¬p ∨ ¬q ∨ ... ∨ ¬t

    SWI-Prolog Glossary of Terms

    Prolog/Recursive Rules

    Foundations of Logic (WorldCat)

    Try the Prolog online

    Using swish (Prolog rules are already entered with this link)
    In the lower right by ?- where it says your query goes here ... enter ancestor(X, john).
    Then in the lower right click Run!
    Above that you should see an ancestor of john
    X=david
    Under that click Next and you should see another ancestor of john
    X=jim
    keep clicking Next to see other ancestors and then finally you should see false meaning there are no more valid answers.

    An excerpt

    From Logic Programming by Frank Pfenning

    To make the transition from inference rules to logic programming we need to impose a particular strategy. Two fundamental ideas suggest themselves: we could either search backward from the conjecture, growing a (potential) proof tree upwards, or we could work forwards from the axioms applying rules until we arrive at the conjecture. We call the first one goal-directed and the second one forward-reasoning.

    How to search

    OP comment

    Could you tell me how you do such searches, 'cause when I run into some complex problems I usually don't know how to search necessary resources

    Normally I would have the OP (original poster) ask that as another question, but since it is more of a subjective than objective question it will get shot down at SO (StackOverflow) with down and close votes and I can use examples related to the original question so I will answer it here.

    When searching the path to success is to figure out the current terminology used by the experts in the area and which key words in that terminology are relevant to what you seek. Sometimes I know the key words off the top of my head, as with this question with disjunction of literals and goal I knew they were key terms in logic, reasoning, theorem proving and logic languages. Other times I am guessing or in the dark as with this question.

    One way that sometimes yields success when trying to learn the current terminology is to search for review articles which typically have survey in the title and thus survey is a good keyword. e.g. using Semantic Scholar with horn clause survey finds on first page Constraint Logic Programming: A Survey

    As an example of searching for the canonical form of math expressions with math canonical form little of relevance was found but after finding that standard from was more commonly used, better results were obtained.

    Sometimes it is not words that help you find the answer and search engines that rely on words will fail you. For example a type of search I see every few weeks or so involves finding the pattern/formula/etc. that generates a sequence of numbers and you only know part of the sequence, and typically the start of the sequence. This is were a search using OEIS (The On-Line Encyclopedia of Integer Sequences®) comes in handy. Another type of search engine related to math is WolframAlpha. So be attentive to the fact that there are other kinds of search engines

    Once you have the key words then as @WillNess notes you some times query for them as single words goal clause, but some times as exact words in quotes "goal clause". For this question using an exact word returned better results.

    The next thing to realize is the source of the information often corresponds with quality of information.

    • Sources from university courses, online digital scientific libraries and books are high on my list
    • PDF (Postscript Document Format). The reason for PDF is that it is common to write technical professional papers with LaTeX which are then output as PDF. The old format was PS (PostScript) but I rarely see that with newer papers. Thus pdf is a good search term to add.
    • Then sites from the creators such as Ubuntu, SWI-Prolog
    • Sites that are obviously good such as w3schools
    • Blog entries by the experts; most blogs are not by the experts.

    Other search engines I use related to computer science technical papers are:

    and of course you can always query for other academic search engines

    If you have only one or two documents that appeal to you but still don't have enough detail then start working down the references noted in those documents. This can be challenging as years ago many of the articles were only published in professional journals and are not freely available. However it is common to find those articles freely available if one of the authors is a professor and you can find the document listed under their public pages where they teach. CiteSeerX is really good for finding referenced documents.

    If you are using an existing SO answer then check the tag to see if they are a top answerer and remember that the accepted answer may not be the best answer and that any answer may not be a correct answer to your question.

    Then it is a matter of reading several of the articles to see what information is current and if there is consistency.

    Some fields are moving fast and changing rapidly even in the time span of the last 20 years of the Internet. Here is an example where one paper made a significant change. If you are not aware of this paper in the area it relates you will probably be confused by research that happened before the paper and research based on the paper. To find such papers note the significant number of citations, at present 18658.

    Don't be hesitant to spend upwards of an hour just searching and then a few more to a full day just reading. Here is a question I spent over four hours searching and reading and still could not find an answer. After finally running out of things to try I posted the question only to find it can not be done and is not documented. The answer was by someone I know to be an expert in F#.

    Lastly don't be afraid to leave bread crumbs, e.g. your own personal notes as I do with Of interest: comments or in this question. You will often use the same search terms over and over again and if you have enough posted on the Internet will start to run into your own post. After a while you will realize that if you only left bread crumbs there it would have made your life easier.

    The rest is just years of experience and diligence.

    Also sometimes asking an SO question requesting help with which keywords to use sometimes gets answers and sometimes get shot down.