Questions tagged [logic-programming]
Logic Programming is a programming paradigm based on first order logic.
235
questions
0
votes
0
answers
34
views
Writing A Repeat Loop in Prolog But The Condition Does Not Update
I am attempting to write a small lexer here:
lexer(InputString) :-
string_chars(InputString, InputAsListOfAtomChars),
maplist(atom_string, InputAsListOfAtomChars, InputAsListOfStringChars),
...
0
votes
0
answers
24
views
answer set programming with recursion
Questions are as follows:
Points on the straight line, 1, 2, 3, 4, 5, the starting point is 1, can go to any point, but a point can only be reached once, output the path to visit all points.
I ...
1
vote
0
answers
61
views
Infinite loop with `counto` relation in core.logic
I am interested in expressing the number of occurrences of an element in a list as a relational goal in Clojure's core.logic library.
(Note that this question is not a duplicate of clojure core.logic ...
0
votes
1
answer
60
views
MiniKanren Racket multiplication for unary numbers
I am trying to implement multiplication for unary numbers in MiniKanren. So I have written the following code:
#lang iracket/lang
(require minikanren)
(require minikanren/matche)
(defrel (unaryo n) (...
1
vote
1
answer
38
views
Minizinc: inconsistent constraint reformulation
I'm developing a Minizinc model and I ran into this issue: given this model
enum req_type = {roads, rivers};
enum cities = {city1, city2, city3}
array[cities, cities] of var bool: are_connected; % ...
0
votes
0
answers
65
views
Using a list in pytholog
I'm trying to define a knowledge base where a disease has a list of symptoms. Here's a snippet:
import pytholog as pl
diseases_kb = pl.KnowledgeBase()
diseases_kb([
"disease(diabetes, [...
3
votes
0
answers
86
views
Logic programming with multiple fact databases
I have to find a logically consistent subset of multiple fact sets (databases). Is there a logic programming language with built-in facilities to do this? If not, are there logic programming languages ...
0
votes
0
answers
36
views
A question about the inner workings of ASP
I'm confused about the inner workings of ASP. Say I'm modelling a country's. For example, say we have
city(london).
city(manchester).
city(leeds).
city(newcastle).
city(sheffield).
road(a1).
road(b1)....
4
votes
2
answers
324
views
How does prolog resolution use proof by contradiction?
I'm learning prolog, and I'm confused by the claim that prolog uses proof by contradiction:
The resolution proof process makes use of a technique that is known as reduction to the absurd: suppose ...
1
vote
1
answer
194
views
Shortest path in Answer Set Programming
I'm trying to find all the shortest path from one source node to all other destination node (so 1-3, 1-5, 1-4) with the relative cost for each shortest path.
I've tried with this code
node(1..5).
...
0
votes
0
answers
39
views
Value Semantics in Parallel Programming
What is the advantage of following value semantics while designing parallel programming?
2
votes
2
answers
108
views
Is it possible to express Prolog's cut in first order logic?
In conversations around Prolog's cut operator !/0, I have only ever heard it described in terms of choice points and Prolog's execution model. It also seems to me that cut was introduced to give more &...
1
vote
0
answers
32
views
How to eliminate circular solutions in unification?
I use the next unification lib.
from unification import *
x1 = var('x1')
unify((x1, 1), x1) # {~x1: (~x1, 1)}
Can you please suggest how to eliminate such circular solutions (~x1 references to ...
1
vote
1
answer
68
views
Why does introducing numbero in minikanren cause the failure of valid unifications?
I am using Racket v8.5, with the packages for minikanren and
minikanren/numbers required. Why does introducing the numbero
constraint cause previously valid unifications to fail?
> (run 1 (q) (<...
0
votes
1
answer
357
views
Clingo: Intersecting All Possible Optimal Solutions (ASP)
I want to find atoms, within a pre-defined set of atoms, that are in all possible optimal solutions of an ASP problem.
I'll explain what i want to do. I have an optimization problem where multiple ...
1
vote
2
answers
179
views
Creating random CNF formulas prolog
For my thesis, I am looking at specific properties of knowledge bases and how this affects argumentation tree sizes. I need a sat solver in prolog which I already have, but I also need an algorithm ...
1
vote
0
answers
131
views
Is it possible to insert a Clojure statement in the middle of a series of core.logic calls, "à la Prolog"?
Prolog mixes logic (fallible) goals, and (infallible) processes like write/2 or assert/1. Is it possible to do so with Clojure's core.logic?
For example:
(pldb/with-db myFacts
(l/run* [x y]
...
1
vote
1
answer
87
views
Optimizing difficulty with a level generator using Clingo
I’m making a puzzle level generator (sokoban) using Clingo and got stuck trying to create levels with a specific move limit. The idea is to use the move limit to control difficulty of a level. This is ...
7
votes
1
answer
209
views
Does the term "Functor" in Prolog have any relation to the term taken from Category Theory?
I started to learn Prolog and I just read that the atom at the beginning of an structure is usually called functor.
I'm also familiar with the term functor from Category Theory and Functional ...
2
votes
2
answers
415
views
Inductive proofs in theorem provers (Z3, Vampire, with TPTP syntax)
I am testing the inductive capabilities of some theorem provers (such as Z3, Alt-Ergo, Vampire etc.) using the TPTP syntax. To my surprise, none of them managed to demonstrate the following simple ...
0
votes
1
answer
106
views
Trying to solve Lady or the Tiger in Alloy
I've been trying to solve the logic puzzle Lady or the Tiger in Alloy but got stuck. Right now I'm trying to solve the 4th puzzle which is on the 2nd day.
It goes as following: There are a few rooms ...
1
vote
1
answer
87
views
Can this type of problem be easily expressed in logic programming paradigm?
For simplicity, this is a toy version of the actual problem: given a set of integers, find the longest sequence of consecutive numbers from that set.
I looked at CLIPS and other expert systems, and ...
2
votes
1
answer
133
views
Route Inspection of Directed Graph in ASP
For the multidirected graph below I am trying to write an program that visits all edges at least once. For instance, in the below graph I am looking for an outcome similar to "edge(1,2), edge(2,3)...
2
votes
0
answers
78
views
Clauses in (lambda)prolog starting with a cut
I am reading the paper Implementing Type Theory in Higher Order Constraint Logic Programming, and on p7 I see the following lambda-prolog code:
% KAM-like rules in CPS style
whd1 (app M N) S Ks Kf :- !...
1
vote
1
answer
326
views
Negative optimization result in Answer Set Programming
I have written an ASP program with an optimization condition in the end. When I compile it, even though I get the correct result, in the summary I get a negative value for the optimization (i.e. -3).
...
1
vote
1
answer
260
views
Spanning Trees in Answer Set Programming
For the undirected graph described below, I am trying to get its spanning trees and then separate its leaves from the internal nodes. Could you please help me with my code ?
What I expect to see after ...
1
vote
1
answer
97
views
Non-termination when query variable is on a specific position
Consider this blog post where the author implements palindrome relation using reverso:
(defn reverso [l r]
(conde
[(== l ()) (== r ())]
[(fresh [la ld ldr]
(conso la ld l)
(...
1
vote
1
answer
406
views
Answer Set Programming - filtering from a large number of models
instance.lp
node(1). node(2). node(3). node(4). node(5). node(6).
edge(1,2). edge(2,1). edge(4,1). edge(2,3). edge(2,6).
edge(3,4). edge(3,5). edge(5,6). edge(6,3).
begin(4).
I have this problem ...
3
votes
1
answer
176
views
What is committed-choice logic programming language?
In the logic programming community, I have heard many people talk about "committed choice logic programming language", but I am not very clear about its definition. I searched the internet, ...
3
votes
1
answer
982
views
What's the difference between logic programming and answer set programming
I'm currently learning how to prove the unsatisfiability of first-order logic. I've learnd in my class that resolution is one way to solve the unsatisfiability problem, e.g., tools like Prolog achieve ...
3
votes
1
answer
117
views
How do I translate Prolog's cuts to Curry?
Here's an algorithm in Curry which takes n and matches on two strings within edit distance n of each other.
lev :: Eq a => Int -> [a] -> [a] -> ()
lev n (a : b) (a : c) =
lev n b c
lev n ...
3
votes
2
answers
223
views
Are there elements of 'logic programming' in Java?
In recent years many elements of 'functional programming' have entered Java, in particular with Java 8. I have in mind lambda-expressions, functional interfaces, Java Generics, the Stream-interface, ...
1
vote
1
answer
234
views
Converting `appendo` relation from smt2 to python
Recently I am learning SMT solver. Although SMT solver is a new concept to me, it reminds me of logic programming, e.g. Prolog and minikanren. So I tried a classic example of logic programming in SMT ...
1
vote
1
answer
178
views
Why the disjunctive ASP program cannot return both disjunct predicates instance in an answer?
I am a newbie to ASP (Answer Set Programming).
I tried the following program in clingo online version (reasoning mode = enumerate all)
% instance
member(dave).
% encoding
edu(X);rich(X) :- member(X).
...
1
vote
1
answer
327
views
How to replace constants terms from python API in clingo / gringo?
Suppose I have a the following file foo.lp:
foo(x).
Now when I run gringo -t -c x=1 foo.lp I obviously get:
foo(1).
Now I want to know how to achieve the same behavior as the -c command line option ...
1
vote
1
answer
232
views
Event-Driven Programming Paradigm in Logic Programing
I need to write a paper on the Event-Driven Programming Paradigm in Logic Programing. I have been able to find a lot of information on Event-Driven Programming in Object-Oriented and Functional ...
1
vote
1
answer
457
views
Clingo: operation undefined
Adding the following rule to my code results in an error message (info: operation undefined (Max-Min)):
rank_difference(Room, Deck, Diff) :-
played(Room, Deck),
Min = #min {Rank: seat(Player, ...
0
votes
1
answer
255
views
Reducing the search space efficiently in clingo
I am struggling to scale a constraint problem (it breaks down for large values and / or if I try to optimise instead of just looking for any solution). I've taken some steps to break the search space ...
0
votes
1
answer
190
views
Shorthand for multiple choice predicates in clingo
Right now I have a single choice predicate that defines my search space.
#const nRounds = 3.
#const nPlayers = 17.
#const nSeats = nRounds * nPlayers.
#const nRooms = 3.
#const nDecks = 6.
nSeats { ...
2
votes
1
answer
481
views
How to sum all rather than just distinct values in clingo?
The following code produces x(3) rather than x(4) because it adds 1 and 2 together even though 1 appears twice. What is the right way of obtaining total sums in clingo?
p(0,1;1,1;2,2).
x(X) :- X = #...
2
votes
2
answers
468
views
How to define multiple penalties to minimise overall in clingo?
I am trying to use clingo to generate tournament player-room allocations:
player(1..20).
room(1..4).
played(1..20, 0).
rank(1..20, 1).
played(1..20, 1..20, 0).
0 { used_room(R) } 1 :- room(R).
3 {...
5
votes
2
answers
297
views
Clarify search algorithms in different minikanren implementation
I am currently learning miniKanren by The Reasoned Schemer and Racket.
I have three versions of minikanren implementation:
The Reasoned Schemer, First Edition (MIT Press, 2005). I called it TRS1
...
0
votes
1
answer
296
views
Clingo program expected to be satisfiable
I am testing some programs involving arithmetics in Clingo 5.0.0 and I don't understand why the below program is unsatisfiable:
#const v = 1.
a(object1).
a(object2).
b(object3).
value(object1,object2,...
2
votes
2
answers
1k
views
logic programming - find synonyms of a given word
Task is to write a program that can decide whether two words are synonyms or not.
I have pairs of synonymous words, E.g.:
[big large]
[large huge]
[small little]
We can derive the synonymous ...
1
vote
2
answers
108
views
Look for algorithm/research area that determines facts that would make a Prolog query true given a Prolog program
I'm looking for research, algorithms or even terminology for this area of research that take a Prolog program and a query I want to be true and attempt to find the facts that would need to be asserted ...
2
votes
1
answer
122
views
Why does "disj" from miniKanren work in Scheme but not in Racket?
I was working with the minikanren library for Racket, but wanted to use the "disj" and "conj" operators. I want to be able to more explicitly declare whether I am using disj or ...
2
votes
1
answer
202
views
"Generating Numbers" Puzzle
I have come across the following puzzle and couldn't formulate a solution in Picat:
You will generate 5-digit numbers, where each digit is in 1..5 and different from the others, with the constraint ...
1
vote
3
answers
501
views
Maximize the interval in clingo
I have the following clingo code that generates the search space, followed by constraints.
{in(I,1..4)}=1 :- I=1..n.
:- [constraint1]
:- [constraint2]
This code works. But I need clingo to find the ...
5
votes
5
answers
259
views
What is the most elegant way to find 16-bit numbers which satisfy some conditions?
I need to find all triples of 16-bit numbers (x, y, z) (well, actually only bits which perfectly match up in different triples with bits on same positions), such that
y | x = 0x49ab
(y >> 2) ^ x ...
3
votes
2
answers
303
views
Finding all nodes connected to a vertex in Prolog
I am curious about pathfinding algorithms, so I took a look at Dijkstra's. I'm using this video as a guide (and it's what I'm basing my graph on). Here is the graph I am working from:
I now want to ...