Math programming with C

@

@(none)

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
 
G

Gregory Toomey

none said:
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
 
W

websnarf

@(none) said:
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.
 
O

Old Wolf

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.
 
B

beliavsky

(e-mail address removed) wrote:

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.)


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.
 
W

websnarf

These seem like overly strong statements. Googling "arbitrary
precision arithmetic C" produces many hits -- can't one use one
of these packages?

Actually, most of them are not thread safe, or require memory usage
"hand holding" (you predeclare the number of digits your are going to
use for any value, etc). I've actually been developing my own
arbitrary precision library because of this. (Given the challenges, I
can see *why* other big integer libraries were designed the way they
were, but it still seems like the wrong trade off to me.)
[...] 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.

Indeed, most practical *programming* problems will hardly ever need
more than 8 bytes for an integer, however the OP was asking about doing
*math* problems (which, admittedly is very open ended, but can easily
require things, basically, a *LOT* more precise of a model for
integers). ABI's are also a practical way of escaping the problems I
cited about C's bizarre challenges with doing ordinary math -- where
other programming languages have also fall into similar traps, ABIs
avoid all of them.
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.

Ok, but that assumes one has a C99 compiler available right? Also
numerical computation (basically matrixes, or numerical methods like
Monte Carlo or Newton's Method) is not the same as "mathematical"
computation (crypto, finite fields, symbolic, graph theory, group
theory, etc).
 
W

websnarf

These seem like overly strong statements. Googling "arbitrary
precision arithmetic C" produces many hits -- can't one use one
of these packages?

Actually, most of them are not thread safe, or require memory usage
"hand holding" (you predeclare the number of digits your are going to
use for any value, etc). I've actually been developing my own
arbitrary precision library because of this. (Given the challenges, I
can see *why* other big integer libraries were designed the way they
were, but it still seems like the wrong trade off to me.)
[...] 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.

Indeed, most practical *programming* problems will hardly ever need
more than 8 bytes for an integer, however the OP was asking about doing
*math* problems (which, admittedly is very open ended, but can easily
require things, basically, a *LOT* more precise of a model for
integers). ABI's are also a practical way of escaping the problems I
cited about C's bizarre challenges with doing ordinary math -- where
other programming languages have also fall into similar traps, ABIs
avoid all of them.
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.

Ok, but that assumes one has a C99 compiler available right? Also
numerical computation (basically matrixes, or numerical methods like
Monte Carlo or Newton's Method) is not the same as "mathematical"
computation (crypto, finite fields, symbolic, graph theory, group
theory, etc).
 
R

Richard Bos

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.

Richard
 
C

CBFalconer

Richard said:
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. I had the unmitigated
gall to criticize the unnecessary non-portability of his code a
while ago, and the reaction mounted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,427
Latest member
HildredDic

Latest Threads

Top