prolog-dif Questions

4

Solved

Do they exist? How are they implemented? The coroutining predicates of SWI-Prolog (freeze, when, dif etc.) have the functionality of guards. How do they fit in the preferred Prolog programming sty...
Dangle asked 7/12, 2012 at 9:8

5

Solved

I can't come up with a situation where I would need it.
Camorra asked 8/6, 2010 at 22:35

4

Solved

Consider what I have tried: dif_to_orto(A, B, C) :- ( dif(A, B) ; dif(A, C) ). While this definition is fine from a declarative viewpoint it contains many redundancies. Think of: ?- dif_to_ort...
Offensive asked 5/2, 2021 at 10:2

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

The problem that I face, is a bit trivial. I want to use logical not in Prolog, but it seems that not/1 is not the thing that I want: course(ai). course(pl). course(os). have(X,Y) :- course(X),co...
Genni asked 15/12, 2011 at 16:46

2

Solved

How would one implement a not_all_equal/1 predicate, which succeeds if the given list contains at least 2 different elements and fails otherwise? Here is my attempt (a not very pure one): not_all...
Tramline asked 24/11, 2017 at 12:45

6

Solved

I have a list with an unknown number of zeros at the beginning of it, for example [0, 0, 0, 1, 2, 0, 3]. I need this list to be stripped of leading zeros, so that it would look like [1, 2, 0 , 3]. ...
Amendment asked 30/9, 2016 at 19:50

1

Solved

Exercise 09 on this page http://www.ic.unicamp.br/~meidanis/courses/mc336/2009s2/prolog/problemas/ asks to create a predicate that packs repeated elements into sublists. A straightforward solution...
Industrials asked 22/7, 2016 at 13:39

1

There is a lot of hype around the dif/2 constraint, especially as a rescue for some non-declarativity of (\=)/2 and (\==)/2. This non-declarativity is often characterized as non-monotonicity and ex...
Wildfire asked 27/6, 2016 at 22:55

4

I have a list [a, b, a, a, a, c, c] and I need to add two more occurrences of each element. The end result should look like this: [a, a, a, b, b, b, a, a, a, a, a, c, c, c, c] If I have an item...
Colcothar asked 21/12, 2013 at 20:56

8

Standard term order (ISO/IEC 13211-1 7.2 Term order) is defined over all terms — including variables. While there are good uses for this — think of the implementation of setof/3, this makes many ot...
Ultan asked 3/11, 2014 at 18:33

8

Solved

different(Xs, Ys) :- member(X, Xs), non_member(X, Ys). different(Xs, Ys) :- member(Y, Ys), non_member(Y, Xs). While this definition using member/2 and non_member/2 is almost1 perfect from a d...
Contemptuous asked 16/6, 2015 at 9:32

4

So i am trying to write a predicate in prolog that can take a list L1 and a list L2 and return a list of all the elements in L1 that are not in L2. This is what i have so far: % Append an element ...
Joaquinajoash asked 29/9, 2015 at 3:11

2

Solved

I am studying Prolog for an university exam and I have problems with this exercise: Implement the predicate not_member(X,L) that is TRUE if the element X does not belong to the list L. If my r...
Monophthong asked 7/4, 2013 at 17:5

6

Pure Prolog programs that distinguish between the equality and inequality of terms in a clean manner suffer from execution inefficiencies ; even when all terms of relevance are ground. A recent ex...
Idaho asked 1/12, 2012 at 23:34

4

I need to find the first duplicate value in a list. prep(3,[1,3,5,3,5]). Should be true. prep(5,[1,3,5,3,5]). Should be false. I thought checking for equality with the current value and the prev...
Dinse asked 21/4, 2012 at 16:5

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

4

Solved

I have a prolog assignment. I need to look at the first item in a list, see if its following items are the same until they are not and separate the lists by the first item and its duplicates. e.g ...
Ragamuffin asked 7/6, 2014 at 10:6

2

Solved

I'm having some trouble understanding why my code in prolog does something based on the order I put my rules in. Here is my database: parent(tom, bob). parent(tom, liz). parent(mary, bob). parent...
Closestool asked 26/11, 2013 at 17:2

2

Solved

I am using SICStus Prolog and have a set of facts: student('John Henry', 'Maths'). student('Jim Henry', 'Maths'). student('John Alan', 'Maths'). student('Alan Smith', 'Computing'). student('Gary H...
Falkirk asked 15/11, 2013 at 20:42

1

Solved

What is the difference between this: X \= Y and this piece of code: dif(X, Y) I thought that they should behave the same, but they do not. Here's the example: n_puta(L, N, X) :- nputa(L, N, ...
Kenneth asked 15/5, 2013 at 8:19

3

Solved

OK I am new to Prolog, so excuse me if this is something trivial, but I can't seem to find a proper elegant answer to this. I am trying to work out the exercise here on learnprolognow.org, exercise...
Cystic asked 29/1, 2013 at 19:33

3

Solved

I am starting on learning Prolog. This program tries to get all occurrences of a given element: occurences(_, [], Res):- Res is []. occurences(X, [X|T], Res):- occurences(X,T,TMP), Res is [X,TM...
Barret asked 1/12, 2012 at 18:1

3

Solved

If I want to make sure that two variables do not instantiate to the same term, what is the preferred way to do it? Let's say I need to find directed edges in a graph, and a node cannot have an edg...
Ratoon asked 7/12, 2012 at 5:8

4

Solved

Trying to write a procedure that given a value and a list, it deletes all the occurence of that value in the list a wrote: delMember(X, [], []) :- !. delMember(X, [X|Xs], Y) :- !, delMember(X, Xs,...
Proliferation asked 29/8, 2012 at 10:0

© 2022 - 2024 — McMap. All rights reserved.