caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [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

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



David Gray a écrit :
> 
> 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

 Hi,

 I've already submitted a bug report for that (id = 1349).
 It will be fixed in the next version.
 Recompiling the Complex module with the bytecode compiler may help:
 ocamlc -c complex.mli complex.ml
 ocaml
        Objective Caml version 3.06

# #load "complex.cmo";;
# open Complex;;
# sqrt;;
- : Complex.t -> Complex.t = <fun>
#

 Cheers,

 Sébastien.

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

* Re: [Caml-list] complex numbers
  2004-02-27 13:18 ` Andrew Lenharth
@ 2004-02-27 16:36   ` Christophe TROESTLER
  0 siblings, 0 replies; 7+ messages in thread
From: Christophe TROESTLER @ 2004-02-27 16:36 UTC (permalink / raw)
  To: alenhart; +Cc: caml-list

On Fri, 27 Feb 2004, Andrew Lenharth <alenhart@cs.ohiou.edu> wrote:
> 
> let y = mul x {re = -1.0; im = -1.0};;

To ease the notations, you can also define infix operators for complex
functions.  E.g. for the above:

let ( *: ) = mul;;
let y = x *: {re = -1.0; im = -1.0};;

ChriS

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

* Re: [Caml-list] complex numbers
       [not found]   ` <403F5ABD.1090402@fssg.st-oskol.ru>
@ 2004-02-27 15:36     ` Andrew Lenharth
  0 siblings, 0 replies; 7+ messages in thread
From: Andrew Lenharth @ 2004-02-27 15:36 UTC (permalink / raw)
  To: Alexander Danilov; +Cc: caml-list

Not that I know of, though you can define them yourself.

# let (+..) x y = add x y;;
val ( +.. ) : Complex.t -> Complex.t -> Complex.t = <fun>
# {re = 1.0; im = 1.0} +.. {re = 1.0; im = 1.0};;
- : Complex.t = {re = 2.; im = 2.}

Andrew Lenharth

On Fri, Feb 27, 2004 at 05:57:01PM +0300, Alexander Danilov wrote:
> Andrew Lenharth wrote:
> 
> >open Complex;;
> >
> >let x = {re = 1.0; im = 1.0};;
> >
> >let y = mul x {re = -1.0; im = -1.0};;
> >
> >let z = norm2 y;;
> >
> >let a = norm x;;
> >
> >The rest of the functions are in the standard library Complex module
> >documentation.  This should be enough to get you started.
> >
> >Andrew Lenharth
> >
> >On Fri, Feb 27, 2004 at 09:04:01AM +0300, Alexander Danilov wrote:
> > 
> >
> >>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.
> >>
> >>   
> >>
> >
> Thank you.
> But what about infix operations for Complex numbers, I mean something 
> like +.,-., /., ... exists for float
> numbers, any such operations defined  for complex number?
> 

-- 
"It will work in practice, yes. But will it work in theory?"
--- a french diplomat's comment, recalled by Madeleine  Albright

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

* Re: [Caml-list] complex numbers
  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>
  1 sibling, 1 reply; 7+ messages in thread
From: Andrew Lenharth @ 2004-02-27 13:18 UTC (permalink / raw)
  To: caml-list

open Complex;;

let x = {re = 1.0; im = 1.0};;

let y = mul x {re = -1.0; im = -1.0};;

let z = norm2 y;;

let a = norm x;;

The rest of the functions are in the standard library Complex module
documentation.  This should be enough to get you started.

Andrew Lenharth

On Fri, Feb 27, 2004 at 09:04:01AM +0300, Alexander Danilov wrote:
> 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

-- 
"It will work in practice, yes. But will it work in theory?"
--- a french diplomat's comment, recalled by Madeleine  Albright

-------------------
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
@ 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
@ 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 --
2003-04-09 10:59 [Caml-list] Complex Numbers David Gray
2003-04-09 11:53 ` sebastien FURIC
  -- strict thread matches above, loose matches on Subject: below --
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
2001-03-28  2:19 [Caml-list] Complex Numbers 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).