Page 215 - DCAP506_ARTIFICIAL_INTELLIGENCE
P. 215

Unit 14: Prolog




          to be the similar term as the argument inside X. In Prolog’s output this is indicated through the  Notes
          use of the variable _G177. This variable has been produced by Prolog during execution time. Its
          particular name, _G177 here, may be different each time the query is submitted.

          Self Assessment

          Fill in the blanks:
          11.  Two terms are defined to ...................... if they are either indistinguishable or if they can be
               made indistinguishable by variable instantiation.

          12.  The similar variable has to be instantiated with the similar ...................... all through an
               expression.

          14.8 Backtracking


          The backtracking predicate provides an alternative path for a program when the current path
          fails.
          The  response  to a  query is  generated after  executing and  evaluating  various  conditional
          statements in the program. During execution, the control goes to the first conditional statement
          and tests it with a variable. If the condition is FALSE, the execution moves back and tries to
          prove the condition with another variable. This looping back to the previous statement is called
          backtracking.

          Listing 3 shows a sample ProLog program that uses the backtracking predicate:
          Listing 3: Program with Backtracking
          /* The program specifies that the weather can be sunny on Friday, Saturday, or Sunday and the
          weekend is on Saturday and Sunday.*/
          /* Facts */
          weather(friday, sunny).
          weather(saturday, sunny).

          weather(sunday, sunny).
          weekend(saturday).
          weekend(sunday).
          /* The rule states that outings are possible on weekends, when the weather is sunny */

          /* Write is a built-in predicate to display on screen */
          outing(Day) :- weather(Day, sunny),
          weekend(Day),
          write(Day),

          nl.
          /* End of Program */


          Backtracking allows Prolog to find all alternative solutions to a given query.






                                           LOVELY PROFESSIONAL UNIVERSITY                                   209
   210   211   212   213   214   215   216   217   218   219   220