Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0001005Core InformEquations, units, arithmeticpublic2012-09-21 15:262014-05-07 07:34
ReporterVictor Gijsbers 
Assigned Tograham 
PrioritynormalSeverityseriousReproducibilityalways
StatusclosedResolutionfixed 
Platformx86OSWindowsOS Version7
Product Version6G60 
Target VersionFixed in Version6L02 
Summary0001005: Order of operations is not respected for arithmatic written in words
DescriptionWhen you use words like "minus" and "divided by" instead of the arithmetical symbols, Inform 7 fails to take to order of operations into account. Thus,

6 - 4 / 2

will evaluate (correctly) to 4, while

6 minus 4 divided by 2

will evaluate (incorrectly) to 1. Obviously, this shouldn't happen.
Minimal Source Text To Reproduce
"Say it with words" by Victor Gijsbers

Mathematical laboratory is a room.

When play begins:
   let n be 6 - 4 / 2;
   say "Obviously, 6 minus 4 divided by 2 is [n].";
   let m be 6 minus 4 divided by 2;
   say "Unless, of course, it is [m]."
Additional InformationMore discussion, including people delving into the generated I6 code:

http://www.intfiction.org/forum/viewtopic.php?f=7&t=5818 [^]
TagsNo tags attached.
Effect(serious/mild) Game compiles but misbehaves
Attached Files

- Relationships
related to 0000776closedgraham Subtraction and division are right associative 
related to 0000905closedgraham Compiler assumes one interpretation for ambiguous source text 
related to 0001179closedgraham Order of operations reversed for arithmetic written in symbols 

-  Notes
(0001843)
EmacsUser (manager)
2012-09-21 18:37

Confirmed, and possibly a duplicate of 0000776 in the sense that both problems stem from the Inform's limitation of one nonterminal per kind.
(0001844)
zarf (developer)
2012-09-21 19:43

I don't know enough about the parsing to know where nonterminals fit into this, but I see that 776 doesn't depend on whether the code uses words or symbols. This one does.

Also, as climbingstars notes in the thread, order of operations is not just ignored but reversed here.

showme 4 / 2 minus 6;

...prints -1 instead of -4.
(0001845)
EmacsUser (manager)
2012-09-22 07:54
edited on: 2012-09-22 09:46

Right. But it's not a words vs. non-words issue; cf.

- - - -
When play begins:
    showme 4 * 2 - 6;
    showme 4 - 2 * 6.
- - - -

As far as I can tell, Inform has a list of productions and goes through them until it can find one whose fixed words all appear. Then it recurses on the in-between parts. The phrases here are tried in the order ``divided by'', ``-'', ``/'', and ``minus'', which means that ``minus'' binds most tightly and ``divided by'' least tightly. 0000776 is turning out the way it does because Inform grabs onto the first occurrence of the fixed words, so ``1 - 2 - 3'' recurses on the ``2 - 3'', not the ``1 - 2''. I suppose I should mark some of the umbrella issues as related.

The way almost all compilers solve both these problems is something like (pseudocode):

To decide what arithmetic value [tier 2] is (X - an arithmetic value [tier 2]) minus (Y - an arithmetic value [tier 1]): ...
To decide what arithmetic value [tier 1] is (X - an arithmetic value [tier 1]) divided by (Y - an arithmetic value [tier 0]): ...

where expressions can be implicitly moved to higher tiers:

To decide what arithmetic value [tier 2] is (X - an arithmetic value [tier 1]): (- {X} -).
To decide what arithmetic value [tier 1] is (X - an arithmetic value [tier 0]): (- {X} -).

and brackets convert expressions to tier 0:

To decide what arithmetic value [tier 0] is ( (X - an arithmetic value [tier 2]) ): (- {X} -).

So if Inform were to follow suit in some way, the same fix would squash this and 0000776, hence my comment. But yes, that probably doesn't make the bugs duplicates.

(0002269)
graham (administrator)
2014-01-12 06:14

This is by design. Arithmetic symbols obey the usual mathematical rules, but English doesn't.

- Issue History
Date Modified Username Field Change
2012-09-21 15:26 Victor Gijsbers New Issue
2012-09-21 18:28 EmacsUser Relationship added related to 0000776
2012-09-21 18:37 EmacsUser Note Added: 0001843
2012-09-21 18:37 EmacsUser Status new => confirmed
2012-09-21 19:43 zarf Note Added: 0001844
2012-09-22 07:54 EmacsUser Note Added: 0001845
2012-09-22 09:43 EmacsUser Note Edited: 0001845 View Revisions
2012-09-22 09:44 EmacsUser Relationship added related to 0000905
2012-09-22 09:46 EmacsUser Note Edited: 0001845 View Revisions
2014-01-12 06:14 graham Note Added: 0002269
2014-01-12 06:14 graham Status confirmed => resolved
2014-01-12 06:14 graham Resolution open => fixed
2014-01-12 06:14 graham Assigned To => graham
2014-01-12 18:25 EmacsUser Issue cloned 0001179
2014-01-12 18:25 EmacsUser Relationship added related to 0001179
2014-05-07 07:34 jmcgrew Fixed in Version => 6L02
2014-05-07 07:34 jmcgrew Status resolved => closed


Copyright © 2000 - 2010 MantisBT Group
Powered by Mantis Bugtracker