Hi,
Has anyone got a patch for the associativity bug in pMARS? E.g. the
following two DATs should be identical, but are evaluated right-to-left
when assembled:
dat 0 - 2*1000 - 3*100
dat 0 - 3*100 - 2*1000
Assembles to:
START DAT.F # 0, $ -1700
DAT.F # 0, $ 1700
Thanks,
John
On Sunday, 1 May 2022 at 9:46:04 pm UTC+8, Stephen Gunnell wrote:
On Sunday, 1 May 2022 at 2:59:37 pm UTC+8, John Metcalf wrote:
Hi,
Has anyone got a patch for the associativity bug in pMARS? E.g. the following two DATs should be identical, but are evaluated right-to-left when assembled:
dat 0 - 2*1000 - 3*100
dat 0 - 3*100 - 2*1000
Assembles to:
START DAT.F # 0, $ -1700
DAT.F # 0, $ 1700
Thanks,
JohnNo but I did manage to build the standalone test version of eval.c. It is late at night here now, I'll have a look at it tomorrow.
StevegOkay, I can confirm that as a bug in eval.c:
steve@steve-Latitude-5320:~/pmars-0.9.2/src$ ./evaltest
Enter infix expression: 0-2*1000-3*100
1700 = (2000 - (3 * ..))
1700 = ((2 * 1000) - ..)
-1700 = (0 - (2 * ..))
-1700 = (0 # (0 - ..))
Evaluation result: -1700
I'll spelunk around in there and see if I can see what is going on. But it is at least 30 years since I last wrote an expression parsed so I may be some time relearning.
Steveg
On Sunday, 1 May 2022 at 2:59:37 pm UTC+8, John Metcalf wrote:
Hi,
Has anyone got a patch for the associativity bug in pMARS? E.g. the following two DATs should be identical, but are evaluated right-to-left when assembled:
dat 0 - 2*1000 - 3*100
dat 0 - 3*100 - 2*1000
Assembles to:
START DAT.F # 0, $ -1700
DAT.F # 0, $ 1700
Thanks,
JohnNo but I did manage to build the standalone test version of eval.c. It is late at night here now, I'll have a look at it tomorrow.
Steveg
steve@steve-Latitude-5320:~/pmars-0.9.2/src$ ./evaltest
Enter infix expression: 0-2*1000-3*100
1700 = (2000 - (3 * ..))
1700 = ((2 * 1000) - ..)
-1700 = (0 - (2 * ..))
-1700 = (0 # (0 - ..))
Evaluation result: -1700
On Monday, 2 May 2022 at 7:40:48 am UTC+8, Stephen Gunnell wrote:
On Sunday, 1 May 2022 at 9:46:04 pm UTC+8, Stephen Gunnell wrote:
On Sunday, 1 May 2022 at 2:59:37 pm UTC+8, John Metcalf wrote:
Hi,
Has anyone got a patch for the associativity bug in pMARS? E.g. the following two DATs should be identical, but are evaluated right-to-left when assembled:
dat 0 - 2*1000 - 3*100
dat 0 - 3*100 - 2*1000
Assembles to:
START DAT.F # 0, $ -1700
DAT.F # 0, $ 1700
Thanks,
JohnNo but I did manage to build the standalone test version of eval.c. It is late at night here now, I'll have a look at it tomorrow.
StevegOkay, I can confirm that as a bug in eval.c:
steve@steve-Latitude-5320:~/pmars-0.9.2/src$ ./evaltest
Enter infix expression: 0-2*1000-3*100
1700 = (2000 - (3 * ..))
1700 = ((2 * 1000) - ..)
-1700 = (0 - (2 * ..))
-1700 = (0 # (0 - ..))
Evaluation result: -1700
I'll spelunk around in there and see if I can see what is going on. But it is at least 30 years since I last wrote an expression parsed so I may be some time relearning.
StevegIt is implementing precedence correctly but it is evaluating equal precedence right to left rather than left to right:
steve@steve-Latitude-5320:~/pmars-0.9.2/src$ ./evaltest
Enter infix expression: 0-2*1000-3*100
CALC x 2 y 1000 op *
CALC x 3 y 100 op *
CALC x 2000 y 300 op -
D 1700 = (2000 - (3 * ..))
A 1700 = ((2 * 1000) - ..)
CALC x 0 y 1700 op -
D -1700 = (0 - (2 * ..))
CALC x 0 y -1700 op #
D -1700 = (0 # (0 - ..))
Evaluation result: -1700
Steveg
In eval.c find:
if ((prec1 = PRECEDENCE(oper1)) >= (prec2 = PRECEDENCE(oper2))) {
if (prec2 >= prevPrec || prec1 <= prevPrec) {
expr = eval(prec1, calc(val1, val2, oper1), oper2, expr, result); change to:
if ((prec1 = PRECEDENCE(oper1)) >= (prec2 = PRECEDENCE(oper2))) {
if (prec2 > prevPrec || prec1 <= prevPrec) {
expr = eval(prec1, calc(val1, val2, oper1), oper2, expr, result);
ie: change "prec2 >= prevPrec" to "prec2 > prevPrec"
steve@steve-Latitude-5320:~/pmars-0.9.2/src$ ./evaltest Enter infix expression: 0-2*1000-3*100
CALC x 2 y 1000 op *
B 2000 = (2 * 1000)
CALC x 0 y 2000 op -
CALC x 3 y 100 op *
CALC x -2000 y 300 op -
D -2300 = (-2000 - (3 * ..))
C -2300 = .. ? (0 - (2 * ..))
CALC x 0 y -2300 op #
D -2300 = (0 # (0 - ..))
Evaluation result: -2300
I've been meaning to chase this for a while but my trivial examples
didn't fail, thanks for the bump John.
Steveg
On Sun, 01 May 2022 17:14:04 -0700, Stephen Gunnell wrote:
In eval.c find:
if ((prec1 = PRECEDENCE(oper1)) >= (prec2 = PRECEDENCE(oper2))) {
if (prec2 >= prevPrec || prec1 <= prevPrec) {
expr = eval(prec1, calc(val1, val2, oper1), oper2, expr, result);
change to:
if ((prec1 = PRECEDENCE(oper1)) >= (prec2 = PRECEDENCE(oper2))) {
if (prec2 > prevPrec || prec1 <= prevPrec) {
expr = eval(prec1, calc(val1, val2, oper1), oper2, expr, result);
ie: change "prec2 >= prevPrec" to "prec2 > prevPrec"
On Wed, 04 May 2022 18:31:27 +0000, John Metcalf wrote:I see the same error in the testeval executable ... I've looked at the patch and I don't see why it would work. So I'm doing some further checking.
On Sun, 01 May 2022 17:14:04 -0700, Stephen Gunnell wrote:
Sorry for the delay. I've made the change above and there's a newIn eval.c find:
if ((prec1 = PRECEDENCE(oper1)) >= (prec2 = PRECEDENCE(oper2))) {
if (prec2 >= prevPrec || prec1 <= prevPrec) {
expr = eval(prec1, calc(val1, val2, oper1), oper2, expr, result);
change to:
if ((prec1 = PRECEDENCE(oper1)) >= (prec2 = PRECEDENCE(oper2))) {
if (prec2 > prevPrec || prec1 <= prevPrec) {
expr = eval(prec1, calc(val1, val2, oper1), oper2, expr, result);
ie: change "prec2 >= prevPrec" to "prec2 > prevPrec"
problem :-( There's an error with the following DAT:
dat 0-2*3-2*3+12
Using the new eval.c:
Error in line 1: 'dat 0-2*3-2*3+12'
Bad expression
Number of errors: 1
I've been searching and I think there might be a patch on Sourceforge (I haven't tested this yet):
https://sourceforge.net/p/corewar/bugs/3/
John
On Sunday, 22 May 2022 at 6:02:53 pm UTC+8, John Metcalf wrote:
On Wed, 04 May 2022 18:31:27 +0000, John Metcalf wrote:
On Sun, 01 May 2022 17:14:04 -0700, Stephen Gunnell wrote:
Sorry for the delay. I've made the change above and there's a newIn eval.c find:
if ((prec1 = PRECEDENCE(oper1)) >= (prec2 = PRECEDENCE(oper2))) {
if (prec2 >= prevPrec || prec1 <= prevPrec) {
expr = eval(prec1, calc(val1, val2, oper1), oper2, expr, result);
change to:
if ((prec1 = PRECEDENCE(oper1)) >= (prec2 = PRECEDENCE(oper2))) {
if (prec2 > prevPrec || prec1 <= prevPrec) {
expr = eval(prec1, calc(val1, val2, oper1), oper2, expr, result);
ie: change "prec2 >= prevPrec" to "prec2 > prevPrec"
problem :-( There's an error with the following DAT:
dat 0-2*3-2*3+12
Using the new eval.c:
Error in line 1: 'dat 0-2*3-2*3+12'
Bad expression
Number of errors: 1
I've been searching and I think there might be a patch on Sourceforge (I haven't tested this yet):
https://sourceforge.net/p/corewar/bugs/3/
JohnI see the same error in the testeval executable ... I've looked at the patch and I don't see why it would work. So I'm doing some further checking.
Steveg
Somehow I was missing most of the patch ... it looks reasonable now that
I can see all of it. I'll have to get a clean version of eval.c to apply
it.
Steveg
On Sun, 22 May 2022 04:44:06 -0700, Stephen Gunnell wrote:
Somehow I was missing most of the patch ... it looks reasonable now
that I can see all of it. I'll have to get a clean version of eval.c to
apply it.
Steveg
Testing your change to eval.c and Bjoern's patch, I found 17 published warriors which assemble differently:
babyswing.red, baselinep.red, bipolar.red, blackbox.red, borkked.red,
damageinf.red, dawn.red, demented40.red, fixed.red, fragility.red,
headortail.red, jedimp.red, lex2.red, mymoorekiller.red, retroq.red,
twister.red, whatever.red
I also found 3 warriors which refused to assemble using your change:
aeka.red, ethanol.red, jedimp.red
I need to take a closer look at the affected warriors.
John
On Wed, 25 May 2022 14:53:46 +0000, John Metcalf wrote:
On Sun, 22 May 2022 04:44:06 -0700, Stephen Gunnell wrote:
Somehow I was missing most of the patch ... it looks reasonable now line >> that I can see all of it. I'll have to get a clean version of eval.c to
apply it.
Steveg
Testing your change to eval.c and Bjoern's patch, I found 17 published warriors which assemble differently:
babyswing.red, baselinep.red, bipolar.red, blackbox.red, borkked.red, damageinf.red, dawn.red, demented40.red, fixed.red, fragility.red, headortail.red, jedimp.red, lex2.red, mymoorekiller.red, retroq.red, twister.red, whatever.red
I also found 3 warriors which refused to assemble using your change:
aeka.red, ethanol.red, jedimp.red
I need to take a closer look at the affected warriors.
JohnSorry, I should've been clearer. Your change gave the same results as the patch, apart from the 3 warriors which didn't assemble.
I've benchmarked the above with and without the fix, and the scores are
very similar. Most of the differences seem to be in boot distances /
qscans.
John
Hi,
Has anyone got a patch for the associativity bug in pMARS? E.g. the
following two DATs should be identical, but are evaluated right-to-left
when assembled:
dat 0 - 2*1000 - 3*100
dat 0 - 3*100 - 2*1000
Assembles to:
START DAT.F # 0, $ -1700
DAT.F # 0, $ 1700
dat 0 - 2*1000 - 3*100
dat 0 - 3*100 - 2*1000
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 403 |
Nodes: | 16 (2 / 14) |
Uptime: | 40:04:26 |
Calls: | 8,407 |
Calls today: | 2 |
Files: | 13,171 |
Messages: | 5,904,809 |