behavior - Prolog cut operator behaviour -


i have these clauses:

a(1). a(2). b(a). c(a,b,c) :- a(a),d(b,c). c(a,b,c) :- b(a),d(b,c). d(b,c) :- a(b),!,a(c). d(b,_) :- b(b). 

when run query c(x,y,z) answers are:

x = 1, y = 1, z = 1 ; x = 1, y = 1, z = 2 ; x = 2, y = 1, z = 1 ; x = 2, y = 1, z = 2 ; x = a, y = 1, z = 1 ; x = a, y = 1, z = 2. 

so basically, cut operator (in here d(b,c) :- a(b),!,a(c).) ignores recent choice points, i.e. not further search d() , a(). though cut ignores previous choice points , won't backtracking.

can explain exact behavior , why wrong?

because did not understand explanation of cut doing, looked @ code. reading went follows:

  • c(a,b,c) true when:
    • a(a) , d(b,c),
    • or b(a) , d(b,c)
  • d(b,c) true when a(b), first a(b) encounter, , don't other d(b,c) definitions might find below one.

my reading went because interpretation of cut is: commit choices made before encountering cut within predicate body, , discard clauses predicate below clause containing cut.

i hope @ least remotely helpful.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -