Skip to content

Ancestry query #110

Answered by EvgSkv
jedi1992 asked this question in Q&A
Discussion options

You must be logged in to vote

That's right, this form works as well. If you don't put any parenthesis then it's interpreted as

AncestryInDownDirection(a,b) distinct :-
  (Parent(a,b) | AncestryInDownDirection(a,x)), Parent(x,b) ;

Which is still a correct definition of ancestry. Even though maybe not very intuitive :-)
It's more intuitive with parenthesis

AncestryInDownDirection(a,b) distinct :-
  Parent(a,b) | (AncestryInDownDirection(a,x), Parent(x,b)) ;

Note that the depth of ancestry as a function of the number of recursive steps grows linearly in this rule and exponentially in the rule from the tweet. So if your tree is deep, but is manageable then the query from the tweet is preferred. On the other hand if you …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jedi1992
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants