opennars / OpenNARS-for-Applications

General reasoning component for applications based on NARS theory.
https://cis.temple.edu/~pwang/NARS-Intro.html
MIT License
91 stars 40 forks source link

[bug] NAR answering with `precondition_beliefs` about "do nothing operator" #286

Open ARCJ137442 opened 1 month ago

ARCJ137442 commented 1 month ago

Background Information

I noticed that ONA has a concept of operations called "do nothing operator", which is related to NAL-8 and can be seen at:

https://github.com/opennars/OpenNARS-for-Applications/blob/96f4d032183b23c6fcef92cc4ac3947151f784a6/src/Decision.h#L87-L88

In normal code logic, the integer "operator id" corresponding to this "do nothing operator" is 0, and in many places "is do-nothing operator or not" is distinguished by op or !op:

https://github.com/opennars/OpenNARS-for-Applications/blob/96f4d032183b23c6fcef92cc4ac3947151f784a6/src/Cycle.c#L385-L389

Some code refers to "traversing all real operators" by explicitly traversing 1 through OPERATIONS_MAX:

https://github.com/opennars/OpenNARS-for-Applications/blob/96f4d032183b23c6fcef92cc4ac3947151f784a6/src/Decision.c#L423

The Main Issue

The main issue happens in the following code:

https://github.com/opennars/OpenNARS-for-Applications/blob/96f4d032183b23c6fcef92cc4ac3947151f784a6/src/NAR.c#L190-L211

Notice the int op_k = 0; op_k<OPERATIONS_MAX in the code, which actually means "traverse the previous operator from the do-nothing operator to the last operator" when the field precondition_beliefs in struct Concept is defined to allow "do nothing operator" in index 0:

https://github.com/opennars/OpenNARS-for-Applications/blob/96f4d032183b23c6fcef92cc4ac3947151f784a6/src/Concept.h#L57

So, Do we need to prohibit traversing "do nothing operator" here? Like the following:

for(int op_k = 1; op_k<=OPERATIONS_MAX; op_k++)

Or do you want to allow all operations including "do nothing operator"?

for(int op_k = 0; op_k<=OPERATIONS_MAX; op_k++)

(like above)

Or, Do we need to make a clear distinction between "real operators" and "do nothing operator" and "no operation id found"?

patham9 commented 1 month ago

The code does the right thing there, the code piece you reference searches the implication tables for a link which unifies with the users's question. But I agree this index trickery sucks and can potentially be improved at some point. :)

patham9 commented 1 month ago

Also: your observation that index 0 is reserved for temporal implications without operation (which is like a do-nothing operator almost) is valid.