Questions tagged [prolog]

Prolog is the most commonly used logic programming language. It supports non-deterministic programming through chronological backtracking and pattern matching through unification. Do not use this tag like Prologue and Epilogue.

Filter by
Sorted by
Tagged with
0 votes
0 answers
14 views

Singleton Detection in Linear Time [Prolog Variables]

More and more Prolog systems support the built-in term_singletons/2 which gives a list of the singleton variables of a Prolog term. Unfortunately because of term sharing in a Prolog term, many ...
Rúben Dias's user avatar
1 vote
4 answers
117 views

How to keep Prolog from going back and forth between the same two steps forever?

Behold the following "solution" to the Towers of Hanoi problem: f([],[],_). f([A|As],[],C) :- f(As,[A],C). f([A|As],B,[]) :- f(As,B,[A]). f([],[B|Bs],C) :- f([B],Bs,C). f(A,[B|Bs],[]) :- f(...
Raffael's user avatar
  • 19.6k
0 votes
0 answers
19 views

Error when including file in Visual Prolog v5.1

I have 2 files on Prolog. ROUTE.PRO: DOMAINS company=symbol city=string transport=symbol PREDICATES route(company, city, city, transport). CLAUSES route(amtrac, "New York", "Boston&...
Salivan's user avatar
  • 73
0 votes
2 answers
34 views

How does SWI Prolog handle lists under the hood?

Why is this not working? ?- '.'(a,[]). ERROR: Unknown procedure: ('.')/2 ERROR: However, there are definitions for: ERROR: ('.')/3 false. ?- .(a,[]). ERROR: Unknown procedure: ('.')/2 ...
Raffael's user avatar
  • 19.6k
0 votes
0 answers
31 views

Prolog task with multiple condition

(e(),[],X). (m(X,D),[X|Xs],X) :- (D,Xs, X). (n(X,D),[X|Xs],Y) :- Y \= X, (D, Xs, Y). ?- (Desc,[1,2],2). Can someone explain me please how we normally do these type of tasks? Desc = n(1,m(2,e()) - ...
Namaz Drv's user avatar
4 votes
6 answers
281 views

Marquee in Prolog

Well known from html, marquee is clearly the pinnacle of the Semantic Web. Or rather its nadir side by side with the blink tag. In any case, how can we represent marquee in Prolog? In other words, ...
false's user avatar
  • 10.1k
1 vote
1 answer
96 views

I'm not understanding why underscore gets grounded in meta-predicates

I'm using SWI-PROLOG. Given a list where almost all elements are compound terms like: ?- MyList = [json([a=1, b=2]), json([a=4, b=1]), 999, json([a=7, b=2])]. I want to filter only the compound ...
Lospix's user avatar
  • 76
1 vote
0 answers
62 views

Find Busy Beaver values for Prolog programs

The famous Busy Beaver function measures the most complex Turing Machine with a size of n states and m symbols, and that halts. In one version the machine starts with a blank tape and measures the ...
Lewis Baxter's user avatar
0 votes
1 answer
50 views

How do I express and solve this trivial logic puzzle?

I tried to express a more complex logic puzzle and boiled down where I'm failing at to this trivial problem: a Car can be red or green or blue bmw is not red and not blue solution: bmw is green But ...
Raffael's user avatar
  • 19.6k
3 votes
1 answer
82 views

Does this Prolog program have a simple proof of non-halting?

:- p(f(X),f(f(Y)),f(f(b))). p(f(a),f(X),f(f(X))). p(f(a),f(a),f(f(X))). p(X,f(f(Y)),X) :- p(Y,f(f(Y)),f(f(X))). p(f(X),Y,Z) :- p(X,f(Y),f(f(Z))). I believe I have a proof that uses induction and ...
Lewis Baxter's user avatar
0 votes
1 answer
53 views

Prolog - get best value among permutations of list

In Prolog, i have a simple list of twelve strings. I also have a list of rules that together assign a score to that list. So according to how those elements are placed in my list, they may or may not ...
JayK23's user avatar
  • 289
1 vote
3 answers
55 views

What would be an elegant/idiomatic way to introduce a predicte on a list of atoms?

Let's say I have objects a1,a2,...,a{n} and I want to introduce effectively an order on those objects like: gt(a1,a2). gt(a2,a3). ... gt(a{n-1},a{n}). Now {n} would be a large number like 200. ...
Raffael's user avatar
  • 19.6k
0 votes
1 answer
31 views

How to write a transitive predicate?

gt(ace,ten). gt(ten,king). gt(king,queen). gt(queen,jack). gt_(X,Y) :- ( gt(X,Z1), gt(Z1,Z2), gt(Z2,Z3), gt(Z3,Y) ) ; ( gt(X,Z1), gt(Z1,Z2), gt(Z2,Y) ) ; ( gt(X,Z1), gt(Z1,Y) ) ; gt(...
Raffael's user avatar
  • 19.6k
1 vote
2 answers
179 views

Is this the smallest Prolog program whose halting is unknown?

It is unknown whether the following 6-clause "pure" Prolog program halts. :- f(s(s(s(s(s(s(s(s(N)))))))),F), m(S,S,s(F)). f(o,s(o)). f(s(N),G) :- f(N,F), m(s(N),F,G). m(o,_,o). ...
Lewis Baxter's user avatar
1 vote
1 answer
50 views

What is the underlying mechanism of Prolog's operation?

I have the above code, and I'm not sure which of the two has_divisor clauses will be called when has_divisor is invoked. Can someone explain this to me? is_prime(2). is_prime(3). is_prime(P):- P&...
chens11111010001's user avatar
0 votes
2 answers
53 views

Flatten list in Prolog

I am fairly new to Prolog and attempting an exercise to flatten a list. My attempt is below, I've seen other correct implementations, but I can't figure out what is wrong with mine in particular. ...
Alastair Litterick's user avatar
0 votes
0 answers
34 views

Minimax Algorithm Issue in Nim Game AI - Opponent Always Choosing 1 Matchstick

I'm working on implementing an AI opponent using the Minimax algorithm for the well-known game of "Nim", which is a two-player game where each player takes turns removing 1 to 3 matchsticks ...
dya47's user avatar
  • 11
1 vote
2 answers
64 views

Formatting nested Prolog output

I am working with a Prolog database that has a set of entities with properties and values. I would like to output every entity along with each of its properties and values. I'm very new to Prolog, and ...
Liz C.'s user avatar
  • 101
1 vote
2 answers
60 views

Is there a way to automatically "consult" files on prolog?

I am kind of annoyed by having to manually re-consult my prolog every time I made changes in its source file. Can I make it run automatically somehow? I have searched for some extensions on vscode IDE,...
excitedGoose's user avatar
1 vote
1 answer
65 views

Why this predicate is written in this way?

I am having a hard time to understand why the second predicate of findall is written as this instead of collect_found([],L) directly. :- dynamic found/1. findall(X, G, _) :- asserta(found(mark)), ...
excitedGoose's user avatar
1 vote
2 answers
61 views

using assertz() and retract() in breadth-first search

I am trying to write breadth-first search in SWI Prolog using assertz() and retract(). I am having some issues though and I was hoping for some guidance. My guess is I'm doing something stupid. :- ...
Gerhardus Carinus's user avatar
0 votes
0 answers
30 views

Unload file in Pyswip

I am using Pyswip. I have some Python code like. In the first iteration, I load file1. In the second iteration, I load file2. for i in [1, 2] prolog = Prolog() prolog.consult(f'file{i}') However, ...
ZhangLiao's user avatar
2 votes
3 answers
88 views

Why does my Prolog predicate succeed twice with the same binding?

Sorry if this is a dumb question, but I'm still at the early stages of learning Prolog (SWI-Prolog in case it makes a difference), and probably doing something stupid. I'm trying to write a predicate ...
Avrohom Yisroel's user avatar
1 vote
0 answers
43 views

GNU Prolog: member in list?

I'm using some code from the Art of Prolog. This example is causing an error in GNU Prolog. mem(X,[X|Xs]). user:2: warning: singleton variables [Xs] for mem/2 mem(X,[Y|Ys]) :- mem(X,Ys). user:3: ...
notaorb's user avatar
  • 1,949
1 vote
1 answer
44 views

Prolog: plus in gnu prolog?

I'm trying to write a plus expression for Prolog. Using an example from the Art of Prolog: nat(0). nat(N) :- N > 0, M is N - 1, nat(M). plus(X, 0, X) :- nat(X). plus(X, s(Y), s(Z)) :- plus(X, Y, Z)....
notaorb's user avatar
  • 1,949
0 votes
1 answer
40 views

Bind a grade to a numeric value in Prolog

I need to use Prolog to bind a letter grade for a given integer grade value (>= 90 is a, >= 80 is b, and so on.) evaluate_grade( X , f ) :- X >= 0.0 , X < 2.0. This works fine: ...
Matt 's user avatar
  • 29
0 votes
2 answers
51 views

Querying and Displaying hierarchical Prolog information

I am working with a Prolog database that has a set of entities with properties and values. I would like to output every entity along with each of its properties and values. I'm very new to Prolog, and ...
Liz C.'s user avatar
  • 101
0 votes
1 answer
55 views

Searching simple paths using prolog

I'm new to Prolog. I'm trying to search simple pathes using prolog, but only base cases(length 1 or 0) were found. What's wrong? Code I rewrited the recursion part referencing several examples which ...
ynymxiaolongbao's user avatar
1 vote
2 answers
53 views

Use Prolog to bind a letter to a given integer such as in class grades

I need to use Prolog to bind a letter grade for a given integer grade value (>= 90 is a, >= 80 is b, and so on.) I am trying to write a function such as this: evaluate_grade( X , F ) :- X \&...
Matt 's user avatar
  • 29
0 votes
1 answer
33 views

Prolog: get the solution with minimal absolute value from the list of solutions

Suppose, we have the following equation in Z_{12} we want to solve in Prolog: (x + y) mod 12 = z with the following domains for variables: x \in [0, 11] y \in [-11, 11] z \in [0, 11] We write the ...
user4035's user avatar
  • 22.6k
1 vote
2 answers
69 views

Understanding the use of decrementation in Prolog predicate instead of incrementation?

I am new to logical programming and trying to understand a Prolog predicate that involves decrementing a variable, especially the logic behind using decrementation instead of incrementation, but I'm ...
dya47's user avatar
  • 11
0 votes
1 answer
40 views

Prolog - writing a query to calculate total of four given numbers

First off, let me say that I am quite a beginner in Prolog. I can create simple rules and facts (I know how to, for example, recursively define the predecessor relation etc). However, now I am given a ...
l0ner9's user avatar
  • 263
2 votes
1 answer
84 views

Exponential runtime of is/2 when linear would suffice

In Prolog building huge trees that are tiny graphs is easy: p(1). p(X+X) :- p(X). For handling such terms with builtin predicates many Prolog systems offer optimized implementations of ground/1 but ...
repeat's user avatar
  • 18.6k
0 votes
1 answer
73 views

Prolog instantiation error when using two "is/2" predicates

I'm new to Prolog and wanted to try some basic examples. I saw multiple questions about the instantiation error that Prolog throws, but I couldn't find a solution for my example. My rule is for ...
clapas's user avatar
  • 1,768
0 votes
0 answers
21 views

How can I solve Pyswip error with exit code 3?

I tried to run a python program that uses pyswip prolog library. When I try to run this program using PyCharm It shows this message: Assertion failed: 0, file /home/swipl/src/swipl-devel/src/pl-fli.c, ...
hey_youu's user avatar
0 votes
0 answers
57 views

All Possible Solution to Sudoku Prolog

I'm a newbie in Prolog and I was looking at the example that the SWI Prolog page gives to solve Sudoku. Is there a way to make it return all possible sudoku solutions? And if so, how would it be? Here ...
winnie's user avatar
  • 3
1 vote
3 answers
92 views

Prolog: Calculate summation by recursive function

I have to write a recursive function in prolog which, given two integers X>0 and N>=2, calculates the following sum: The code I wrote is as follows: sum(1,2,9). sum(X,N,Y):- X>1, N>...
anlux's user avatar
  • 11
2 votes
1 answer
123 views

In Prolog, how can I check condition B only if condition A is not satisfied?

I am trying to solve this optimization problem with Prolog. A person can only drive a car if his/her ability is higher than the car's difficulty. Additionally, if possible, each person should get one ...
luanpo1234's user avatar
1 vote
0 answers
38 views

Exception for "effect of operation is undefined"

SICStus Prolog offers an abstract datatype ("mutable term") for efficient backtrackable destructive assignment. The user's manual subsection on mutable terms states: Please note: the effect ...
repeat's user avatar
  • 18.6k
3 votes
5 answers
149 views

Iterate through two lists at same index

How can you iterate through two lists with the same index, so that you get a pair of each list: ?- X = [1, 2, 3], Y = [a, b, c], ... ElemX = 1, ElemY = a; ElemX = 2, ElemY = b; ElemX = 3, ElemY = c.
Jonas's user avatar
  • 198
0 votes
0 answers
51 views

Visual Prolog: Checking if integer* list head is even or odd

I want to check, if a head of an integer* list is even or odd I use the mod operator, but the program throws an error error c504 : The expression has type '::integer*', which is incompatible with the ...
IdleEnjoyer's user avatar
1 vote
2 answers
62 views

Prolog Count the number of fact in a Table

I have a program asking patients if they have symptoms like cold, fever, etc. Based on their answers a fact table is done using the dynamic: and assert command. The fact table at the end looks ...
LUIS's user avatar
  • 11
0 votes
1 answer
60 views

Binary to Integer in Prolog

Ok so. Still learning the basics in prolog and was given the bonus question on an assignment of converting a binary number into an integer based on the following definition for a binary num: bin(bin(X)...
Guilherme Doherty Marques's user avatar
2 votes
1 answer
64 views

Convert General Tree to List in Prolog

So I'm taking a programming paradigms course and we're tackling Prolog. The last exercise is to flatten a general tree structure into a list. By general it means that it can branch any number of times ...
Guilherme Doherty Marques's user avatar
1 vote
1 answer
126 views

Prolog project issue with GNU Prolog

I have an issue with this code that works in Swi Prolog but doesn't in GNU Prolog. :- dynamic libro/3. :- dynamic prestito/3. trim_whitespace(Input, Output) :- atom_string(InputAtom, Input), ...
Carlo27's user avatar
  • 11
0 votes
1 answer
45 views

i have problems with my connect_four.pl program

I'm working on a Prolog program for a class project and I'm running into a syntax error on line 74 when I try to compile it using GNU Prolog version 1.4.5. The code runs without any issues when I use ...
REDDIT STORIES's user avatar
0 votes
0 answers
39 views

tuProlog: how to make dynamic procedures?

tuProlog is a light version of prolog but does it support dynamic procedures? I read manual and explore other sources but could not find any information. If there is maybe other way to make dynamic ...
allrightallrightallright's user avatar
0 votes
0 answers
31 views

Using external variables from python to problog

I'm starting with problog, I want to use deeproblog for a neurosymbolic application. So I have several variables coming from python, and I want to introduce them into the problog to use them. Is there ...
Joaquin's user avatar
  • 141
0 votes
1 answer
35 views

Visual Prolog 5.2: a odd backtracking behavior

predicates /*....*/ clauses contain([H|_], H) :- write("up"), nl. contain([_|L], N) :- contain(L, N). goal contain([4,4,2,3,2], 2). I have this little program in prolog it supposed to yell &...
joudia's user avatar
  • 65
0 votes
1 answer
44 views

How to clear the previous query result on a list (in Prolog)

I have this code: connected(a,b). connected(b,a). connected(b,j). connected(j,b). connected(j,i). connected(i,j). connected(i,h). connected(h,i). connected(h,g). connected(g,h). connected(g,f). ...
Alex_Z's user avatar
  • 1

1
2 3 4 5
268