graal icon indicating copy to clipboard operation
graal copied to clipboard

BUG: parseAtom does not preserve variable names

Open shade-belisar opened this issue 6 years ago • 4 comments

When parsing the Atom "predicate(X)" with DlgpParser.parseAtom, the result is "predicate\1(I0)". I would expect it to be "predicate\1(X)". Is there a reason why the variable name is ignored, or is this a bug?

shade-belisar avatar Jan 10 '19 02:01 shade-belisar

It's because in

p(X).
q(X).

the two X must be different. see http://graphik-team.github.io/graal/doc/dlgp

sipi avatar Jan 10 '19 10:01 sipi

I see. Followup question: What is the use case of parsing an atom with variables if the names are not kept? And why does parseRule preserve the variable names?

shade-belisar avatar Jan 10 '19 12:01 shade-belisar

It just asserts that there exists X such as p(X). But, in practice with Graal we usually put all facts in a same AtomSet so we can't assert that there exists X such as p(X) and q(X) which is more specific. So it's why the Graal's dlgp parser rewrites variable names to get "there exists IO, I1 such as p(I0), p(I1)" which is logically equivalent to (there exists X such as p(X)) and (there exists X such as p(X)).

To rules and queries, variable names remain local in Graal so no need to rewrite.

However, it's true that we should provide a way to disable this behavior. What is your use case ?

sipi avatar Jan 10 '19 13:01 sipi

I am working on importing Graal into VLog4J. While I am uncertain what the use case for Atoms with Variables is (if one wanted to use them in rules, one would simply create a rule via the parser), it is possible someone will do this. In that case, I want to be able to provide comprehensive documentation explaining what is happening.

shade-belisar avatar Jan 22 '19 12:01 shade-belisar