Skip to content

What is the best way to implement transitive closure/chaining using match and add-atom? #73

@CICS-Oleg

Description

@CICS-Oleg

Suppose we have the following knowledge base:

(Parent Tom Bob)
(Parent Pam Bob)
(Parent Tom Liz)
(Parent Bob Ann)
(Parent Bob Pat)
(Parent Pat Jim)
(Parent Jim Lil)

How to implement transitive closure through the loop of the match-based rules below in the most efficient way?

!(match &self (Parent $x $y) (add-atom &self (Predecessor $x $y)))
!(match &self (, (Parent $x $y) (Predecessor $y $z)) (add-atom &self (Predecessor $x $z)))

The main parts of the question are:

how to effectively check immutability of the space to stop the loop?

and how to effectively populate space with intermediate inference results without duplicates of what's been done on the previous steps?

For now I'm doing the last with the "function" like that (from this issue)

(= (not_exist $pattern)
    (unify &self $pattern Fasle True))

but it seems kinda awkward.

Metadata

Metadata

Assignees

Labels

answeredTutorial question is answered but not added to docshelp wantedExtra attention is neededquestionFurther information is requestedtutorialTutorial question

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions