Personally, I thinks it would be much more elegant to have a direct
notation. It could be argued that the Ratio type could also be
implemented without a special Ratio type, but where's the fun in that?
Consider:

(* 3.4+7i 15i)
  vs
(complex-multiply (construct-complex 3.4 7) (construct-complex 0 15))

It is a bit of effort and certainly non-trivial, but it's more of a
large hill to climb rather than a mountain. Again, this is for my
personal curiosity and may lead to nothing. Feel free to add
suggestion to an implementation! Already, I've added two things to my
implementation:

1.) using either i/I or j/J
2.) adding an "Imaginary" type for pure imaginary numbers ... as a
performance improvement.

Thanks all!

-Travis

On Jun 7, 10:32 am, Mark Engelberg <mark.engelb...@gmail.com> wrote:
> Yes, but in (some versions of) Scheme, (sqrt -1) yields i.
>
> Representing complex numbers and just doing math between two complex
> numbers is not the problem.  Retrofitting Clojure math so that all
> operations work on the entire numeric tower, allowing you to
> seamlessly manipulate complex and non-complex numbers together, is
> non-trivial.
>
> On Mon, Jun 7, 2010 at 12:09 AM, Steven Devijver
>
>
>
> <steven.devij...@gmail.com> wrote:
> > For what it's worth, I found that working with complex numbers in
> > clojure doesn't require specialist types or notation at all:
>
> > (defn complex-times [[a_re a_im] [b_re b_im]] [(- (* a_re b_re) (*
> > a_im b_im)) (+ (* a_re b_im) (* a_im b_re))])
> > (defn complex-plus  [[a_re a_im] [b_re b_im]] [(+ a_re b_re) (+ a_im
> > b_im)])
> > (defn complex-minus [[a_re a_im] [b_re b_im]] [(- a_re b_re) (- a_im
> > b_im)])
> > (defn complex-abs [[re im]] (Math/hypot re im))
>
> > (prn (complex-abs (complex-plus [1.5 1] (complex-times [1 -2] [2
> > -1]))))
>
> > --
> > 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 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

Reply via email to