Page 210 - DCAP506_ARTIFICIAL_INTELLIGENCE
P. 210

Artificial Intelligence




                    Notes          14.5.2 Cuts

                                   The  cut  (!)  functions  in  the  conventional  manner.  When  implemented,  it  succeeds  and
                                   throws away all backtrack points among  itself and its CUTPARENT.  Usually, the cutparent
                                   is the  query that  caused execution  to  enter  the  existing  clause.  Though,  if the  cut  is  in
                                   an  environment that  is OPAQUE  TO  CUTS,  the cutparent  is the  commencement of  that
                                   environment.


                                          Example: Examples of surroundings that are opaque to cuts are:
                                   _   The argument of the negation operator (\+).
                                   _   The  argument of  call,  which  can  certainly  be a  compound goal, such  as  call((this,!,
                                       that)).
                                   _   The left–hand argument of ‘->’ (see below).
                                   The objectives that are arguments of once, catch, findall, bagof, and setof (and, usually, any other
                                   goals that are arguments of predicates).

                                   14.5.3 If-then-else

                                   The  “if–then–else”  build  (Goal1  ->  Goal2  ;  Goal3)  tries  to  implement  Goal1,  and,  if
                                   successful, proceeds to Goal2; or else, it proceeds to Goal3. The semicolon and Goal3 can be
                                   omitted.
                                   Observe that:
                                   _   Only the first solution to Goal1  is established;  any backtrack points produced  while
                                       executing Goal1 are thrown away.
                                   _   If Goal1 succeeds, execution proceeds to Goal2, and then:
                                       If Goal2 fails, the whole construct fails.
                                   –   If Goal2 succeeds, the whole construct succeeds.

                                   –   If Goal2 has multiple solutions, the whole construct has multiple solutions.
                                   _   If Goal1 fails, execution proceeds to Goal3, and then:
                                       If Goal3 fails, the whole construct fails.

                                   –   If Goal3 succeeds, the whole construct succeeds.
                                   –   If Goal3 has multiple solutions, the whole construct has multiple solutions.
                                   _   If Goal1 fails and there is no Goal3, the whole construct fails.
                                   _   Either Goal2 or Goal3 will be executed, but not both (not even upon backtracking).
                                   _   If Goal1 contains a cut, that cut only has scope over Goal1, not the whole clause. That is,
                                       Goal1 is opaque to cuts.
                                   _   The whole if–then–else structure has numerous solutions if Goal1 succeeds and Goal2 has
                                       multiple solutions, or if Goal1 fails and Goal3 has multiple solutions. That is, backtrack
                                       points in Goal2 and Goal3 behave normally.

                                   _   Cuts in Goal2 and Goal3 have scope over the entire clause (i.e., behave normally).






          204                               LOVELY PROFESSIONAL UNIVERSITY
   205   206   207   208   209   210   211   212   213   214   215