prolog-cut Questions

4

Solved

Let's say I have the following: parent(alice, charlie). parent(bob, charlie). parent(bob, diane). parent(alice, diane). parent(bob, eve). parent(alice, eve). % people are siblings of each other i...
Radiotelephone asked 23/11, 2013 at 19:56

2

Solved

I am reading through Learn Prolog Now! 's chapter on cuts and at the same time Bratko's Prolog Programming for Artificial Intelligence, Chapter 5: Controlling Backtracking. At first it seemed that ...
Shama asked 2/12, 2016 at 13:32

4

Solved

How can I simulate a soft cut I *-> T; E in ISO Prolog? I has side effects, so I can not call it multiple times. Except for the last requirement, I think the following definition works: if_(I, T,...
Entremets asked 15/11, 2016 at 21:58

4

Solved

Consider the following code: a(X) :- b(X),!,c(X),fail. a(X) :- d(X). b(1). b(4). c(1). c(3). d(4). The query a(X). produces 1 ?- a(X). false. 2 ?- but with this code a(X) :- b(X),!,c(X...
Wriest asked 28/2, 2013 at 15:0

6

Solved

lcs([ H|L1],[ H|L2],[H|Lcs]) :- !, lcs(L1,L2,Lcs). lcs([H1|L1],[H2|L2],Lcs):- lcs( L1 ,[H2|L2],Lcs1), lcs([H1|L1], L2 ,Lcs2), longest(Lcs1,Lcs2,Lcs), !. lcs(_,_,[]). longest(L1,L2,Longest) :...
Shillelagh asked 23/11, 2017 at 19:52

5

I've took a course in which I learned some prolog. I couldn't figure out how / when to use cuts. Even though I get the general idea of cuts, I can't seem to use them properly. Can anyone explain it...
Shortcake asked 26/1, 2013 at 20:16

4

counter([],[]). counter([H|T],[[H,C1]|R]) :- counter(T,[[H,C]|R]),!, C1 is C+1. counter([H|T],[[H,1]|R]) :- counter(T,R). What is the effect of the "!" as I'm getting the same output for an input...
Electrometallurgy asked 9/5, 2017 at 5:41

1

Solved

I have been reading through the answers and comments of my previous question and I have tried applying the given explanations on an example from Bratko (Prolog Programming for Artificial Intelligen...
Carpet asked 6/12, 2016 at 11:15

2

Solved

Firstly, I have read all other posts on SO regarding the usage of cuts in Prolog and definitely see the issues related to using them. However, there's still some unclarity for me and I'd like to se...

1

Solved

Could somebody explain me what does "!" do in Prolog ? I don't understand it. Here I have a code that counts how many sublists of a heterogeneous list have mountain aspect. nrSubliste([], 0). nrSu...
Exclamatory asked 9/1, 2016 at 12:48

1

Solved

In the code given below, there is the ! (cut) that prunes the choice point for efficiency. I am pretty certain that the reverse predicate and the agent_do_moves predicate are essential. solve_tas...
Cullum asked 13/6, 2015 at 23:51

3

Solved

I have implemented the following function in prolog with the following code: abs2(X, Y) :- X < 0, Y is -X. abs2(X, X) :- X >= 0, !. How can I implement this function without the use of cut...
Cement asked 26/1, 2011 at 19:54

4

Solved

Disclaimer: This is informal and non-assessed coursework to do in my own time. I have tried it myself, failed and am now looking for some guidance. I am trying to implement a version of the member...
Housetop asked 26/11, 2011 at 23:36

1

Solved

I have this tracing meta interpreter, altered from previous question Prolog unbind bound variable. I don't understand how to interpret cut. Thanks to user @false who told me that the cut is badly ...
Glue asked 1/12, 2014 at 18:50

2

This is the code that i am trying to understand. co(X) :- co(X,[],L). co([],A,A):- write(A). co([X|Xs], A, L) :- p(X-Z,A,R), !, Z1 is Z+1, co(Xs, [X-Z1|R], L). co([X|Xs], A, L) :- co(Xs, [X-1|A],...
Nationality asked 14/11, 2014 at 10:15

1

I started learning prolog, and wanted to make the whole cuts thing clearer. I have read that "green cut doesnt change declarative meaning of the program, while red cut does". But, the meaning of t...
Giralda asked 21/9, 2014 at 19:6

2

Solved

I am taking an AI course this semester in which we are learning Prolog. Our lecturer has told us to try and avoid using cuts in our assignment, however, for a couple of the questions I can't ...
Ingenerate asked 9/4, 2014 at 17:29

2

Solved

I'm new to prolog, and am experimenting with how to get it to stop querying after it finds one answer. I'm using this code: member1(L,[L|_]). member1(L,[_|RS]) :- member1(L,RS),!. The result i...
Nowadays asked 24/11, 2013 at 20:7

2

Solved

This Prolog program de fines the third argument to be the maximum value of the fi rst two numeric arguments: max(X, Y, X) :- X >= Y, !. max(X, Y, Y). I think that this program works just fine...
Familiarity asked 15/5, 2013 at 21:42

2

Solved

I was reading the answer to this question, p(X) :- read(A), q(A,X-[]). q(end,X-X) :- !. q(A,[A|X]-Y) :- read(B), q(B,X-Y). The code above uses the syntax List-List. I somewhat understand what...
Thunell asked 16/3, 2013 at 23:38

3

Solved

I'm implementing a PEG parser generator in Python, and I've had success so far, except with the "cut" feature, of which whomever knows Prolog must know about. The idea is that after a cut (!) symb...
Drayton asked 3/1, 2013 at 18:15

1

Solved

To grok green cuts in Prolog I am trying to add them to the standard definition of sum in successor arithmetics (see predicate plus in What's the SLD tree for this query?). The idea is to "clean up...
Beichner asked 9/11, 2012 at 0:19

3

Solved

Let's consider the following Prolog program (from "The Art of Prolog"): natural_number(0). natural_number(s(X)) :- natural_number(X). plus(X, 0, X) :- natural_number(X). plus(X, s(Y), s(Z)) :- pl...
Inessa asked 31/10, 2012 at 16:43

4

Solved

What problem can occur when we use append with cut operator? append2([],L,L):-!. append2([H|T],L,[H|TL]):-append2(T,L,TL). I have tried several different inputs, but it always succeeds. ?- a...
Endoblast asked 6/7, 2012 at 10:0

3

Solved

I found this nice snippet for parsing lisp in Prolog (from here): ws --> [W], { code_type(W, space) }, ws. ws --> []. parse(String, Expr) :- phrase(expressions(Expr), String). expressions(...
Culbertson asked 15/6, 2011 at 13:37

© 2022 - 2024 — McMap. All rights reserved.