[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [seul-edu] Programming Mathematics



On Mon, Sep 25, 2000 at 07:34:26AM -0700, lp wrote:
> What I want are some super simple programs, that have something   
> to do with math, for the programming languages that are freely
> available with Linux. I thought I would put together a dozen or so
> simple programs - and I mean REALLY simple - that have 
> something to do with math, and show what the syntax would be
> for all of the different languages, how to compile them
> (if necessary), and how to run them.
 
I'm a little bit confused about what you mean by this. Based on some of
the programs below, doing them well requires rather more than 2-10 lines
of code. I guess the problem lies in the fact that you have underspecified
certain aspects of the problem; in particular, "a program that factors
a number": what is "a number"?  Are you assuming it's 32 bits? Do you
want to do it quickly, or just show "a way" and put a disclaimer on the
side that says "this has nothing to do with real problems"?

Part of math is algorithms -- learning how to do things efficiently.
For instance, you're going to want a good number sieve system if you're
generating primes after a certain point, or if you're trying to factor
something tough (they're very related problems).

If you want to handle arbitrary numbers, you'll want to use gmp (gnu
multiprecision library), and you'll start running into problems like
"perl can handle arbitrary precision numbers, except in the cases where
it silently rounds them off and doesn't tell you" and similar issues.
It will get complex quickly.

Of course, some of your examples are much easier to program than the
arbitrary factoring problem.

> For example, to factor a number
> 
> Just type
>                 
>         factor 33333,
>                    
> (oh, and don't forget to press enter.)
 
The sh-utils rpm includes a program called 'factor' (with c code) that
does this. wc -l puts it at 207 lines, but many of those are license and
comments (good things, imo). a program called 'primes' is also running
around somewhere; it was standard in redhat 4.2, I think it's been taken
out of 6.x for some reason. It's probably still in debian.
                 
> If you have any super simple starter things like this, 
> or know where it exists on the web, let me know. 
> I'll do a lot of it myself, but the less time it takes
> the better.

Google seems to turn up some large math collections, but none of them
looks quite perfect. You should spend some time hunting before you
duplicate work. Because while you can whip out some 10 line programs to
do things, they won't necessarily be the best teaching tools.

--Roger