Loading custom character sets

Basic and Machine Language

Moderator: Moderators

User avatar
ral-clan
plays wooden flutes
Posts: 3702
Joined: Thu Jan 26, 2006 2:01 pm
Location: Canada

Post by ral-clan »

Leeeeee wrote:Priorities in descending order are ..

This is pretty much standard for all Microsoft BASICs.

Lee.
Is there any hard reason "order of operations" (what we called it in school) exists or is it just a standard that was arbitrarily set?

I mean, why not just do the operations (X, +, -, or whatever) as they occur in the formula (sequentially)?

Just wondering - I really suck at math so it's not obvious to me.
vic user
VicGyver
Posts: 1401
Joined: Thu Mar 25, 2004 9:40 am

Post by vic user »

I mean, why not just do the operations (X, +, -, or whatever) as they occur in the formula (sequentially)?
you can answer that one yourself i think.

just take and equation and solve it using different orders of operation, and notice how many different answers you get.
vic user
VicGyver
Posts: 1401
Joined: Thu Mar 25, 2004 9:40 am

Post by vic user »

i found this:
Date: 11/22/2000 at 12:12:26
From: Doctor Peterson
Subject: Re: History of Order of Operations

Hi, Brian.

The Order of Operations rules as we know them could not have existed
before algebraic notation existed; but I strongly suspect that they
existed in some form from the beginning - in the grammar of how people
talked about arithmetic when they had only words, and not symbols, to
describe operations. It would be interesting to study that grammar in
Greek and Latin writings and see how clearly it can be detected.

At the other end, I think that computers have influenced the subject,
so that it is taught more rigidly now than it used to be, since
programming languages have had to define how every expression is to be
interpreted. Before then, it was more acceptable to simply recognize
some forms, like x/yz, as ambiguous and ignore them - something I
think we should do more often today, considering some of the questions
we get on such issues.

I spent some time researching this question, because it is asked
frequently, but I have not found a definitive answer yet. We can't say
any one person invented the rules, and in some respects they have
grown gradually over several centuries and are still evolving.

Here are my conclusions, perhaps in more detail than you want:

1. The basic rule (that multiplication has precedence over addition)
appears to have arisen naturally and without much disagreement as
algebraic notation was being developed in the 1600s and the need for
such conventions arose. Even though there were numerous competing
systems of symbols, forcing each author to state his conventions at
the start of a book, they seem not to have had to say much in this
area. This is probably because the distributive property implies a
natural hierarchy in which multiplication is more powerful than
addition, and makes it desirable to be able to write polynomials with
as few parentheses as possible; without our order of operations, we
would have to write

ax^2 + bx + c
as
(a(x^2)) + (bx) + c

It may also be that the concept existed before the symbolism, perhaps
just reflecting the natural structure of problems such as the
quadratic.

You can see an example of early notation in "Earliest Uses of Grouping
Symbols" at:

http://jeff560.tripod.com/grouping.html

where the use of a vinculum (an early version of parentheses) shows,
both in its presence (around an additive expression) and its absence
(around the multiplicative term "B in D") that the rules were
implicitly followed:
________________
In Van Schooten's 1646 edition of Vieta, B in D quad. + B in D
is used to represent B(D^2 + BD).

2. There were some exceptions early in this development; in
particular, math historian Florian Cajori quotes many writers for
whom, in the special case of a factorial-like expression such as

n(n-1)(n-2)

the multiplication sign seems to have had some of the effect of an
aggregation symbol; they would write

n * n - 1 * n - 2

(using a dot or cross where I have the asterisks) to express this. Yet
Cajori points out that this was an exception to a rule already
established, by which "nn-1n-2" would be taken as the quadratic
"n^2 - n - 2."

There was also an early notation in which a multiplication would be
replaced by a comma to indicate aggregation:

n, n - 1

would mean

n (n - 1)

whereas

nn-1

meant

n^2 - 1.

3. Some of the specific rules were not yet established in Cajori's own
time (the 1920s). He points out that there was disagreement as to
whether multiplication should have precedence over division, or
whether they should be treated equally. The general rule was that
parentheses should be used to clarify one's meaning - which is still
a very good rule. I have not yet found any twentieth-century
declarations that resolved these issues, so I do not know how they
were resolved. You can see this in "Earliest Uses of Symbols of
Operation" at:

http://jeff560.tripod.com/operation.html

4. I suspect that the concept, and especially the term "order of
operations" and the "PEMDAS/BEDMAS" mnemonics, was formalized only in
this century, or at least in the late 1800s, with the growth of the
textbook industry. I think it has been more important to text authors
than to mathematicians, who have just informally agreed without
needing to state anything officially.

5. There is still some development in this area, as we frequently hear
from students and teachers confused by texts that either teach or
imply that implicit multiplication (2x) takes precedence over
explicit multiplication and division (2*x, 2/x) in expressions
such as a/2b, which they would take as a/(2b), contrary to the
generally accepted rules. The idea of adding new rules like this
implies that the conventions are not yet completely stable; the
situation is not all that different from the 1600s.

In summary, I would say that the rules actually fall into two
categories: the natural rules (such as precedence of exponential over
multiplicative over additive operations, and the meaning of
parentheses), and the artificial rules (left-to-right evaluation,
equal precedence for multiplication and division, and so on). The
former were present from the beginning of the notation, and probably
existed already, though in a somewhat different form, in the geometric
and verbal modes of expression that preceded algebraic symbolism. The
latter, not having any absolute reason for their acceptance, have had
to be gradually agreed upon through usage, and continue to evolve.

You can see a briefer answer in our archives at:

Ordering the Operations
http://mathforum.org/library/drmath/view/58237.html

and some of the current debates here:

More on Order of Operations
http://mathforum.org/library/drmath/view/57021.html

- Doctor Peterson, The Math Forum
http://mathforum.org/dr.math/
User avatar
ral-clan
plays wooden flutes
Posts: 3702
Joined: Thu Jan 26, 2006 2:01 pm
Location: Canada

Post by ral-clan »

vic user wrote:
I mean, why not just do the operations (X, +, -, or whatever) as they occur in the formula (sequentially)?
you can answer that one yourself i think.

just take and equation and solve it using different orders of operation, and notice how many different answers you get.
I do get that, yes. But couldn't the SEQUENCE (left to right) in which you write the equation be (hypothetically) used as the standard which sets the order of operations (i.e. all operators to the left take precedence over those to the right).

i.e. instead of writing

1 + 2 X 4 = 9

write:

2 X 4 + 1 = 9

It seems the second way is more intuitive to me. Just write it in a way so that from let to right, it equals what you want.

...I realize I'm in way over my head here and am probably missing something important :oops: .

EDIT: I just saw your second long post and will read it now.

PS: on a similar note, have you ever looked at the skill testing question on the back of those scratch-n-win lottery tickets. By law here in Ontario, all lotteries must have the winner fulfill a skill testing question to claim his or her prize (this is so the lotteries "technically" become competitions of skill rather than "games of chance" - or gambling - under Ontario law). Even Tim Horton's (doughnut shop) makes winners of its "Roll Up the Rim" paper cup contest fill out a simple math question to claim the prize. The math question is usually just a "token" question - so simple as to be easy enough for anyone to do it.

Here is a news story about this - and how one lady got it wrong and couldn't claim her prize:

http://cnews.canoe.ca/CNEWS/Canada/2008 ... 1-sun.html

Anyway, my point it, some of those skill-testing questions involve different operators in the same equation - but the instructions on the back of the lottery ticket where the question is printed doesn't specify if "order of operations" applies (and shouldn't it, by default, apply?)

The Tim Horton's skill-testing question (with their "official" answer) was:

8 x 6 - 5 + 9 = 52

But if Order of Operations states this priority:
Brackets / O / Division / Multiplication / Addition / Subtraction.

Then shouldn't the answer be: 34

My reasoning:

8 X 6 = 48
5 + 9 = 14
so...
48 - 14 = 34

See, this is exactly what I mean about it being non-intuitive (unless I've gotten something wrong!)

So if I used order of operations I would be denied my prize! :P
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

In German speaking countries, the most important rule goes: "Punktrechnung geht vor Strichrechnung",

literally translated to: "Dot calculations take precedence over Dash calculations.",

which stems from the writing of Multiplication as "·" (a dot at half height), and Division as ":", while Addition, and Subtraction are written with "+", and "-". For example, 2+3·5=17. I use this formula to check, whether a calculator obeys these rules. Cheap ones often don't, and return 25.

As Lee already pointed out, Multiplication and Division share the same priority, as well as Addition and Subtraction: Operators of same priority are evaluated from left to right.

It is also quite common in formulas to write negative numbers in brackets: (-1), because the "Morse sign" "·-" could easily be mistaken for a "-" alone. Also, it solves the ambiguity of sign versus exponentiation: Some languages, or calculators evaluate "-1^2" as "-(1^2)", others as "(-1)^2". If one writes "(-1)^2" from the beginning, this ambiguity can be avoided.
User avatar
Kweepa
Vic 20 Scientist
Posts: 1315
Joined: Fri Jan 04, 2008 5:11 pm
Location: Austin, Texas
Occupation: Game maker

Post by Kweepa »

Thanks vic-user, very interesting!
ral-clan wrote:8 x 6 - 5 + 9 = 52

But if Order of Operations states this priority:
Brackets / O / Division / Multiplication / Addition / Subtraction.

Then shouldn't the answer be: 34

My reasoning:

8 X 6 = 48
5 + 9 = 14
so...
48 - 14 = 34
No, priority of operations is:
Brackets
Order
Division & Multiplication
Addition & Subtraction

Anything on the same priority level is evaluated left to right.
(See the table the VIC uses on the previous page)

8 x 6 = 48
48 - 5 + 9 = 43 + 9 = 52

Another way to look at this is to consider all - signs as unary minus and all / signs as unary divide, with priority just below brackets.

8 x 6 - 5 + 9
8 x 6 + (-5) + 9
48 + (-5) + 9
52

4 / 2 - 1
4 x (1/2) + (-1)
2 + (-1)
1
Legacy
Vic 20 Enthusiast
Posts: 154
Joined: Wed Dec 31, 2008 4:01 pm

Post by Legacy »

Ok guys, for real, I havnt been in college for 6 years, I just forgot a couple operations so thank you, now back to the matter at hand! My Legacy program was complete I thought, then I plugged it into my unexpanded and when I hit run, it prints out @.A.B.C.D.E. on the screen, like nothing was ever transferred from ROM to RAM at all... very odd, then my Run/Stop key was busted, I couldnt do anything! It runs fine on VICE why wont a real vic run it the same?

1 poke52,28:poke56,28: clr
2 for i=7168 to 7679:poke i,peek(i+25600):next
3 poke 36869,255
10 for l=7168 to 7168 + 6*8 - 1:read a:pokel,a:next
20 data 48,48,96,96,192,192,254,254
21 data 254,254,192,204,108,96,60,60
22 data 240,240,192,239,239,118,62,30
23 data 62,62,102,102,214,214,6,6
24 data 24,56,112,96,192,192,254,254
25 data 198,230,118,62,30,6,30,30
30 poke 36879,8
35 print"{clr}{white}{right 6, down7} @.a.b.c.d.e."
40 for s = 1 to 1000
45 for i = 1 to 7
50 p=38560
52 for v=1to6: poke p,i:p=p+2:next v
55 for t=1to25:next t:next i:next s



60 rem line 10 = 7215
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

The program is in order.
Legacy wrote:then I plugged it into my unexpanded and when I hit run, ...
Exactly how did you transfer the program to the VIC?

One simple typo in one of the POKE statements can send your VIC to Tumbolia.
User avatar
pitcalco
just pitcalco
Posts: 1272
Joined: Wed Dec 28, 2005 4:13 pm
Location: Berlin

Post by pitcalco »

Ral-clan,

You might be interested in Reverse Polish Notation which by its very nature eliminates many of the problems associated with the precedence of operations.

http://en.wikipedia.org/wiki/Reverse_polish_notation

Machine language programmers, I suspect, would have a particular taste for that convention
There are only three kinds of people in the world: those who can count and those who can't.

Paul Lambert
Berlin
Federal Republic of Germany
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Forth and Lisp programmers (although in the latter case not reversed) already know about this notation. :) Well, owners of certain TI calculators too.
Anders Carlsson

Image Image Image Image Image
Legacy
Vic 20 Enthusiast
Posts: 154
Joined: Wed Dec 31, 2008 4:01 pm

Post by Legacy »

So when we want to tell BASIC user RAM (4096 to 7679) to use less memory then it really has in order to store ROM memory there we can do the following pokes:

poke 52,20 :poke 56,20 this frees up 2559k from 5120 to 7679
poke 52,24 :poke 56,24 this frees up 1535k from 6144 to 7679
poke 52,28 :poke 56,28 this frees up 512k from 7168 to 7679
(also assumes screen memory starts at 7680 and is unexpanded)

Which is stated page 84 Programmers reference guide. Is there anyway to free up less than 512 k?

I experimented with poke 52,29 :poke 56,29 and it gave me total 3325 bytes free or 258 freed up from 7421-7679, shouldn't this be a more even number such as 256

And 52,30 56,30 is almost all free except 2 bytes 3581 or 7677 to 7679
Post Reply