caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] complex numbers
@ 2004-02-27  6:04 Alexander Danilov
  2004-02-27 13:18 ` Andrew Lenharth
       [not found] ` <20040227131719.GA827@peuter>
  0 siblings, 2 replies; 7+ messages in thread
From: Alexander Danilov @ 2004-02-27  6:04 UTC (permalink / raw)
  To: caml-list

Please, show me an example how to work with complex numbers in Ocaml.
I mean, how to create complex number, how to perform orepations (+ - * 
/) with complex numbers.
Thanx.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 7+ messages in thread
* [Caml-list] Complex Numbers
@ 2003-04-09 10:59 David Gray
  2003-04-09 11:53 ` sebastien FURIC
  0 siblings, 1 reply; 7+ messages in thread
From: David Gray @ 2003-04-09 10:59 UTC (permalink / raw)
  To: caml-list

Does anyone have trouble with 3.06 version for windows using the following:

#open Complex;;
#let y = {re = -1.; im = 0.};;
#let ans = sqrt y;;
Reference to undefined global `Complex'

the above seems to work under Red Hat.

Dave

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 7+ messages in thread
* [Caml-list] Complex Numbers
@ 2001-03-28  2:19 David McClain
  0 siblings, 0 replies; 7+ messages in thread
From: David McClain @ 2001-03-28  2:19 UTC (permalink / raw)
  To: caml-list

"One of the articles by William Kahan (www.cs.berkeley.edu/~wkahan/)
"How JAVA's Floating-Point Hurts Everyone Everywhere" discusses
(among other things) some traps in complex number implementations,
including those in Fortran.
"

My NML, written in OCaml, paid particular attention to these issues after I
read everything I could from Kahan. To my knowledge, aside from Common Lisp
(perhaps), it is the only proper implementation of complex arithmetic
available.

In particular, Kahan's demo of "Borda's Pipe", shows that stream lines are
incorrectly computed in every language I have tried: Mathematica, RSI/IDL,
Fortran, C/C++, Basic, with the possible exception of Common Lisp. Only NML
has passed demonstrably passed this test.

The difficulty stems from the fact that, to paraphrase Kahan, "a tuple
representation of complex numbers is insufficient, given the Riemann
surfaces of common transcendental functions". There are two zeros defined in
the IEEE Floating Point Standard: 0+, and 0-.  Arithmetic in the floating
point domain do not obey classical algrebraic relations with respect to
conventional identity elements.

I sweated out two solid weeks in gaining a full understanding of his rather
cryptic statement. NML represents my final victory over this issue and I can
thank OCaml and the INRIA team for their wonderful implementation language
that made it all so readily possible.

- DM


Borda NML code follows:

--------------------------------------------------
(* borda.nml -- test of complex arithmetic in NML *)
(* DM/MCFA  09/99 *)

let g z = z^2 + z*sqrt(z^2+1)
let f z = 1 + g(z) + log(g z)

let ls =
  let ptor r theta =
    complex (r*cos theta) (r*sin theta)
  in
  let t = tan(pi/2*[0, 0.001, .. 1]) in
    map (fun ang ->
    ptor t ang)
      (lis (pi * [-0.5, -0.45, .. 0.5]))

let rec pshow (l, ... as args) =
  let clip x =
    x #< 400 #> -400
  in
  let z = f(l) in
    oplot(clip(re z), clip(im z) | args @ [clip: true])

let borda() =
  let s = 5 in
    axes(xrange: [-s,s], yrange: [-s,s],
 title: "The Correct Borda!");
    pshow(hd ls, color: red, thick: 2);
    app pshow (tl ls)

let _ = borda()



-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-02-27 16:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-27  6:04 [Caml-list] complex numbers Alexander Danilov
2004-02-27 13:18 ` Andrew Lenharth
2004-02-27 16:36   ` Christophe TROESTLER
     [not found] ` <20040227131719.GA827@peuter>
     [not found]   ` <403F5ABD.1090402@fssg.st-oskol.ru>
2004-02-27 15:36     ` Andrew Lenharth
  -- strict thread matches above, loose matches on Subject: below --
2003-04-09 10:59 [Caml-list] Complex Numbers David Gray
2003-04-09 11:53 ` sebastien FURIC
2001-03-28  2:19 David McClain

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