Author Topic: Inconsistent handling of logic functions  (Read 3289 times)

Offline Sprotiel

  • Bot Destroyer
  • ***
  • Posts: 135
    • View Profile
Inconsistent handling of logic functions
« on: January 21, 2007, 06:27:13 PM »
In 2.42.9u, on an empty condition stack:
* 'not' is true
* 'and' is true
* 'or' is true
* 'xor' is false
*'(true) and' is true
*'(false) and' is false
*'(true) or' is true
*'(false) or' is true
*'(true) xor' is true
*'(false) xor' is true
This is inconsistent in the sense that it is not possible to assume that a boolean is generated to fill the missing operands, contrarily to what happens with the integer stack (missing operands are replaced by 0).
Since an empty stack is true, as far as gene execution is concerned, what would make the most sense would be to use 'true' as default, fill-in value. Besides, it only causes a change of behaviour in the 2 italicized cases out of 10.

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Inconsistent handling of logic functions
« Reply #1 on: January 21, 2007, 06:54:05 PM »
I've looked at the code in this area.  The intent of whoever wrote this appears to have been that if the boolean stack is empty and a boolean operator is encountered that requires a value be popped off the empty stack, that the boolean operation is simply ignored.

However, there is a bug in the current implementation.  PopBoolStack() currently returns -5 if the stack is empty but ExecuteLogic() is checking for a return value of 5 (not -5) when deciding whether to attempt to perform the boolean operation.  Thus, the intent of the original programmer isn't being achevied.  Boolean operations are currently always performed when the stack is empty with the inconsistant results you sight.

I can either fix the bug and make it work as intended I.e. boolean operations on empty stack values are simply ignored or as you suggest, I can have PopBoolStack return True when the stack is empty.

I plan to do the latter unless there are objections.
Many beers....

Offline Sprotiel

  • Bot Destroyer
  • ***
  • Posts: 135
    • View Profile
Inconsistent handling of logic functions
« Reply #2 on: January 21, 2007, 07:51:29 PM »
Quote from: EricL
I plan to do the latter unless there are objections.

Actually, I have one: it'll break some existing evolved bots. It's quite hard to know which proportion exactly, but it won't be negligible. However, such considerations have never prevented us from changing the program, so I think we can proceed.

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Inconsistent handling of logic functions
« Reply #3 on: January 21, 2007, 09:12:05 PM »
I have implemented the change and have been running my large evo sim for several hours with no detectable impact.  This does not change your point however - some bots will break.  But I agree we should make the change.

BTW, for the next version, I have also increased the stack sizes for both the integer and boolean stacks from 20 to 100.  In current versions, pushing the 21st value onto either stacks looses the 1st value.
Many beers....

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Inconsistent handling of logic functions
« Reply #4 on: January 21, 2007, 10:44:37 PM »
The more I think about it, the less I think there will be much impact given the lack of evolved conditional logic to date and the fact that boolean operators arn't exected outside cond sections which evo bots tend not to utilize anyway (so far).
Many beers....

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Inconsistent handling of logic functions
« Reply #5 on: January 23, 2007, 01:41:04 PM »
Tying up loose ends.  This was fixed in 2.42.9v.
Many beers....