Complex numbers are tricky because: - They need to be fast in order to be useful for numerical computing. The "obvious" implementations that you might create with boxed values, vectors/maps, multimethods and protocols are likely to be unacceptable for many use cases - You still want to be able to use them in a generic way, with operations that play nicely with other values (Doubles etc.)
I have thought about this a lot w.r.t. core.matrix and have come to the conclusion that there is no simple, elegant answer that meets all use cases. What I'd like to suggest is: a) The community converge on a single, minimal, lightweight representation for a boxed complex scalar value. This is probably best as a Java class (for easy interop with Java libraries). I think http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/complex/Complex.html is a good candidate b) A lightweight wrapper library that provides nice complex functions in Clojure, using the above type. Nothing fancy. But can make extensive use of type hints etc. for performance so should be pretty fast c) A library using core.matrix that implements complex vectors, complex matrices etc but also uses a) for complex scalar values. This should use a underlying double-array backed implementation for performance, probably vectorz-clj would be best (though that could be hidden as an implementation detail). This library would also implement all the core.matrix protocols for the chosen complex number type, mostly just by calling b) directly On Monday, 27 April 2015 23:39:34 UTC+8, Nik wrote: > > I have been thinking along the lines of mikera and Maik - and it seems > like there is no further progress here? I would like to take a crack at > creating a complex number type, but implemented as a library to Clojure. I > am not sure where to start, and if anyone here has suggestions, I'd be > happy to hear them. > > A complex number could simply be a vector of two elements, or a map with > :real and :imag keys (or something lightweight) - and I am not sure what it > would require to make this type work happily with code arithmetic functions > in Clojure and Java Math. > > It would also have to work with seq operations in Clojure - for instance: > If I have a complex number c = {:real 3 :imag 4}, and a vector v = [1 -2 > c], it would be nice to have the call 'map #(Math/abs %) v' produce (1 2 > 5). > > I am having trouble figuring out all the pieces that need to be > implemented. Is it even possible to implement this as a library, or does > this need to be a part of clojure.core? > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.