Boolean logic conundrum

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Boolean logic conundrum

Postby purplepenguin » Tue Dec 04, 2012 5:11 pm

Hi, I wonder if someone would be so kind as to help me out?

I'm writing a Sense program for my HND at the OU and I'm not sure if I'm being stupid or whether I've spotted a typo. I wanted to check with people in the know before I email my tutor.

The task tells me:

Place the sprite at x:0 and y:170
So long as the y position of sprite is greater than or equals to -175 it should move down the stage in 1 step intervals.

To my mind if the sprite's y position is equal to -175 it should continue to move and end up at -176.

Later on i am told that the sprite should not exceed -175

How can the sprite be equal to -175 and still move 1 place down but not exceed -175.

Thank you for your patience
purplepenguin
LXF regular
 
Posts: 130
Joined: Wed Oct 05, 2011 2:19 pm
Location: Blissfully at the Command Line

Postby greg.d » Tue Dec 04, 2012 8:48 pm

So -175 is the lowest value? I dont know what they mean by move down the stage? Maybe that means the X axis?
So do they mean move X by 1, and Y by -1 each time until Y=-175?
greg.d
 
Posts: 24
Joined: Thu Oct 27, 2005 8:29 am

Postby guy » Tue Dec 04, 2012 9:05 pm

You are right, the logic is faulty. Worse, it is ambiguous and both interpretations are still faulty!

If it moves when Y is "greater than or equal to" -175 then it should move until eventually Y becomes less than -175, i.e. -176. Then it should stop.

"The sprite should not exceed -175" is unclear, since "exceed" is not mathematically defined. However, both possible meanings are wrong.
If "exceed" means "greater than" as in 170 exceeds -175, then that would lead to an incorrect statement, since the starting point well exceeds the stated limit.
If "exceed" means "have greater magnitude than" as in -175 has greater magnitude than 170, then that would also be incorrect, since as we have seen the sprite must pass through -175 and stop at -176.

However, the faulty logic is not Boolean, it is arithmetical.
Cheers,
Guy
The eternal help vampire
User avatar
guy
LXF regular
 
Posts: 1078
Joined: Thu Apr 07, 2005 12:07 pm
Location: Worcestershire

Postby Dutch_Master » Wed Dec 05, 2012 2:25 am

FYI: this is not Boolean, it's maths :P
Dutch_Master
LXF regular
 
Posts: 2445
Joined: Tue Mar 27, 2007 1:49 am

Postby purplepenguin » Wed Dec 05, 2012 7:11 pm

Hi Guy

Thank you for your explanation, just as I thought although I was starting to doubt myself and wonder if I was missing something obvious.

I was getting all wrapped up with Boolean logic as we have just covered <, >, =, and, or and not operators the OU explained these as Boolean Logic operators. I now see the error is a mathematical one.

I have sent an email to my tutor. I am now wondering if maybe it was intentional to see if we are paying attention.

Thank you once again.
purplepenguin
LXF regular
 
Posts: 130
Joined: Wed Oct 05, 2011 2:19 pm
Location: Blissfully at the Command Line

Postby guy » Wed Dec 05, 2012 7:58 pm

Well, < and > are not usually regarded as Boolean operators - especially on a beginners' course. AND, OR, NOT and so on are the usual suspects.

However I seem to recall that some Boolean algebras incorporate them as well. I suppose that = is trivially Boolean.

@Dutch_Master, Is logic a branch of maths or is maths a branch of logic? The answer of course depends on whether you ask a logician or a mathematician. :P
Cheers,
Guy
The eternal help vampire
User avatar
guy
LXF regular
 
Posts: 1078
Joined: Thu Apr 07, 2005 12:07 pm
Location: Worcestershire

Postby AndyBaxman » Mon Dec 10, 2012 1:02 pm

purplepenguin wrote:I was getting all wrapped up with Boolean logic as we have just covered <, >, =, and, or and not operators the OU explained these as Boolean Logic operators. I now see the error is a mathematical one.


Comparison operators (==, >, <, <=, >=, ===, etc, depending on language) are not boolean operators as they can take non boolean operands, but they do always return a boolean result.

Only the equality operator makes any sense with Boolean operands, and then only if you are comparing two boolean variables (i.e. not literals). (boolvar1 == boolvar2) will return true if, and only if, both variables are true or both variables are false (i.e. the same)

Cases like (boolvar1 == true) are nonsensical as
IF boolvar1 == 1 THEN .....

is equivalent to

IF boolvar1 THEN .....
Bomb #20: "Let there be light"
User avatar
AndyBaxman
LXF regular
 
Posts: 523
Joined: Tue Oct 04, 2005 8:47 am


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron