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
4
votes
2 answers

Prolog loop after results

So I wrote this predicate to find all possible subsets + permutations of a list. I get the correct output but for some reason the program keeps looping after giving me all the (correct) results. What am I doing wrong? % Gets all subsets of a…
4
votes
3 answers

create circled List in Prolog

I'm trying to create this function in Prolog: % Signature: circleList(L1, L2)/2 % Purpose: L2 is a "circled" L1 list. % Precondition: L1 is fully instantiated. % Examples: % ?- circleList([2, 3, 4, 5], X). % X = [2, 3, 4, 5]; % X = [3, 4, 5, 2]; % X…
kitsuneFox
  • 1,243
  • 3
  • 18
  • 31
4
votes
3 answers

Parsing an expression in Prolog and returning an abstract syntax

I have to write parse(Tkns, T) that takes in a mathematical expression in the form of a list of tokens and finds T, and return a statement representing the abstract syntax, respecting order of operations and associativity. For example, ?- parse( […
4
votes
3 answers

Prolog finding the largest integer in a list from the tail

I need to find the largest integer in a list from the head of a list and alternatively from the tail. I have already written a program that can find the largest from the head now I need some help to do it from the tail. Here is what I have so…
user2933973
  • 69
  • 1
  • 5
4
votes
3 answers

Explanation of Prolog recursive procedure

I'd like someone to explain this procedure if possible (from the book 'learn prolog now'). It takes two numerals and adds them together. add(0,Y,Y). add(s(X),Y,s(Z)) :- add(X,Y,Z). In principle I understand, but I have a few issues. Lets say I…
Justin
  • 322
  • 3
  • 13
4
votes
4 answers

How does recursion in Prolog works from inside. One example

I've got here a small script, that converts list of elements into a set. For example list [1,1,2,3] -> set [1,2,3]. Can somebody explain to me, step by step, whats happening inside those procedures? Can you please use my [1,1,2,3] -> [1,2,3]…
Ariel Grabijas
  • 1,472
  • 5
  • 25
  • 45
4
votes
3 answers

Prolog - get the factors for a given number doesn't stop?

I need to find the factors of a given number , e.g : ?- divisors2(40,R). R = [40,20,10,8,5,4,2,1]. The code : % get all the numbers between 1-X range(I,I,[I]). range(I,K,[I|L]) :- I < K, I1 is I + 1, range(I1,K,L). % calc the modulo of each…
JAN
  • 21,236
  • 66
  • 181
  • 318
4
votes
5 answers

Why my predicate in Prolog Fib/2 always says "out of local stack"?

I wrote a predicate fib/2 to calculate the Fibonacci numbers in Prolog. Though it works, it always says "out of local stack" and the error looks like: ?- fib(10, F). F = 55 ; ERROR: Out of local stack my predicate is below: fib(0, 0). fib(1,…
zzx
  • 179
  • 2
  • 12
4
votes
2 answers

Prolog: pythagorean triple

I have this code that uses an upper bound variable N that is supposed to terminate for X and Y of the pythagorean triple. However it only freezes when it reaches the upper bound. Wasn't sure how to use the cut to stop the backtracking. Code…
RandellK02
  • 167
  • 1
  • 4
  • 17
4
votes
2 answers

Why does Prolog crash in this simple example?

likes(tom,jerry). likes(mary,john). likes(mary,mary). likes(tom,mouse). likes(jerry,jerry). likes(jerry,cheese). likes(mary,fruit). likes(john,book). likes(mary,book). likes(tom,john). likes(john,X):-likes(X,john), X\=john. Hi there, above is a…
Max
  • 3,824
  • 8
  • 41
  • 62
3
votes
6 answers

Even and odd cases for the pivot/2 predicate aren't running properly when placed together

My goal is to implement the pivot(Before,After) predicate that returns true when Before's first half is equal to After's second half and Before's second half is equal to After's first half. With an even number of elements in input list, the lengths…
3
votes
2 answers

How to implement the factorial sequence in successor arithmetics for all argument modes?

The following Prolog program defines a predicate fact/2 for computing the factorial of an integer in successor arithmetics: fact(0, s(0)). fact(s(X), Y) :- fact(X, Z), prod(s(X), Z, Y). prod(0, _, 0). prod(s(U), V, W) :- sum(V, X, W), …
3
votes
2 answers

Understanding prolog better

I'm trying to understand Prolog and how the resolution algorithm it uses. I have this example that I found: hates(1, 2). hates(2, 3). hates(3, 4). jealous(A, B) :- jealous(A, C), jealous(C,B). jealous(A,B) :- hates(A,B). But when I try to say that…
Gringo
  • 81
  • 5
3
votes
2 answers

Why does my list reversal only work correctly in one direction?

I have produced the following code. list_reverse([],[]). list_reverse([X],[X]). list_reverse(Ls,[R|Rs]) :- last_elem(Ls,R), without_last_elem(Ls,Next), list_reverse(Next,Rs). last_elem([E],E). last_elem([_|Xs],E) :- …
Nicholas Hubbard
  • 527
  • 2
  • 15
3
votes
2 answers

Prolog Implementation of Mergersort won't halt

I am a new Prolog developer and am trying to get merge sort working.The query mergesort([2,1],T). Will Produce T=[1,2]; T=[1,2]; T=[1,2]; ... So Although it seems to "correctly" sort the sequence it doesn't halt On the other hand if I had a query…
1 2
3
8 9