POV-Ray : Newsgroups : povray.general : unexpected rotation result Server Time
14 Oct 2026 09:11:28 EDT (-0400)
  unexpected rotation result (Message 1 to 48 of 48)  
From: Tom Melly
Subject: unexpected rotation result
Date: 5 Feb 2001 05:07:48
Message: <3a7e7b74$1@news.povray.org>
I came across this one the other day (don't know how I'd missed this
"feature" before).

Basically, I expected the two following rotations to be identical:

rotate y * - 45 + 45
rotate y * (- 45 + 45)

However, only the second one limits the rotation to y (the behaviour I
expected), whereas the first rotates y then z. Does this seem odd to anyone
else? Why is the first statement equivalent to <0,-45,45> ? Don't you need
commas and/or chevrons for vectors involving more than one axis?

Confused of Putney.


Post a reply to this message

From: Gail Shaw
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 05:36:06
Message: <3a7e8216@news.povray.org>
Tom Melly <tom### [at] tomandlucouk> wrote in message
news:3a7e7b74$1@news.povray.org...
> I came across this one the other day (don't know how I'd missed this
> "feature" before).
>
> Basically, I expected the two following rotations to be identical:
>
> rotate y * - 45 + 45
> rotate y * (- 45 + 45)
>

I would guess that pov is doing the multiplication first then adding
45.  Hence it's doing rotate <0,-45,0> + 45.
whereas the brackets in the second force pov
to evaluate the -45+45 first and multiply with y second.

Gail
********************************************************************
* gsh### [at] monotixcoza              * System.dat not found.         *
* http://www.rucus.ru.ac.za/~gail/ * Reformat hard drive Y)es O)k  *
********************************************************************
* If at first you don't succeed, call it version 1.0               *
********************************************************************


Post a reply to this message

From: Tom Melly
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 05:45:28
Message: <3a7e8448$1@news.povray.org>
"Gail Shaw" <gsh### [at] monotixcoza> wrote in message
news:3a7e8216@news.povray.org...
>
> > rotate y * - 45 + 45
> > rotate y * (- 45 + 45)
> >
>
> I would guess that pov is doing the multiplication first then adding
> 45.  Hence it's doing rotate <0,-45,0> + 45.
> whereas the brackets in the second force pov
> to evaluate the -45+45 first and multiply with y second.
>

Ah, it would appear that my problem here was based on a more serious
underlying misunderstanding. I've always specified single-axis rotations as,
for example, rotate x * 45. I thought that this just meant rotate x 45
degrees. So what does rotate x*45 mean? 45 times what?


Post a reply to this message

From: Gail Shaw
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 05:56:48
Message: <3a7e86f0@news.povray.org>
Tom Melly <tom### [at] tomandlucouk> wrote in message
news:3a7e8448$1@news.povray.org...
>
>
> Ah, it would appear that my problem here was based on a more serious
> underlying misunderstanding. I've always specified single-axis rotations
as,
> for example, rotate x * 45. I thought that this just meant rotate x 45
> degrees. So what does rotate x*45 mean? 45 times what?
>

x is equivalent to <1,0,0> hence rotate x*45 is exactly the same
as saying rotate <1,0,0>*45 or rotate <45,0,0>

Gail
********************************************************************
* gsh### [at] monotixcoza              * System.dat not found.         *
* http://www.rucus.ru.ac.za/~gail/ * Reformat hard drive Y)es O)k  *
********************************************************************
* If at first you don't succeed, call it version 1.0               *
********************************************************************


Post a reply to this message

From: Tom Melly
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 05:58:55
Message: <3a7e876f@news.povray.org>
"Gail Shaw" <gsh### [at] monotixcoza> wrote in message
news:3a7e86f0@news.povray.org...

> x is equivalent to <1,0,0> hence rotate x*45 is exactly the same
> as saying rotate <1,0,0>*45 or rotate <45,0,0>
>

SHPINGGG! (sound of light going on in confused head)

Many thanks Hurricane Beach.


Post a reply to this message

From: PoD
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 06:02:35
Message: <3A7E8847.C9EFB12A@merlin.net.au>
Tom Melly wrote:
> 
> "Gail Shaw" <gsh### [at] monotixcoza> wrote in message
> news:3a7e8216@news.povray.org...
> >
> > > rotate y * - 45 + 45
> > > rotate y * (- 45 + 45)
> > >
> >
> > I would guess that pov is doing the multiplication first then adding
> > 45.  Hence it's doing rotate <0,-45,0> + 45.
> > whereas the brackets in the second force pov
> > to evaluate the -45+45 first and multiply with y second.
> >
> 
> Ah, it would appear that my problem here was based on a more serious
> underlying misunderstanding. I've always specified single-axis rotations as,
> for example, rotate x * 45. I thought that this just meant rotate x 45
> degrees. So what does rotate x*45 mean? 45 times what?

x = <1,0,0> so x*45 = <45,0,0>

As for the first problem, the POV parser uses normal precedence rules.
It does the multiplication first, then the addition.
y = <0,1,0> so y* -45 = <0,-45,0>
then it promotes the second 45 to a vector so that it can be added
45 becomes <45,45,45>
so the end result is <0,-45,0> + <45,45,45> = <45,0,45>

-- 
PoD.


Post a reply to this message

From: Gail Shaw
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 06:03:40
Message: <3a7e888c@news.povray.org>
Tom Melly <tom### [at] tomandlucouk> wrote in message
news:3a7e876f@news.povray.org...
>
> SHPINGGG! (sound of light going on in confused head)

Glad to have been of help.

> Many thanks Hurricane Beach.
>

ROFL. Haven't seen that one before.

Gail


Post a reply to this message

From: Tom Melly
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 06:19:45
Message: <3a7e8c51@news.povray.org>
"PoD" <pod### [at] merlinnetau> wrote in message
news:3A7E8847.C9EFB12A@merlin.net.au...

> As for the first problem, the POV parser uses normal precedence rules.
> It does the multiplication first, then the addition.
> y = <0,1,0> so y* -45 = <0,-45,0>
> then it promotes the second 45 to a vector so that it can be added
> 45 becomes <45,45,45>
> so the end result is <0,-45,0> + <45,45,45> = <45,0,45>
>

Yep, got it figured now. I'd never taken in that rotate y on its own meant
anything, so I'd misunderstood what the * in rotate y*45 meant (I vaguely
assumed it was to allow the parser to recognise a single vector
transformation).

That aside, intuitively, I would still have expected "rotate y * foo + bar"
to limit the rotations to the y axis. Still, now I know.....

All in all, it reminds me of what someone at work told me. He is an
experienced programmer and script writer, but he always uses brackets - e.g.

x := ((x*45) + 10)

When I asked him why, he said that a) he doesn't have to worry about someone
screwing up the parser, b) it makes the code clearer and c) why not?


Post a reply to this message

From: Scott Hill
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 11:15:25
Message: <3a7ed19d$1@news.povray.org>
"Tom Melly" <tom### [at] tomandlucouk> wrote in message
news:3a7e8c51@news.povray.org...
> "PoD" <pod### [at] merlinnetau> wrote in message
> news:3A7E8847.C9EFB12A@merlin.net.au...
>
> All in all, it reminds me of what someone at work told me. He is an
> experienced programmer and script writer, but he always uses brackets...
>

    Most experienced programmers/scripters do - it's the safest way to get
any language to do what _you want_, rather than what _it thinks you want_ !
E.g, what does 1+2*3-4 evaluate to ?

Scott.


Post a reply to this message

From: Gail Shaw
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 14:39:50
Message: <3a7f0186@news.povray.org>
Scott Hill <sco### [at] ncgraphicsnet> wrote in message
news:3a7ed19d$1@news.povray.org...
>     Most experienced programmers/scripters do - it's the safest way to get
> any language to do what _you want_, rather than what _it thinks you want_
!
> E.g, what does 1+2*3-4 evaluate to ?
>


If the rules of precedence that I remember are correct then that equals 3,
but it's
not clear from a quick look. I tend to use brackets if there are more that 3
terms
in an expression, regardless of whether they are actually needed or not.

Gail
--
********************************************************************
* gsh### [at] monotixcoza              * System.dat not found.         *
* http://www.rucus.ru.ac.za/~gail/ * Reformat hard drive Y)es O)k  *
********************************************************************
* If at first you don't succeed, call it version 1.0               *
********************************************************************


Post a reply to this message

From: Peter J  Holzer
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 16:01:42
Message: <slrn97u21r.1qn.hjp-usenet@teal.h.hjp.at>
On 2001-02-05 16:14, Scott Hill <sco### [at] ncgraphicsnet> wrote:
>"Tom Melly" <tom### [at] tomandlucouk> wrote in message
>news:3a7e8c51@news.povray.org...
>> "PoD" <pod### [at] merlinnetau> wrote in message
>> news:3A7E8847.C9EFB12A@merlin.net.au...
>>
>> All in all, it reminds me of what someone at work told me. He is
>> an experienced programmer and script writer, but he always uses
>> brackets...
>
>    Most experienced programmers/scripters do - it's the safest way to
>get any language to do what _you want_, rather than what _it thinks you
>want_ ! E.g, what does 1+2*3-4 evaluate to ?

That one should be the same (3) in just about every programming
language. But there are more difficult examples. E.g., what is
(0x11 & 0xF0 == 0x10) in C? C has so many operators that even the
experienced C programmer gets confused sometimes. It gets worse if you
use several programming languages with slightly different evaluation
rules.

However, more parentheses are not always more readable. Where the
average programmer already knows the precedence (e.g, multiplication
before addition), they only clutter the display and make the reader
wonder why they were used. For example, I wouldn't write
    1+(2*3)+4,
although I would probably write 
    1 + 2*3 + 4
to enhance readability for the human reader.

Really religious application of parentheses is required in macro
processors which do simple string substitutions (like cpp or those of
many assemblers). Otherwise you get nasty surprises if you do something
like

#define twice(a) a*2
printf("%d", twice(1+2));

	hp

-- 
   _  | Peter J. Holzer    | All Linux applications run on Solaris,
|_|_) | Sysadmin WSR       | which is our implementation of Linux.
| |   | hjp### [at] wsracat      | 
__/   | http://www.hjp.at/ |	-- Scott McNealy, Dec. 2000


Post a reply to this message

From: Margus Ramst
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 16:27:18
Message: <3a7f1ab6@news.povray.org>
"Peter J. Holzer" <hjp### [at] hjpat> wrote:
> 
> Really religious application of parentheses is required in macro
> processors which do simple string substitutions (like cpp or those of
> many assemblers).

Why go there, just take POV macros for example :)
I encounted several frustrating quirks with POV macros, before I learned to
use parantheses liberally both in macro bodies and around macro calls.

-- 
Margus Ramst

Personal e-mail: mar### [at] peakeduee
TAG (Team Assistance Group) e-mail: mar### [at] tagpovrayorg
Home page http://www.hot.ee/margusrt


Post a reply to this message

From: David Fontaine
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 18:09:32
Message: <3A7F3285.CAAFC1FA@faricy.net>
Scott Hill wrote:

>     Most experienced programmers/scripters do - it's the safest way to get
> any language to do what _you want_, rather than what _it thinks you want_ !
> E.g, what does 1+2*3-4 evaluate to ?

3. Bad example, that's standard basic math. Everyone learns order of operations
in elementary school! :) In fact, even with all the computer-specific
extensions like bit rotation and boolean logic, the order of precedence should
still be the same in every language.

--
David Fontaine  <dav### [at] faricynet>  ICQ 55354965
My raytracing gallery:  http://davidf.faricy.net/


Post a reply to this message

From: David Fontaine
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 18:13:59
Message: <3A7F3390.822EA9BB@faricy.net>
"Peter J. Holzer" wrote:

> That one should be the same (3) in just about every programming
> language. But there are more difficult examples. E.g., what is
> (0x11 & 0xF0 == 0x10) in C? C has so many operators that even the
> experienced C programmer gets confused sometimes. It gets worse if you
> use several programming languages with slightly different evaluation
> rules.

True, parentheses can help you be less obfuscated. But I thought all
languages had the same order of operations, except maybe a few very obscure
examples.


> However, more parentheses are not always more readable. Where the
> average programmer already knows the precedence (e.g, multiplication
> before addition), they only clutter the display and make the reader
> wonder why they were used. For example, I wouldn't write
>     1+(2*3)+4,
> although I would probably write
>     1 + 2*3 + 4
> to enhance readability for the human reader.

I find myself doing that more; put a space padding around additive
operations but bunch together multiplicative operations. That shows the
algebraic seperation of terms, which incidentally is also where the parser
should seperate it. So is useful to know. :)


--
David Fontaine  <dav### [at] faricynet>  ICQ 55354965
My raytracing gallery:  http://davidf.faricy.net/


Post a reply to this message

From: Ron Parker
Subject: Re: unexpected rotation result
Date: 5 Feb 2001 18:53:15
Message: <slrn97uf7e.4fs.ron.parker@fwi.com>
On Mon, 05 Feb 2001 17:13:20 -0600, David Fontaine wrote:
>True, parentheses can help you be less obfuscated. But I thought all
>languages had the same order of operations, except maybe a few very obscure
>examples.

Sometimes the parser has a bug, though.  Not that I'm naming names or
anything.

-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

From: Mark Wagner
Subject: Re: unexpected rotation result
Date: 6 Feb 2001 01:20:54
Message: <3a7f97c6$1@news.povray.org>
David Fontaine wrote in message <3A7F3390.822EA9BB@faricy.net>...
>
>True, parentheses can help you be less obfuscated. But I thought all
>languages had the same order of operations, except maybe a few very obscure
>examples.


All Reverse Polish Notation languages have the same order of operation:
strictly left-to-right for all operators.

--
Mark


Post a reply to this message

From: John VanSickle
Subject: Re: unexpected rotation result
Date: 6 Feb 2001 01:24:03
Message: <3A7FAE41.E1255D1A@hotmail.com>
Tom Melly wrote:
> 
> I came across this one the other day (don't know how I'd missed this
> "feature" before).
> 
> Basically, I expected the two following rotations to be identical:
> 
> rotate y * - 45 + 45

Which the parser expands to y*-45 + <45,45,45> = <45,0,45>

> rotate y * (- 45 + 45)

Which the parser evaluates as y*0.

> Confused of Putney.

Hope this enlightens,
John


Post a reply to this message

From: Scott Hill
Subject: Re: unexpected rotation result
Date: 6 Feb 2001 07:02:19
Message: <3a7fe7cb@news.povray.org>
"David Fontaine" <dav### [at] faricynet> wrote in message
news:3A7F3285.CAAFC1FA@faricy.net...
> Scott Hill wrote:
>
> >     Most experienced programmers/scripters do - it's the safest way to
get
> > any language to do what _you want_, rather than what _it thinks you
want_ !
> > E.g, what does 1+2*3-4 evaluate to ?
>
> 3.

    No ! 5.

> Bad example, that's standard basic math. Everyone learns order of
operations
> in elementary school! :) In fact, even with all the computer-specific
> extensions like bit rotation and boolean logic, the order of precedence
should
> still be the same in every language.
>

    That's the point - we and parsers all assume, because we've all learned
(or, in the case of parsers, have been hard coded with) the correct operator
ordering, that it evaluates to 3, but, I may not have meant that, I could
just as easily meant ((1+2)*3)-4 ! Without brackets it is ambiguous, to a
degree - we may default to assuming that we're meant to follow the standard
operator order rules but we don't and can't know that that assumption is
correct.

Scott.


Post a reply to this message

From: Marc-Hendrik Bremer
Subject: Re: unexpected rotation result
Date: 6 Feb 2001 07:31:34
Message: <3a7feea6$1@news.povray.org>
Scott Hill schrieb in Nachricht <3a7fe7cb@news.povray.org>...
>Without brackets it is ambiguous, to a
>degree - we may default to assuming that we're meant to follow the standard
>operator order rules but we don't and can't know that that assumption is
>correct.


Well, it is even ambiguous with brackets. Cause if you don't fallow the
standard rules, you could give the brackets a totally different meaning.
That's what makes all communication that faulty - we assume, that we follow
the same rules, but most of the time we don't. As a wise man said ones - it
is more of an wonder that communication does happens most of the time in a
correct way than the opposite.

Marc-Hendrik


Post a reply to this message

From: Warp
Subject: Re: unexpected rotation result
Date: 6 Feb 2001 07:37:08
Message: <3a7feff3@news.povray.org>
Gail Shaw <gsh### [at] monotixcoza> wrote:
: I would guess that pov is doing the multiplication first then adding 45.

  Well, that's exactly what it should do because that's the correct behaviour.
Multiplication has higher precedence than addition.

-- 
char*i="b[7FK@`3NB6>B:b3O6>:B:b3O6><`3:;8:6f733:>::b?7B>:>^B>C73;S1";
main(_,c,m){for(m=32;c=*i++-49;c&m?puts(""):m)for(_=(
c/4)&7;putchar(m),_--?m:(_=(1<<(c&3))-1,(m^=3)&3););}    /*- Warp -*/


Post a reply to this message

From: Scott Hill
Subject: Re: unexpected rotation result
Date: 6 Feb 2001 13:27:35
Message: <3a804217@news.povray.org>
"Marc-Hendrik Bremer" <Mar### [at] t-onlinede> wrote in message
news:3a7feea6$1@news.povray.org...
>
> Scott Hill schrieb in Nachricht <3a7fe7cb@news.povray.org>...
> >Without brackets it is ambiguous, to a
> >degree - we may default to assuming that we're meant to follow the
standard
> >operator order rules but we don't and can't know that that assumption is
> >correct.
>
>
> Well, it is even ambiguous with brackets. Cause if you don't fallow the
> standard rules, you could give the brackets a totally different meaning.
> That's what makes all communication that faulty - we assume, that we
follow
> the same rules, but most of the time we don't. As a wise man said ones -
it
> is more of an wonder that communication does happens most of the time in a
> correct way than the opposite.
>

    Hmm, yes, but not in the same way - you may as well say that it's
ambiguous because we _could_ interpret the numerical digits differently -
the problem is not that we're misinterpret anything, but, rather that there
isn't enough information in the original form - we need the precedence rules
to remove the ambiguity but they do not redefine or even clarify the meaning
of any of the symbols ('+' stills means 'plus', '-' still means 'minus' and
'*' still means 'times'). Likewise, adding brackets does not change the
meanings of any of the symbols, they just clarify how those symbols are
intended to interact.

Does that make any sense ?

Scott.


Post a reply to this message

From: Tom Melly
Subject: Re: unexpected rotation result
Date: 6 Feb 2001 14:45:34
Message: <3a80545e@news.povray.org>
"Scott Hill" <sco### [at] ncgraphicsnet> wrote in message
news:3a804217@news.povray.org...

<snip>

>     Hmm, yes, but not in the same way - you may as well say that it's
> ambiguous because we _could_ interpret the numerical digits differently -

<snip>

Exactly - the sentence "the man went into the farmer's toilet and took his
trousers down" is ambiguous because we don't know whether the man takes his
own or the farmer's trousers down. It is also ambiguous because "trousers"
could mean "dictation". However, one is an ambiguity within the rules of
English, whereas the latter is only ambiguous if we ignore the rules of
English. We resolve the first by using common sense - we would generally
assume that the man takes his own trousers down (unless the book has been
purchased in a specialist shop and is being read one-handed).

Unfortunately, there is no common sense that can resolve "3+2*5". There is
nothing to imply that the multiplication occurs first. It would not be
illogical to write a parser that evaluated the addition first - it doesn't
break a rule, so much as a convention designed to resolve the inherant
ambiguity. However, to write a parser that ignored brackets or treated them
as some other operator would be an act of blatent idiocy.


Post a reply to this message

From: Marc-Hendrik Bremer
Subject: Re: unexpected rotation result
Date: 6 Feb 2001 15:02:14
Message: <3a805846@news.povray.org>
Scott Hill schrieb in Nachricht <3a804217@news.povray.org>...

>Does that make any sense ?
>


Yes, it does. But only if you use a hierarchic structure for the rules, you
use. From a strictly mathematical point of you (I think) there is no
difference in the rule that multiplications are done before additions and
the one that tells you, what brackets mean or what the digit "2" mean. Or is
this not right?

From a more general point of view you and Tom are absolutely right of
course.

Marc-Hendrik


Post a reply to this message

From: David Fontaine
Subject: Re: unexpected rotation result
Date: 6 Feb 2001 18:17:03
Message: <3A8085CA.B22C86A5@faricy.net>
Scott Hill wrote:

>     No ! 5.
>
>     That's the point - we and parsers all assume, because we've all learned
> (or, in the case of parsers, have been hard coded with) the correct operator
> ordering, that it evaluates to 3, but, I may not have meant that, I could
> just as easily meant ((1+2)*3)-4 ! Without brackets it is ambiguous, to a
> degree - we may default to assuming that we're meant to follow the standard
> operator order rules but we don't and can't know that that assumption is
> correct.

NO!! 1+2*3-4 is three, only three, exactly three, no more, no less, and most
certainly not and NEVER five. If you meant (1+2)*3-4, that would be analagous to
me typing orange and meaning purple. Anyone who types 1+2*3-4 and expects 5 is
an idiot.

--
David Fontaine  <dav### [at] faricynet>  ICQ 55354965
My raytracing gallery:  http://davidf.faricy.net/


Post a reply to this message

From: David Fontaine
Subject: Re: unexpected rotation result
Date: 6 Feb 2001 18:19:51
Message: <3A808672.D37E6BD5@faricy.net>
Tom Melly wrote:

> Unfortunately, there is no common sense that can resolve "3+2*5". There is
> nothing to imply that the multiplication occurs first.

[snip]
Of course there is. It's called simple algebra.
a*x^2+b*x+c means what to you?

--
David Fontaine  <dav### [at] faricynet>  ICQ 55354965
My raytracing gallery:  http://davidf.faricy.net/


Post a reply to this message

From: Mark Wagner
Subject: Re: unexpected rotation result
Date: 7 Feb 2001 00:20:58
Message: <3a80db3a$1@news.povray.org>
David Fontaine wrote in message <3A8085CA.B22C86A5@faricy.net>...
>NO!! 1+2*3-4 is three, only three, exactly three, no more, no less, and
most
>certainly not and NEVER five. If you meant (1+2)*3-4, that would be
analagous to
>me typing orange and meaning purple. Anyone who types 1+2*3-4 and expects 5
is
>an idiot.


I just typed the expression 1+2*3-4 into my TI-1795 calculator, and, as
expected, got the number 5.

--
Mark


Post a reply to this message

From: Tom Melly
Subject: Re: unexpected rotation result
Date: 7 Feb 2001 04:24:39
Message: <3a811457$1@news.povray.org>
"David Fontaine" <dav### [at] faricynet> wrote in message
news:3A808672.D37E6BD5@faricy.net...
> Tom Melly wrote:
>
> > Unfortunately, there is no common sense that can resolve "3+2*5". There
is
> > nothing to imply that the multiplication occurs first.
>
> [snip]
> Of course there is. It's called simple algebra.
> a*x^2+b*x+c means what to you?
>

(a*(x^2)) + (b*x) + c - but this is not common sense, it is following a
convention that exists because common sense is not available.

In fact, one could argue that the only common sense option is to evaluate
the expression strictly left to right. IMHO common sense would dictate that
the solution is: (a*x)^2 + (b*x) + c.


Post a reply to this message

From: Tom Melly
Subject: Re: unexpected rotation result
Date: 7 Feb 2001 04:27:17
Message: <3a8114f5$1@news.povray.org>
"David Fontaine" <dav### [at] faricynet> wrote in message
news:3A8085CA.B22C86A5@faricy.net...

> NO!! 1+2*3-4 is three, only three, exactly three, no more, no less, and
most
> certainly not and NEVER five. If you meant (1+2)*3-4, that would be
analagous to
> me typing orange and meaning purple. Anyone who types 1+2*3-4 and expects
5 is
> an idiot.
>

I disagree. Anyone who types 2*1.5 and expects 5 is an idiot. Typing 1+2*3-4
and expecting 5 just means that they don't know the conventions. The
conventions exist because intelligence alone cannot resolve the issue.


Post a reply to this message

From: Tom Melly
Subject: Re: unexpected rotation result
Date: 7 Feb 2001 04:28:34
Message: <3a811542@news.povray.org>
"Mark Wagner" <mar### [at] gtenet> wrote in message
news:3a80db3a$1@news.povray.org...
>
> I just typed the expression 1+2*3-4 into my TI-1795 calculator, and, as
> expected, got the number 5.
>

Good point.


Post a reply to this message

From: Chris Huff
Subject: Re: unexpected rotation result
Date: 7 Feb 2001 05:33:16
Message: <chrishuff-95BA06.05341707022001@news.povray.org>
In article <3a811457$1@news.povray.org>, "Tom Melly" 
<tom### [at] tomandlucouk> wrote:

> > Of course there is. It's called simple algebra.
> > a*x^2+b*x+c means what to you?
> 
> (a*(x^2)) + (b*x) + c - but this is not common sense, it is following a
> convention that exists because common sense is not available.
> 
> In fact, one could argue that the only common sense option is to evaluate
> the expression strictly left to right. IMHO common sense would dictate 
> that the solution is: (a*x)^2 + (b*x) + c.

You still followed the precedece of * over +, I think it's even uglier:
((((a * x) ^ 2) + b) * x) + c
Unless you were only talking about individual terms.

I think my exponent patch (which allows you to use ^ for pow() in 
ordinary scene code) breaks on this, instead of evaluating that as:
(a*(x^2)) + (b*x) + c
It will see:
((a*x)^2) + (b*x) + c

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: Scott Hill
Subject: Re: unexpected rotation result
Date: 7 Feb 2001 06:40:02
Message: <3a813412$1@news.povray.org>
"Marc-Hendrik Bremer" <Mar### [at] t-onlinede> wrote in message
news:3a805846@news.povray.org...
>
> Scott Hill schrieb in Nachricht <3a804217@news.povray.org>...
>
> >Does that make any sense ?
> >
>
>
> Yes, it does. But only if you use a hierarchic structure for the rules,
you
> use. From a strictly mathematical point of you (I think) there is no
> difference in the rule that multiplications are done before additions and
> the one that tells you, what brackets mean or what the digit "2" mean. Or
is
> this not right?
>

    Hmm. IMHO, no. But then I've just tried putting into words why they're
different and I can't. I'll have to ponder on this one for while....

> From a more general point of view you and Tom are absolutely right of
> course.
>

    Of course. I'm _always_ right! ;-)

--
Scott Hill.
NC Graphics (Cambridge) Ltd.
http://www.ncgraphics.co.uk


Post a reply to this message

From: Tom Melly
Subject: Re: unexpected rotation result
Date: 7 Feb 2001 07:34:23
Message: <3a8140cf@news.povray.org>
"Chris Huff" <chr### [at] maccom> wrote in message
news:chrishuff-95BA06.05341707022001@news.povray.org...

> > that the solution is: (a*x)^2 + (b*x) + c.
>
> You still followed the precedece of * over +, I think it's even uglier:
> ((((a * x) ^ 2) + b) * x) + c
> Unless you were only talking about individual terms.
>

I didn't really follow the precedence - I just reduced the equation to a
non-ambiguous form... Well, almost. I should have written ((a*x)^2)+(b*x)+c.
As I wrote it originally, I suppose it could mean (a*x)^(2+(b*x)+c).


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: unexpected rotation result
Date: 7 Feb 2001 09:32:37
Message: <3a815c85@news.povray.org>
In article <3a80db3a$1@news.povray.org> , "Mark Wagner" 
<mar### [at] gtenet> wrote:

> I just typed the expression 1+2*3-4 into my TI-1795 calculator, and, as
> expected, got the number 5.

Yes, because you did not calculate the above!  What you calculated* was :

1+2=3

3*3=9

9-4=5

Obviously this cannot be the same as 1+2*3-4.


     Thorsten


* Your calculator manual will of course explain this exactly the same way.
However, most newer caclulators (and many expensive older ones) support
calculations in mathematical order (or whatever this is called).

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Scott Hill
Subject: Re: unexpected rotation result
Date: 7 Feb 2001 10:20:51
Message: <3a8167d3@news.povray.org>
"Thorsten Froehlich" <tho### [at] trfde> wrote in message
news:3a815c85@news.povray.org...
> In article <3a80db3a$1@news.povray.org> , "Mark Wagner"
> <mar### [at] gtenet> wrote:
>
> > I just typed the expression 1+2*3-4 into my TI-1795 calculator, and, as
> > expected, got the number 5.
>
> Yes, because you did not calculate the above!  What you calculated* was :
>
> 1+2=3
>
> 3*3=9
>
> 9-4=5
>
> Obviously this cannot be the same as 1+2*3-4.
>
>


    Yeah, but the point is that 5 is just as valid a result as 3, for the
sum 1+2*3-4, if we ignore the 'accepted' operator precedence rules. We could
quite as easily have precedence rules that state that addition and
subtraction is done before multiplication and then everyone would be saying
"But it's not 3, it's -3!". Do you see ? All that makes 1+2*3-4 evaluate to
3, rather than -3, or 5, or -1 is an arbitrary rule about which order the
operations should be done in - change those rules and you change the
answer - but you don't change any fundamental aspect of mathematics.

    There are, unless I've missed some, 5 ways (if we ignore standard
operator order rules) to interpret '1+2*3-4' :

    (1+(2*(3-4))) = -1
    (1+((2*3)-4)) = 3
    ((1+(2*3))-4) = 3
    ((1+2)*(3-4)) = -3
    ((1+2)*3)-4) = 5

    These're all _mathematically_ correct statements, yet we only except one
to be the correct evaluation of '1+2*3-4'. This is not, as I've already
said, because any of the others are wrong, but merely because the statement
is ambiguous and we therefore need some way to de-ambiguate (choose) between
the possible interpretations.

--
Scott Hill.
NC Graphics (Cambridge) Ltd.
http://www.ncgraphics.co.uk

P.S. When will p.o-t be back ?


Post a reply to this message

From: Tom Melly
Subject: Re: unexpected rotation result
Date: 7 Feb 2001 10:42:55
Message: <3a816cff$1@news.povray.org>
"Scott Hill" <sco### [at] ncgraphicsnet> wrote in message
news:3a8167d3@news.povray.org...
>
> P.S. When will p.o-t be back ?
>

It is! (follow ups to ot.)


Post a reply to this message

From: Marc-Hendrik Bremer
Subject: Re: unexpected rotation result
Date: 7 Feb 2001 10:50:09
Message: <3a816eb1@news.povray.org>
Scott Hill schrieb in Nachricht <3a8167d3@news.povray.org>...

>    (1+(2*(3-4))) = -1
>    (1+((2*3)-4)) = 3
>    ((1+(2*3))-4) = 3
>    ((1+2)*(3-4)) = -3
>    ((1+2)*3)-4) = 5
>
>    These're all _mathematically_ correct statements, yet we only except
one
>to be the correct evaluation of '1+2*3-4'. This is not, as I've already
>said, because any of the others are wrong, but merely because the statement
>is ambiguous and we therefore need some way to de-ambiguate (choose)
between
>the possible interpretations.


They are not mathematically correct, because an improtant part of the
mathematical system are the precedence rules. They are in no way more
arbitrary than any other mathematical rule, 'cause mathematics is no science
but just a set of rules which have at first nothing to do with any real
thing in the world (although they prove to be of much help to understand
some things in real world). If you just cancel one of the rules you can as
easily give up the whole system - or at least you have to say what you are
doing. The mathematical system in whole is not ambiguos at all - cause there
are rules to tell you how everything interacts which each other.

>P.S. When will p.o-t be back ?
>

Well, it is back for more than a week now.


Marc-Hendrik


Post a reply to this message

From: Tom Melly
Subject: Re: unexpected rotation result
Date: 7 Feb 2001 11:14:51
Message: <3a81747b$1@news.povray.org>
"Marc-Hendrik Bremer" <Mar### [at] t-onlinede> wrote in message
news:3a816eb1@news.povray.org...
>
>
> They are not mathematically correct, because an improtant part of the
> mathematical system are the precedence rules. They are in no way more
> arbitrary than any other mathematical rule, 'cause mathematics is no
science

I disagree - for example I am not offended/shocked/suprised/whatever that
entering 2+3*5 in a calculator gives me 25 but gives me 17 in POV. However,
if a calculator or program ever told me that 3*5 was anything but 15, I
would ask for a refund.

IMHO you're missing the point. Precedence rules exist (once more with
feeling) because common-sense cannot resolve the issue.

Another English example - "rape" is both an act and a plant. If I say "there
is a lot of rape in Sussex" you have no way of knowing whether I mean the
plant or the act. The doubt can only be resolved by some extra words. For
example "there are many rape-plants in Sussex".

This is the linguistic equivalent of brackets in a function. For you to
argue that the meaning of * or + is just as arbitary as precedence is the
equivalent of me saying that "there is a lot of rape in Sussex" is as
ambivalent as "there is a lot of crime in Sussex" because, in some private
language of my own, "crime" also means "oxygen".

Yes, maths is arbitary, but so is English. Nevertheless "rape" is ambivalent
in a way that "crime" is not.


Post a reply to this message

From: Warp
Subject: Re: unexpected rotation result
Date: 7 Feb 2001 12:23:25
Message: <3a81848c@news.povray.org>
Tom Melly <tom### [at] tomandlucouk> wrote:
: I disagree - for example I am not offended/shocked/suprised/whatever that
: entering 2+3*5 in a calculator gives me 25

  If I enter that in my calculator it gives me 17.
  Why?

  There are two (main) types of calculators.
  Usually calculators only calculate one operation at a time. They do not
have memory for long expressions (some of these have indeed parentheses,
but still they work in the same way when parentheses are not used) and they
calculate every sub-expression right after it has been entered.
  What happens when you type "2+3*" (yes, I left the '5' intentionally out)
is the following: The calculator gets a '2', then a '+', then a '3'. Now
it expects either a number or another key (such as '=' or another operator).
When it gets something that is not numerical input it immediately calculates
the result of the current operation (as if '=' had been pressed) before
continuing.
  In fact, pressing any operator is like pressing '=' and that operator
(some very cheap calculators don't even have a '=' at all, but you have to
press some operator in order to get the result, such as '+'). Pressing the
operator is more like a shortcut for '=' and the operator itself.
  This is most probably done for simplicity. Usually these kind of calculators
are used for very simple tasks, like adding the prices of some products
together and so on. Modifying the behaviour of the operator keys to work
in another way would most probably just confuse people.
  When you type "2+4*5" you are, in fact, typing "2=+3=*5", although it's
kind of hidden.

  Now, the most advanced calculators (mainly graphical ones, like mine) allow
you to actually write long expressions (the whole expression is shown on
the screen of the calculator) and the result is calculated only when you
press '=' (or usually 'enter' in those calculators).
  These calculators also usually allow you to navigate through the expression
with cursor keys and make modifications to it.
  (The most advanced allow you to enter more complex mathematical operations
such as summation, derivative and integrals. Mine does; it even shows them
in the same way as I would write them on paper.)
  Since in these calculators you are actually calculating the result of the
whole expression, not just a sub-expression at a time, the result is the
mathematically expected one.

-- 
char*i="b[7FK@`3NB6>B:b3O6>:B:b3O6><`3:;8:6f733:>::b?7B>:>^B>C73;S1";
main(_,c,m){for(m=32;c=*i++-49;c&m?puts(""):m)for(_=(
c/4)&7;putchar(m),_--?m:(_=(1<<(c&3))-1,(m^=3)&3););}    /*- Warp -*/


Post a reply to this message

From: Peter Popov
Subject: Re: unexpected rotation result
Date: 7 Feb 2001 14:41:13
Message: <ae738t4t1vm66jo1sup9dgpbkvkim23ec3@4ax.com>
>E.g, what does 1+2*3-4 evaluate to ?

11123-4
12222223-4

and so on

Basically one or more 1's followed by zero or more 2's followed by
'3-4'

It basically depends on the input string you are matching against.


Peter Popov ICQ : 15002700
Personal e-mail : pet### [at] vipbg
TAG      e-mail : pet### [at] tagpovrayorg


Post a reply to this message

From: Tom Melly
Subject: Re: unexpected rotation result
Date: 7 Feb 2001 14:58:30
Message: <3a81a8e6@news.povray.org>
"Warp" <war### [at] tagpovrayorg> wrote in message
news:3a81848c@news.povray.org...
> Tom Melly <tom### [at] tomandlucouk> wrote:
> : I disagree - for example I am not offended/shocked/suprised/whatever
that
> : entering 2+3*5 in a calculator gives me 25
>
>   If I enter that in my calculator it gives me 17.
>   Why?
>

<SNIP>

Exactly - there is no wrong answer in the two answer, they are just using
two different conventions. However, to calculate the result on the basis
that "+" meant "/" would be silly.


Post a reply to this message

From: David Fontaine
Subject: Re: unexpected rotation result
Date: 7 Feb 2001 17:31:51
Message: <3A81CCBB.635F3E91@faricy.net>
Tom Melly wrote:

> (a*(x^2)) + (b*x) + c - but this is not common sense, it is following a
> convention that exists because common sense is not available.

I don't know, it seems sensible to me. Addition versus multiplication: to me,
multiplying implies part of the same thing, like  width and height of a
rectangle, whereas addition is the sum multiple things, ie multiple rectangles.
Think of the problem of surface area of a 3d solid. Hence multiplication
operations should be "groups" when figuring out the order of operations. It
gets progressively more obscure, but I think a similar arument can be made for
all precedences.

Besides from which, mathematics and programming require strict rules and some
degree of consistency by their very nature.

--
David Fontaine  <dav### [at] faricynet>  ICQ 55354965
My raytracing gallery:  http://davidf.faricy.net/


Post a reply to this message

From: David Fontaine
Subject: Re: unexpected rotation result
Date: 7 Feb 2001 17:49:10
Message: <3A81D0CA.309094A@faricy.net>
Tom Melly wrote:

> > NO!! 1+2*3-4 is three, only three, exactly three, no more, no less, and
> most
> > certainly not and NEVER five. If you meant (1+2)*3-4, that would be
> analagous to
> > me typing orange and meaning purple. Anyone who types 1+2*3-4 and expects
> 5 is
> > an idiot.
> >
>
> I disagree. Anyone who types 2*1.5 and expects 5 is an idiot. Typing 1+2*3-4
> and expecting 5 just means that they don't know the conventions. The
> conventions exist because intelligence alone cannot resolve the issue.

I still disagree. Mathematics REQUIRES conventionality. There can be NO
ambiguity in mathematics. It operates on the idea of proof through logic.

There are reasons for the order of operations. Every multiplication operation
takes parts of the same thing; length*width=area of *one* face on a cube, or
average_velocity*time=displacement. Addition and subtraction however take
multiples of something; you sum multiple faces to get the total surface area, et
al. Of course it is not always this simple, but that's why we use parentheses.
The parentheses show us clearly, visually and unambiguously that an operation is
being used as one piece in a larger operation.

If your calculator is giving you five it is merely a limitation of the
technology. The manual probably states clearly that five is techincally wrong,
and shows what the calculator is *really* doing. Any scientific calculator obeys
order of operations, and even the older ones will expect that you request the
result before the computation is complete. Instead the cheap calcs think you
want a result after every operation, then discard everything you typed in.


--
David Fontaine  <dav### [at] faricynet>  ICQ 55354965
My raytracing gallery:  http://davidf.faricy.net/


Post a reply to this message

From: Tom Melly
Subject: Re: unexpected rotation result
Date: 8 Feb 2001 04:36:14
Message: <3a82688e$1@news.povray.org>
"David Fontaine" <dav### [at] faricynet> wrote in message
news:3A81CCBB.635F3E91@faricy.net...

> Think of the problem of surface area of a 3d solid. Hence multiplication
> operations should be "groups" when figuring out the order of operations.
It
> gets progressively more obscure, but I think a similar arument can be made
for
> all precedences.

Well, yes, but obscure is the important point. Okay, you might be able to
make a clear arguement for * over + but what about - and + or / and * ?
There maybe an arguement, but it isn't a clear one. However, any arguement
that says 2*3 is not 6 is plainly batty.


Post a reply to this message

From: Geoff Wedig
Subject: Re: unexpected rotation result
Date: 8 Feb 2001 08:21:07
Message: <3a829d42@news.povray.org>
Tom Melly <tom### [at] tomandlucouk> wrote:

> "David Fontaine" <dav### [at] faricynet> wrote in message
> news:3A81CCBB.635F3E91@faricy.net...

>> Think of the problem of surface area of a 3d solid. Hence multiplication
>> operations should be "groups" when figuring out the order of operations.
> It
>> gets progressively more obscure, but I think a similar arument can be made
> for
>> all precedences.

> Well, yes, but obscure is the important point. Okay, you might be able to
> make a clear arguement for * over + but what about - and + or / and * ?
> There maybe an arguement, but it isn't a clear one. However, any arguement
> that says 2*3 is not 6 is plainly batty.

Actually, there are plenty of number systems where this is plainly *not*
true.  There are the simple systems where 6 is undefined (base 4, for
example, where 2+3 = 11, or the mod 5 number system, where 2*3 = 2) and then
there are more complex things, where the definitions which you use for the
multiplicative and additive operators get weird.  I can't give a good
example here, since A. It takes a lot of math, and B. It's been close to a
decade since I did discrete algebra.  How number systems behave is highly
dependant upon the assumptions you place upon them.

Now, if you're talking about the integer, rational, or real number lines,
then yes, 2*3 = 6.  However, those are not the only number system available
to us.  I use mod systems all the time in POV, for example.

Geoff


Post a reply to this message

From: Tom Melly
Subject: Re: unexpected rotation result
Date: 8 Feb 2001 09:11:22
Message: <3a82a90a$1@news.povray.org>
"Geoff Wedig" <wed### [at] darwinepbicwruedu> wrote in message
news:3a829d42@news.povray.org...
> Tom Melly <tom### [at] tomandlucouk> wrote:
> > There maybe an arguement, but it isn't a clear one. However, any
arguement
> > that says 2*3 is not 6 is plainly batty.
>
> Actually, there are plenty of number systems where this is plainly *not*
> true.  There are the simple systems where 6 is undefined (base 4, for
> example, where 2+3 = 11, or the mod 5 number system, where 2*3 = 2) and
then

Well, yes, obviously if you use any other system than decimal, then all bets
are off. However, even recognising the validity of some of the arguements
put forward, I still find it remarkably obtuse to argue that precedence is
no more arbitary than what 1+1 equals (base 3 upwards ;)


Post a reply to this message

From: Geoff Wedig
Subject: Re: unexpected rotation result
Date: 8 Feb 2001 09:22:54
Message: <3a82abbd@news.povray.org>
Tom Melly <tom### [at] tomandlucouk> wrote:

> "Geoff Wedig" <wed### [at] darwinepbicwruedu> wrote in message
> news:3a829d42@news.povray.org...
>> Tom Melly <tom### [at] tomandlucouk> wrote:
>> > There maybe an arguement, but it isn't a clear one. However, any
> arguement
>> > that says 2*3 is not 6 is plainly batty.
>>
>> Actually, there are plenty of number systems where this is plainly *not*
>> true.  There are the simple systems where 6 is undefined (base 4, for
>> example, where 2+3 = 11, or the mod 5 number system, where 2*3 = 2) and
> then

> Well, yes, obviously if you use any other system than decimal, then all bets
> are off. However, even recognising the validity of some of the arguements
> put forward, I still find it remarkably obtuse to argue that precedence is
> no more arbitary than what 1+1 equals (base 3 upwards ;)

Oh, yes.  Precedence is a convention, not a base assumption of mathematics. 
Precedence involves how systems of equations are written down, how they're
represented, not the equations themselves.  The equations are what's really
relevant, not their representation.  Representations have changed over the
years (the way Newton wrote out equations was *very* different from anything
we'd see today), but the math that was represented, that is what's
importatn, and that hasn't changed (well, been improved, modified, etc, but
nothing in it has become incorrect within its sphere)

Geoff


Post a reply to this message

From: Peter J  Holzer
Subject: Re: unexpected rotation result
Date: 9 Feb 2001 16:02:18
Message: <slrn988lhg.85s.hjp-usenet@teal.h.hjp.at>
On 2001-02-07 17:23, Warp <war### [at] tagpovrayorg> wrote:
>Tom Melly <tom### [at] tomandlucouk> wrote:
>: I disagree - for example I am not offended/shocked/suprised/whatever
>: that entering 2+3*5 in a calculator gives me 25
>
>  If I enter that in my calculator it gives me 17. Why?
>
>  There are two (main) types of calculators Usually calculators only  .
>  calculate one operation at a time                                   .

I would debate the "usually" here. Every calculator I have ever bought
(starting with that TI-33 over 20 years ago) knew about precedence
rules. The cheap thingies built into mouse mats and rulers probably
don't but they don't have parentheses either (for the same reason -
parentheses require a deeper stack).

An interesting variation are some printing desk calculators, which use
infix operators for multiplication and division and postfix for addition
and subtraction. So to compute 2*3 - 4*5 you would type
CLR 2 * 3 + 4 * 5 -

>  Now, the most advanced calculators (mainly graphical ones, like mine)
>allow you to actually write long expressions (the whole expression is
>shown on the screen of the calculator) and the result is calculated
>only when you press '=' (or usually 'enter' in those calculators).

The TI-33 didn't. It calculated each subexpression as soon as possible.
So if you type 2+3* it would notice that * has higher precedence than +
and throw 2+ on the stack. If you continued typing 5-, it would first
complete the multiplication (giving 15) and further check the stack
for pending operations. Since + has the same precedence as -, it would
perform the addition, too.

The stack had a limited depth (6 entries, I think), but I rarely
exceeded it. That wasn't a high-end calculator at that time, either, it
costed only a few hundred ATS - an HP-42 was about 10 or 20 times as
expensive, IIRC.

	hp

-- 
   _  | Peter J. Holzer    | All Linux applications run on Solaris,
|_|_) | Sysadmin WSR       | which is our implementation of Linux.
| |   | hjp### [at] wsracat      | 
__/   | http://www.hjp.at/ |	-- Scott McNealy, Dec. 2000


Post a reply to this message

From: David Fontaine
Subject: Re: unexpected rotation result
Date: 9 Feb 2001 17:56:29
Message: <3A84756F.7892F9E8@faricy.net>
Tom Melly wrote:

> Well, yes, but obscure is the important point. Okay, you might be able to
> make a clear arguement for * over + but what about - and + or / and * ?
> There maybe an arguement, but it isn't a clear one. However, any arguement
> that says 2*3 is not 6 is plainly batty.

- and + are the same operation. / and * are the same operation. Well, they're
inverse, but to be inverse they must use the same stuff (ya know, like to be
opposites words must describe the same thing--hot and cold). -x = +(-x) and /x =
*(1/x). It wouldn't make any sense to do multiplaction then subtraction then
division then addition, or something like that.

--
David Fontaine  <dav### [at] faricynet>  ICQ 55354965
My raytracing gallery:  http://davidf.faricy.net/


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.