Register to reply

How does one become proficient in programming?

by kingkong11
Tags: proficient, programming
Share this thread:
phinds
#19
Jul17-11, 06:31 AM
PF Gold
phinds's Avatar
P: 6,122
Quote Quote by Jocko Homo View Post
It doesn't matter whether you represent the number in decimal, hexadecimal or binary, a rational number is rational and an irrational number is irrational...
That is incorrect. Do the math.
rcgldr
#20
Jul17-11, 09:02 AM
HW Helper
P: 7,035
A bit off topic, maybe this should be split off into a separate thread.

Quote Quote by phinds View Post
For example, I'm always astounded by how many programmers do not instantly understand why the following is false ... 1.4 + 2.6 = 4.0
It's not false in languages like APL, which have a tolerance factor for comparasons.

Quote Quote by Jocko Homo View Post
It doesn't matter whether you represent the number in decimal, hexadecimal or binary, a rational number is rational and an irrational number is irrational...
Quote Quote by phinds View Post
That is incorrect. Do the math.
Am I missing something here, every rational number can be represented as the result of division of two finite sized integers regardless if the number is stored as decimal or binary (my calculator has a factional display option but the size of the integers is limited). An irrational or transcendental number can not be represented as the division of two finite sized integers. I don't see how a number is stored in a computer changes this.
phinds
#21
Jul17-11, 09:56 AM
PF Gold
phinds's Avatar
P: 6,122
Quote Quote by rcgldr View Post
Am I missing something here, every rational number can be represented as the result of division of two finite sized integers regardless if the number is stored as decimal or binary (my calculator has a factional display option but the size of the integers is limited). An irrational or transcendental number can not be represented as the division of two finite sized integers. I don't see how a number is stored in a computer changes this.
Hm ... you are correct in the definition of rational number of course and perhaps where I am being misled (or not, I haven't done math to follow through on this) is that I have taken it as being a number which, when that ratio is taken, results in either a terminating decimal number (at some point it just becomes all 0's on out) OR a number that at some point comes to a repeating pattern (that continues forever).

My belief, and I have not yet verified this, is that when you convert some numbers from decimal to binary and then do the division in binary, you do can get an infiinite non-repeating binary real number. I doesn't SOUND logical, now that I think about it and perhaps when I did 16/10 as 10000/1010 I didn't carry it out far enough (or it might have been 14/10 as 1110/1010, I can't remember whether both of them seemed irrational in binary or just one of them.

Guess I'm now going to have to do the math. GADS I HATE doing long division in binary, but in this case, I KNOW you can't get the computer to do it for you because it doesn't have enough bits, so it gets to a rounding error which is the point I was making in the post I referred to.


LATER: OK, I didn't go very far w/ the long division in binary (horrible stuff) but I'm convinced you are correct, as you logically MUST be. The problem of 1.4+2.6 not being equal to 4.0 in computers has nothing to do with the rationality of the number in one system or the other, it just has to do with the fact that when you do the division in binary you have to truncate before adding so you get a rounding error.

As I pointed out in the other thread, the decimal-based computer's equivalent of this is that 1/3 + 2/3 is not equal to 1.0 because when you put them into floating point representation you get (I'm going to assume a 10-digit memory) .3333333333 + .6666666666 which comes out to .9999999999 so the equality doesn't work.

Thanks for pointing out my mistake about the rationality.
martix
#22
Jul17-11, 01:54 PM
P: 128
Quote Quote by Wikipedia
Irrational numbers are precisely those real numbers that cannot be represented as terminating or repeating decimals.
There are a few important points here in the above.

Given that, I know for a fact that there are numbers which can be represented accurately in a finite string of digits in one number system, while requiring a representation with repeating digits in another. (I just can't think of any examples in binary right now)
phinds
#23
Jul17-11, 02:12 PM
PF Gold
phinds's Avatar
P: 6,122
Quote Quote by martix View Post
There are a few important points here in the above.

Given that, I know for a fact that there are numbers which can be represented accurately in a finite string of digits in one number system, while requiring a representation with repeating digits in another. (I just can't think of any examples in binary right now)
For sure one of the examples I gave (either 1.4 or 1.6) converts to binary with an infinitely repeating pattern (I've tossed my scratch notes and don't remember which it was ... might have been both).
rcgldr
#24
Jul17-11, 03:46 PM
HW Helper
P: 7,035
This is a niche part of programming, still thinking it belongs in another thread.

Quote Quote by phinds View Post
when you do the division in binary you have to truncate before adding so you get a rounding error.
Some environments will round instead of truncating to get more accurate results, when doing floating point math.

Quote Quote by phinds View Post
1/3 + 2/3 is not equal to 1.0 because when you put them into floating point representation you get (I'm going to assume a 10-digit memory) .3333333333 + .6666666666 which comes out to .9999999999 so the equality doesn't work.
Depends on the comparason "tolerance factor", and also some systems will convert 2/3 into .6666666667, since that is the more accurate answer.

There are numbers which can be represented accurately in a finite string of digits in one number system, while requiring a representation with repeating digits in another
Depends if the denominator has any prime factors that are not factors of the base number. 3 isn't a factor of either 2 or 10, so 1/3 in decimal = .33333333 and in hex = .55555555. 1/5 = .2 in decimal, but .33333333 in hex. 2 is a factor of 10, so fractions involving powers of 2 are finite (but possibly long) strings in decimal, such as 1/256 = 0.00390625 in decimal, and .01 in hex.
Jocko Homo
#25
Jul17-11, 10:28 PM
P: 133
Quote Quote by phinds View Post
Quote Quote by Jocko Homo View Post
It doesn't matter whether you represent the number in decimal, hexadecimal or binary, a rational number is rational and an irrational number is irrational...
That is incorrect. Do the math.
I would please like an honest answer to the following question: what makes you think that I haven't done "the math?"

The way you put this makes you sound like you're so sure of yourself, which is exacerbated by how wrong you are. Honestly, it's pretty insulting...
Jocko Homo
#26
Jul17-11, 10:40 PM
P: 133
Quote Quote by martix View Post
Quote Quote by Wikipedia
Irrational numbers are precisely those real numbers that cannot be represented as terminating or repeating decimals.
There are a few important points here in the above.

Given that, I know for a fact that there are numbers which can be represented accurately in a finite string of digits in one number system, while requiring a representation with repeating digits in another. (I just can't think of any examples in binary right now)
Two points:

First, please read your claim of knowledge above. Can you see how it's irrelevant? According to your quote, irrational numbers "cannot be represented as terminating or repeating decimals," emphasis being mine. While a number may be represented with a finite number of digits in one system and a repeating set of digits in another, this doesn't change whether that number is irrational or not...

Secondly, please take care to quote in context:
Quote Quote by Wikipedia
In mathematics, an irrational number is any real number which cannot be expressed as a fraction a/b, where a and b are integers, with b non-zero, and is therefore not a rational number. Informally, this means that an irrational number cannot be represented as a simple fraction. Irrational numbers are precisely those real numbers that cannot be represented as terminating or repeating decimals.
The emphasis is mine...

It seems to me that you're referring to an "informal" definition. While these informal descriptions can aid in understanding, I wouldn't rely on them as evidence as much as you do...
rcgldr
#27
Jul17-11, 11:42 PM
HW Helper
P: 7,035
Quote Quote by kingkong11 View Post
I agree with the comment that learning things at its most fundamental level is the way to start. However, the book I'm using for C doesn't have too much information about how computers actually store data (other than the fact they are stored in binary).
Trying to get back on topic here. For storing floating point numbers, most computers use IEEE format:

http://en.wikipedia.org/wiki/IEEE_754-2008

For most computers integers are stored as 32 bit or 64 bit signed binary numbers, although some computers support larger integers.

How the data is stored isn't that important for programming proficiency. There a lot of different types of programming, business, scientific, operating systems, data base, web site design, embedded code for peripherals or consumer devices that have computers in them, ... .

Many students and engineers find MatLab to be helpful, although it's more like a mathematical tool as opposed to a programming language. There's still a large amount of legacy like scientific code still being written in Fortran. C and C++ are popular for a lot of types of programming.

You didn't mention what aspect of programming you like. As mentioned in prevoius posts, most jobs involve specializing in one type of programming. The main issue for learning programming is finding a good set of tasks to implement for the learning experience. Even if you don't take a class, getting the assignments from a class to implement programs yourself can be useful, but you made need help if you run into issues. I'm not sure what book to recommend these days.
SixNein
#28
Jul18-11, 12:45 AM
PF Gold
SixNein's Avatar
P: 194
Quote Quote by phinds View Post
That is incorrect. Do the math.
No he's correct.

The mathematical reason floating point numbers behave as they do on computers has nothing to do with binary; instead, it is due to the inability of processors to work with fractions. So when you ask the computer to store 1/3, it does the calculation as 1 divided by 3 in decimal notation. So the computer winds up with .33333333-> and is truncated to a certain precision. If an operation such as 3 * (1/3) is performed, the computer takes .333333333 and times it by 3 to arrive at .9999999999. But its still a rational number because it repeats.

For example.... the .333333333 can be expressed as a fraction by taking 33 (the pattern) and dividing by 99. The .999999999 can be expressed as fraction with 99/99.

Irrational numbers, like PI, are always irrational. There are no patterns.


Register to reply

Related Discussions
Recommended programming language (and texts) for middle-school beginner programming Programming & Computer Science 9
Physics proficient? Academic Guidance 2
Doing OO programming the right way Programming & Computer Science 17
Programming a PIC Programming & Computer Science 21
Programming language to make a forum Computing & Technology 10