By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

Math programming with C

P: n/a
Hi, I need to learn the necessary and sufficient C programming knowledge
in order to be able to implement number theory and graph theory
algorithms (as RSA or Dijkstra algorithms). No system programming no
network programming nor graphic programming.

Any advice ? Any link to a non verbose reference ?

Thanks in advance,
La Tortue
Nov 14 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
none wrote:
Hi, I need to learn the necessary and sufficient C programming knowledge
in order to be able to implement number theory and graph theory
algorithms (as RSA RSA is cryptography, not graph theory
or Dijkstra algorithms). No system programming no
network programming nor graphic programming.

Any advice ? Any link to a non verbose reference ?

Thanks in advance,
La Tortue


Start with http://nr.com/ or http://directory.fsf.org/libs/GNUsl.html

gtoomey
Nov 14 '05 #2

P: n/a
Gregory Toomey a écrit :
none wrote:

Hi, I need to learn the necessary and sufficient C programming knowledge
in order to be able to implement number theory and graph theory ~~~~~~~~~~~~
algorithms (as RSA
RSA is cryptography, not graph theory


Sure. RSA is basically number theory stuff.

or Dijkstra algorithms). No system programming no
network programming nor graphic programming.

Any advice ? Any link to a non verbose reference ?

Thanks in advance,
La Tortue

Start with http://nr.com/ or http://directory.fsf.org/libs/GNUsl.html


Thanks, interesting links (although not exactly for _learning_ C
programming language for math).

La tortue

Nov 14 '05 #3

P: n/a
@(none) wrote:
Hi, I need to learn the necessary and sufficient C programming
knowledge in order to be able to implement number theory and
graph theory algorithms (as RSA or Dijkstra algorithms). No
system programming no network programming nor graphic
programming.
C is not a precise language, which makes it very hard to do hardcore
mathematics in it. Its possible, but you basically have to compromise
either on portability or speed, unless you are willing to really become
expert on the language.

Just learning how C deals with integers should give you reason to
reconsider using it as a language for this kind of thing. To get some
sort of sanity out of the language you have put letters like "U" or "L"
at the end of all your inline declared numbers. I would recommend
testing on no less than 7 compilers all with maximum warning settings
and using lint if you plan on having any degree of portability.

But, no compiler or lint-like utility that I am aware of can actually
assist programmers with any kind of numerical determinism. You are
basically forced to become an expert at the language which may take
many weeks or months (Python can be learned in a few hours and doesn't
have these problems).

Here are some examples:

int a, b;
unsigned int c, d;
...
if (a < 0) a = -a;
return sqrt (a); /* Undefined result. */

b = a >> 24; /* A completely meaningless operation */

if ((a % c) == (b % c))
/* a and b having the same residue mod c is insufficient
to make this condition true */

d = (a - b) % c;
/* d is zero when a and b are equal mod c, but otherwise
will not necessarily be equal to the correct residue
mod c */

And just to annoy mathematicians, C uses "*" for two different
operations as well as part of the comment brackets (and uses "/" for
comment brackets as well).

C is just a rotten language for doing real mathematics. Most of these
problems go away in other languages -- especially those that support
arbitrary precision integers (like Java, Python, etc.)
Any advice ? Any link to a non verbose reference ?


Yeah, pick a different language.

---
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/

Nov 14 '05 #4

P: n/a
we******@gmail.com wrote:
@(none) wrote:
Hi, I need to learn the necessary and sufficient C programming
knowledge in order to be able to implement number theory and
graph theory algorithms (as RSA or Dijkstra algorithms). No
system programming no network programming nor graphic
programming.
C is not a precise language, which makes it very hard to do
hardcore mathematics in it. Its possible, but you basically
have to compromise either on portability or speed, unless you
are willing to really become expert on the language.


Your trolling has been getting more and more pronounced over
the last few months.
Just learning how C deals with integers should give you
reason to reconsider using it as a language for this kind of
thing. To get some sort of sanity out of the language you
have put letters like "U" or "L" at the end of all your
inline declared numbers. I would recommend testing on no
less than 7 compilers all with maximum warning settings and
using lint if you plan on having any degree of portability.
Ok, it's now clear that you have trouble with C .. that doesn't
mean you should tell everyone else on comp.lang.c to avoid it.
C is just a rotten language for doing real mathematics. Most
of these problems go away in other languages -- especially
those that support arbitrary precision integers (like Java,
Python, etc.)


C supports arbitrary precision integers (for example, the GMP
library).

You could have said something like 'Mathematics takes less coding
time in a higher-level language', instead of that rant.

Nov 14 '05 #5

P: n/a
we******@gmail.com wrote:

<snip>
C is just a rotten language for doing real mathematics. Most of these problems go away in other languages -- especially those that support
arbitrary precision integers (like Java, Python, etc.)
Any advice ? Any link to a non verbose reference ?


Yeah, pick a different language.


These seem like overly strong statements. Googling "arbitrary precision
arithmetic C" produces many hits -- can't one use one of these
packages? I think many Fortran and C compilers support both 8 and 4
byte integers nowadays, whereas Python uses either 4 byte or arbitrary
precision integers (ABI). ABI's are much slower to work with than 8
byte integers, which may be all that is needed for a particular
calculation.

C99 (the latest C standard) has added many features for numerical
computation. One of the few books covering C99 is "C Primer Plus", 4th
Edition, by Stephen Prata.

Nov 14 '05 #6

P: n/a
CBFalconer <cb********@yahoo.com> wrote:
Richard Bos wrote:
we******@gmail.com wrote:
C is not a precise language, which makes it very hard to do
hardcore mathematics in it.


As usual, Paul Hsieh is talking complete bollocks. If you know
your C and take just a little care, it's quite possible to do
maths in C, and number and graph theory are not even the hardest.
Of course, this does require that you are willing to learn the
language properly, which Paul has never been.


Oh my - prepare for a flood of invective.


Feh. I only care about invective if it comes from people I take
seriously.

Richard
Nov 14 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.