From: Michael Hohn <hohn@math.utah.edu>
To: semenova@snob.spb.ru
Cc: caml-list@inria.fr
Subject: Re: Is Caml a suitable tool for complicated mathematical methods.
Date: Fri, 22 Dec 2000 11:34:47 -0700 (MST) [thread overview]
Message-ID: <200012221834.LAA24027@suntan.math.utah.edu> (raw)
In-Reply-To: <00122200235700.00634@snob.spb.ru> (message from Semenova Natalya Nickolaevna on Thu, 21 Dec 2000 23:39:37 +0300)
We are going to rewrite a large bundle of Fortran-3 (!!!) sources to some
"better" language. Sources are the solution of the system of differential
equations in partial derivatives by normal finite differencing methods.
Two candidats are voted: Pascal and Ocaml. Is Caml convenient tool for such
tasks?
Definitely. I finished an implementation of a linear elliptic pde
solver using sinc methods** last summer, and ocaml made this a
*very* pleasant experience. To me, the biggest advantages over most
other languages, especially Pascal, FORTRASH (no typo there) and C
are:
o functional programming
A programming style much better suited for numerical math than
imperative ever was.
Closures alone reduce programming effort tremendously, and yield
very clean code. Just try translating the following piece to Pascal
or C:
let make_phi a b =
fun x -> (log ((x-. a)/. (b-. x)));;
>> val make_phi : float -> float -> float -> float = <fun>
let phis = [| make_phi 0.0 1.0; make_phi 2.1 3.2 |];;
>> val phis : (float -> float) array = [|<fun>; <fun>|]
phis.(0) 0.1;;
>> - : float = -2.19722457734
phis.(1) 3.1;;
>> - : float = 2.30258509299
The stuff following >> is the toplevel's output.
o interactive toplevel
The ability to test individual functions without the lengthy
write-compile-run cycle is hard to do without.
o type inference
As the small sample above shows, type declarations are not usually
needed. This means *much* shorter code when writing smaller
functions.
o data serialization
The ability to produce *portable* binary data files from *arbitrary*
data structures (as long as they contain no closures or objects)
with a single function call is priceless.
With this, I was able to run a large problem at the university on a
Sun Ultrasparc with 2GB of memory, save the results, transfer the
binary file, and work with that file at home using a Pentium II
running Linux. All by writing about 20 lines of extra code!
o defineable operators
For example, ocaml does not have complex number support built-in.
No problem. After defining some basic complex functionality, the
following works by defining the *: operator:
# #load "cmplx.cmo";;
# open Cmplx;;
# (cx 1.0 1.0) *: (cx (-2.0) 1.1);;
- : Cmplx.cmplx = {re=-3.1; im=-0.9}
# zexp (cx 3.5 27.1);;
- : Cmplx.cmplx = {re=-12.7877837182; im=30.5467796339}
There are many other advantages, too tedious to describe. At least
the following are worth mentioning:
o garbage collection
o polymorphism
o strong static typing
o module support
I hope this very brief summary helps.
Happy programming,
Michael
P.S. Is anybody interested in using/extending the complex number code?
** Based on many papers and the book
@Book{stenger,
author = "Stenger, Frank",
title = "Numerical Methods Based on Sinc and Analytic Functions",
publisher = "Springer-Verlag",
year = "1993"
}
next prev parent reply other threads:[~2000-12-25 21:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-12-21 20:39 Semenova Natalya Nickolaevna
2000-12-22 16:43 ` Brian Rogoff
2000-12-22 18:34 ` Michael Hohn [this message]
2000-12-27 2:39 ` Vitaly Lugovsky
2000-12-22 21:49 Daniel Ortmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200012221834.LAA24027@suntan.math.utah.edu \
--to=hohn@math.utah.edu \
--cc=caml-list@inria.fr \
--cc=semenova@snob.spb.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).