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 whena(b), firsta(b)encounter, , don't otherd(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
Post a Comment