Questions tagged [logic-programming]

Logic Programming is a programming paradigm based on first order logic.

Logic programming is a programming paradigm which is largely based on formal logic. Any program written in a logic programming language is a set of sentences in logical form, expressing facts and rules about some problem domain. Major logic programming language families include Prolog, answer set programming (ASP) and Datalog.

231 questions
0
votes
1 answer

Prolog Recursion might not be exiting with proper boundary condition

Given the following database: location(desk, office). location(apple, kitchen). location(flashlight, desk). location('washing machine', cellar). location(nani, 'washing machine'). location(broccoli, kitchen). location(crackers,…
0
votes
1 answer

Find number of successes from a list of terms/goals

I have written the following predicate exactly/2 that succeeds if exactly N of the numbers in the list L are equal to 1: :- pred exactly(int, list(int)). :- mode exactly(in, in) is semidet. :- mode exactly(out, in) is det. exactly(N, L) :- …
0
votes
2 answers

Prolog : querying if something doesn't satisfy a predicate

I'm sure this is a n00b question, but how do I ask for things which satisfy one predicate and not another? Eg. in a database of people and…
interstar
  • 26,048
  • 36
  • 112
  • 180
0
votes
1 answer

Need help understanding Prolog append/3 and inverse/2 and trace output

This is the question find value A. inverse([],[]). inverse([H|T],D) :- inverse(T,Z), append(Z,[H],D). append([],X,X). append([X|L],M,[X|N]) :- append(L,M,N). This is the answer: Plese help me to understand this!
0
votes
1 answer

Creating relations with unify and regular expression

I'm trying to create a relation with unify for example: Boy(Mike) --> Mike is a boy Girl(Lisa) --> Lisa is a girl isSister(Mike,Lisa) --> Lisa is Mike's sister and this is my code: from fact import Fact from logic import get, unify, var from…
javiera
  • 85
  • 1
  • 1
  • 5
0
votes
1 answer

Answer set of a program - why is the empty set not an answer set?

I'm a little confused by the definition of an answer set. S is an answer set of P if S is the least model of P. When I have a program b :- a a. Then I know my answer set has to be {a,b}, because a is a fact. What happens if I have something like a…
0
votes
1 answer

Prolog Nim Game - Out of local stack error

I've been doing some Prolog lately. And I've read The Art Of Prolog book. They have a Nim game implementation there. So I've rewritten it to SWI-Prolog and everything seems fine except this Out of local stack error. After debugging I've found out…
Naz
  • 5,104
  • 8
  • 39
  • 63
0
votes
1 answer

How to retract rules from pyDataLog

I'm implementing a FOIL-like algorithm in which I want to efficiently try different hypotheses (i.e., clauses) while I keep the rest of data untouched. I was wondering how without using clear() function, I could retract a rule?
0
votes
1 answer

Does pyDatalog have a "cut" operator like prolog?

This may be quite simple, but i can't find the answer anywhere. In Prolog, when you want to prevent it from searching for additional answers, once a variable has already been instantiated, you can use the ! sign (usually called the "cut" sign). You…
0
votes
0 answers

How to solve the equation in pyDatalog?

The pyDatalog page shows how to implement the factorial algorithm to calculate N! values. Is it possible to modify it (eg. using predicates) to solve for which N the N! will equal a given value (eg. 6) ? from pyDatalog import…
aoi
  • 21
  • 3
0
votes
1 answer

How to create arithmetic predicates in pyDatalog?

how do I translate this kind of arithmetic predicate to a legal pyDatalog predicate? add(X, Y, Z) ← X + Y = Z for example: ?add(5, 7, Z). the answer should be: add(5, 7, 12). Thanks!
user2199630
  • 203
  • 1
  • 2
  • 12
0
votes
1 answer

How does getting the highest value work with Logic Programming with AND, NOT and >

This is about Logic Programming from Structure and Interpretation of Computer Programs It's a simple problem of understanding how to get the highest value. This a sample database: ((is-student Anna) (is-student Bart) (is-student …
Gosa
  • 23
  • 7
0
votes
1 answer

How to create dynamic arithmetic facts in pyDatalog?

I need to create a simple Datalog machine (Which means that my input are 2 files: 1. facts , 2. rules.) I'm currently using pyDatalog package. I need to parse the facts and create terms dynamically. from pyDatalog's tutorial I've found this example…
user2199630
  • 203
  • 1
  • 2
  • 12
0
votes
3 answers

Maximum minimum and mean in Datalog

I cannot figure how calculate a mean, maximum and minimum using Datalog declarative logic programming language. Eg. Considering this simple schema Flows(Stream, River) Rivers(River, Length) If I want a) the mean length of the rivers, b) the…
AndreaF
  • 11,975
  • 27
  • 102
  • 168
0
votes
1 answer

Usage of Pydatalog Aggregate Functions

I have been playing around with the various aggregate functions to get a feel for them, and after being confused for the past few days I am in need of clarification. I either get completely unintuitive behavior or unhelpful errors. For instance, I…
kb345
  • 3
  • 1