Questions tagged [transitive-closure]

Use this tag for the transitive closure of a relationship or when related to graph theory.

References:

Wikipedia
Wolfram MathWorld

148 questions
3
votes
3 answers

Prolog Recursion - Satisfying Both Directions (Simple)

I am very new to Prolog and I was given this assignment. My code is as follows: relatives(cindy,tanya). relatives(tanya,alan). relatives(alan,mike). relatives(kerry,jay). relatives(jay,alan). isRelated(X,Y):- relatives(X,Y). isRelated(X,Y):- …
cYn
  • 3,291
  • 6
  • 25
  • 43
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

Can't understand why is prolog looping infinitly

From Bratko's book, Prolog Programming for Artificial Intelligence (4th Edition) We have the following code which doesn't work - anc4(X,Z):- anc4(X,Y), parent(Y,Z). anc4(X,Z):- parent(X,Z). In the book, on page 55, figure 2.15, is…
Assaf
  • 1,112
  • 4
  • 14
  • 35
3
votes
4 answers

Create a list of unique numbers by applying transitive closure

I have a list of tuples (each tuple consists of 2 numbers) like: array = [(1, 2), (1, 3), (2, 4), (5, 8), (8, 10)] Lets say, these numbers are ids of some db objects (records) and inside a tuple, there are ids of duplicate objects. Which means 1…
Zohaib Ijaz
  • 21,926
  • 7
  • 38
  • 60
3
votes
1 answer

Prolog - 2 ways for progenitor predicate implementation

Given a set of facts that represent parent-child relationships via the predicate parent/2, what are the differences when defining the relation "progenitor"(ancestor) with the predicates pred1/2 and pred2/2 as shown below? pred1(X,Z) :-…
Da Mike
  • 447
  • 4
  • 17
3
votes
3 answers

Do I need "base step" to make a recursion on Prolog?

I'm learning Prolog at my university and I'm stuck with a question. Note that I'm a newbie in Prolog and I don't even know the correct spelling of Prolog elements. I need to define a recursive rule in my .pl file and I don't know if I need a "base…
Paladini
  • 4,522
  • 15
  • 53
  • 96
3
votes
2 answers

Recursive reference in prolog

I meet some problem when I try to implement friends(mia, ellen). friends(mia, lucy). friends(X,Y) :- friends(X,Z), friends(Y,Z). and when i ask ?- friends(mia, X)., it run out of local stack. Then I add friends(ellen, mia) friends(lucy, mia)…
Weslin
  • 33
  • 4
3
votes
2 answers

Prolog graph path search with cyclic path

I am a complete newbie in Prolog. I am trying to figure out a problem where I need to check if path is present between edges. I am done with acyclic graph code for cyclic my code is going to infinite loop. path(Start, End) :- edge(Start,…
3
votes
2 answers

Determining if graph is connected in prolog

I need to make a predicate isConnected/1 that takes a graph as an argument and determines if there is an undirected path between the pairs. Suppose I have a list of edges (where G is a graph): isEdge(G,1,2). isEdge(G,2,3). isEdge(G,4,5). So because…
3
votes
2 answers

Prolog "Out of local stack" Error

Here is my simple Prolog program: friend(X,Y):- knows(X,Y). friend(X,Z):- friend(X,Y), friend(Y,Z). knows(brian,tom). knows(tom,peter). If I type the following query friend(brian,peter). Prolog will give the following output: ?-…
Pingu
  • 646
  • 1
  • 5
  • 19
3
votes
1 answer

PROLOG how to "connect" similar objects

Hey im new to prolog and was wondering: Let's say i have this code: component(a,b). component(a,c). component(a,d). component(b,e). component(b,f). and i want to create an argument consistsof(X,Y):- component(X,Y); component(Y,Z). that…
zero
  • 35
  • 3
3
votes
2 answers

An infinite success tree, or not?

I'm given the following program: edge(a,b). edge(b,c). edge(a,d). path(N,M):- path(N,New),edge(New,M). path(N,M):- edge(N,M). And asked if when applying a proof tree algorithm to the following query: ?- path(a,X). the proof tree is an infinite…
Rachel Bernouli
  • 225
  • 2
  • 9
3
votes
3 answers

not stop after true answer in prolog

i write this programm for give me this result : "X=john" "Y=jane" likes(john,mary). likes(mary,jane). likes(l,k). likes(X,Y) :- likes(X,Z), likes(Z,Y). but if run this programm such that this result: i think the programm get in loop ! i want to…
user2254798
  • 553
  • 2
  • 6
  • 17
3
votes
2 answers

Finding Least Common Ancestor from a Transitive Closure Table

I have a table representing the transitive closure of an organizational hierarchy (i.e., its a tree with a single root): create table ancestry ( ancestor integer, descendant integer, distance integer ); I have another table that…
3
votes
2 answers

Algorithm for computing transitive closures on DAGs by harnessing machine words?

Let G be DAG with n vertices and m edges given by adjacency matrix. I need to calculate it's closure in form of a matrix as well. We have a computer that each word is b bits. and I need to find an algorithm that calculate the transitive closure in…
Anna
  • 59
  • 1
  • 2
  • 8
1
2
3
9 10