Questions tagged [failure-slice]

A failure-slice is a fragment of a Prolog program obtained by inserting one or more `false` goals somewhere in it. Failure-slices help to localize reasons for universal non-termination and instantiation errors of a pure monotonic Prolog program. They also help to give a lower bound for the number of inferences needed. It is a concrete program-slicing technique.

A failure-slice is a fragment of a Prolog program obtained by inserting one or more false goals somewhere in it. Failure-slices help to localize reasons for universal and instantiation errors of a pure monotonic Prolog program. They also give a lower bound for the number of inferences needed. It is a concrete technique.

References

Localizing and explaining reasons for non-terminating logic programs with failure-slices

125 questions
42
votes
2 answers

Prolog successor notation yields incomplete result and infinite loop

I start to learn Prolog and first learnt about the successor notation. And this is where I find out about writing Peano axioms in Prolog. See page 12 of the PDF: sum(0, M, M). sum(s(N), M, s(K)) :- sum(N,M,K). prod(0,M,0). prod(s(N), M, P) :- …
11
votes
1 answer

Features of good Prolog code?

What are the design heuristics one has to master to write good Prolog? I've heard it takes an experienced programmer about two years to become proficient in Prolog. Using recursion effectively is part of it, but that seems to be a relatively minor…
user287424
  • 1,219
  • 12
  • 22
9
votes
2 answers

Backtracking in recursive predicates

Assume we have the following predicates (This is an example from Programming in Prolog): [F0] isInteger(0). [F1] isInteger(X):- isInteger(Y), X is Y+1. The first result for query isInteger(R), the marker is placed at F0, and will return R=0 If…
Suzanne L.
  • 115
  • 4
8
votes
9 answers

Prolog program to find equality of two lists in any order

I wanted to write a Prolog program to find equality of two lists, where the order of elements doesn't matter. So I wrote the following: del(_, [], []) . del(X, [X|T], T). del(X, [H|T], [H|T1]) :- X \= H, del(X, T, T1). member(X, [X|_]). …
Happy Mittal
  • 3,667
  • 12
  • 44
  • 60
7
votes
2 answers

Why does this command cause a stack overflow in prolog?

I have the following snippet of prolog code: num(0). num(X) :- num(X1), X is X1 + 1. fact(0,1) :-!. fact(X,Y) :- X1 is X-1, fact(X1,Y1), !, Y is Y1 * X. fact(X) :- num(Y), fact(Y,X). Can somebody please explain why the following command causes a…
rookie
  • 7,723
  • 15
  • 49
  • 59
7
votes
3 answers

Prolog - infinite loop

I want to check if element is in the middle of list. I search middle element and next I check if is a member of list, but I get infinite loop. My predicates: remove_first([_,H1|T], [H1|T]). remove_last([_],[]). remove_last([H|T], [H|T2]) :-…
user
  • 4,410
  • 16
  • 57
  • 83
7
votes
3 answers

how to stop prolog from examining impossible solutions infinitely?

suppose the following program: nat(0). nat(s(N)) :- nat(N). /* 0+b=b */ plus(0,B,B) :- nat(B). /* (a+1)+b = c iff a+(b+1)=c */ plus(s(A),B,C) :- plus(A,s(B),C). it works great for adding two numbers, but when i attempt a query of the following…
yurib
  • 8,043
  • 3
  • 30
  • 55
6
votes
2 answers

prolog - infinite rule

I have the next rules % Signature: natural_number(N)/1 % Purpose: N is a natural number. natural_number(0). natural_number(s(X)) :- natural_number(X). ackermann(0, N, s(N)). % rule 1 ackermann(s(M),0,Result):- ackermann(M,s(0),Result). % rule…
Tom
  • 673
  • 4
  • 12
  • 20
6
votes
4 answers

Better termination for s(X)-sum

(Let me sneak that in within the wave of midterm questions.) A common definition for the sum of two natural numbers is nat_nat_sum/3: nat_nat_sum(0, N, N). nat_nat_sum(s(M), N, s(O)) :- nat_nat_sum(M, N, O). Strictly speaking, this definition is…
false
  • 10,264
  • 13
  • 101
  • 209
6
votes
2 answers

In prolog, why doesn't adding "edge(X, Y) :- edge(Y, X)." alone work for converting a directed graph definition to an undirected graph

I'm just learning Prolog, and I'm reviewing lecture notes and all the notes say is that: given the following definition for directed graphs: path(X, Y) :- edge(X, Y). path(X, Y) :- edge(X, Z), path(Z, Y). If we wanted to make this an undirected…
Leggy
  • 147
  • 7
6
votes
2 answers

prolog dcg restriction

I would like to use DCGs as a generator. As of now, the syntax is s-->a,b. a-->[]. a-->a,c. c-->[t1]. c-->[t2]. b-->[t3]. b-->[t4]. I would like to generate all s where the length of a is < someNumber. Using ?- phrase(a,X),length(X,Y),Y<4. i can…
Ruben Real
  • 63
  • 3
6
votes
2 answers

Regular Expression Matching Prolog

I am trying to do Regular Expression matching. I have all the functions written out, but they are not working as they should. From what I can tell, it has a problem when I try to compare a list. For instance, "re_contains(a,a)." gives true…
Ryan C. Stacy
  • 87
  • 1
  • 7
5
votes
2 answers

Prolog predicate - infinite loop

I need to create a Prolog predicate for power of 2, with the natural numbers. Natural numbers are: 0, s(0), s(s(0)) ans so on.. For example: ?- pow2(s(0),P). P = s(s(0)); false. ?- pow2(P,s(s(0))). P = s(0); false. This is my code: times2(X,Y) :- …
5
votes
1 answer

How to implement list item deletion for all argument modes?

The following Prolog program defines a predicate deleted/3 for deleting all the occurrences of the item passed in first argument from the list passed in second argument and results in the list passed in third argument: deleted(_, [], []). deleted(X,…
Géry Ogam
  • 6,336
  • 4
  • 38
  • 67
5
votes
2 answers

List of integers and infinite loop in Prolog CLPFD

Suppose I want to represent integers like so: integer:Sign:[FirstDigit,SecondDigit,...]. For instance, 42 would be represented as integer:positive:[4,2]. I need a predicate that generates the value of the integer based on this representation and…
Fatalize
  • 3,513
  • 15
  • 25
1
2 3
8 9