Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > complex numbers

Reply
Thread Tools

complex numbers

 
 
xah@xahlee.org
Guest
Posts: n/a
 
      01-09-2005
#python supports complex numbers.
# append a "j" to a number and it represents the imaginary number. e.g.
# 3j means 3*i.
#(3,4) can be written as 3+4j
#another way to write is is
#complex(3,4)
#arithmetic operations can be applied normally.
# to get the real part, imaginary part, or length, one can do
a=complex(3,4)
print a.real
print a.imag
print abs(a)
print complex(3,4)+5+6j

----------------

# Perl doesn't support complex numbers. But there are packages that
supports it.
Xah
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://xahlee.org/PageTwo_dir/more.html

 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      01-09-2005
(E-Mail Removed) wrote:
> #python supports complex numbers.

[...]

So?

> # Perl doesn't support complex numbers. But there are packages that
> supports it.


The Math::Complex module is part of the standard installation already, no
need for any "packages" (whatever that might be).
Did you check "perldoc Math::Complex"

NAME
Math::Complex - complex numbers and associated mathematical functions
[...]

jue


 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      01-09-2005
(E-Mail Removed) <(E-Mail Removed)> wrote:

> #python supports complex numbers.


> # Perl doesn't support complex numbers.



Then you should use Python and stop Perl programming immediately!


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Alfred Z. Newmane
Guest
Posts: n/a
 
      01-10-2005
J|rgen Exner wrote:
> (E-Mail Removed) wrote:
>> #python supports complex numbers.

> [...]
>
> So?
>
>> # Perl doesn't support complex numbers. But there are packages that
>> supports it.

>
> The Math::Complex module is part of the standard installation
> already, no need for any "packages" (whatever that might be).


'package' is a keyword, you should know this Thats an important part
of most modules.

Actually it seems a lot of people use 'module' and 'package'
interchangably, both refering to libraries, if you will, the one can
include in a script, or another package.


 
Reply With Quote
 
It's me
Guest
Posts: n/a
 
      01-11-2005
For those of us that works with complex numbers, having complex number as a
natively supported data type is a big advantage. Non-native add-ons are not
sufficient and lead to very awkward program code.


"Jürgen Exner" <(E-Mail Removed)> wrote in message
news:Fm6Ed.3556$u47.321@trnddc09...
> (E-Mail Removed) wrote:
> > #python supports complex numbers.

> [...]
>
> So?
>


The world would come to a halt if all of a sudden nobody understands complex
numbers anymore.

> > # Perl doesn't support complex numbers. But there are packages that
> > supports it.

>
> The Math::Complex module is part of the standard installation already, no
> need for any "packages" (whatever that might be).
> Did you check "perldoc Math::Complex"
>
> NAME
> Math::Complex - complex numbers and associated mathematical functions
> [...]
>
> jue
>
>



 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      01-11-2005
It's me <(E-Mail Removed)> wrote in comp.lang.perl.misc:

[reply moved to bottom into context]

> "Jürgen Exner" <(E-Mail Removed)> wrote in message
> news:Fm6Ed.3556$u47.321@trnddc09...
> > (E-Mail Removed) wrote:
> > > #python supports complex numbers.

> > [...]
> >
> > So?
> >

>
> The world would come to a halt if all of a sudden nobody understands complex
> numbers anymore.
>
> > > # Perl doesn't support complex numbers. But there are packages that
> > > supports it.

> >
> > The Math::Complex module is part of the standard installation already, no
> > need for any "packages" (whatever that might be).
> > Did you check "perldoc Math::Complex"
> >
> > NAME
> > Math::Complex - complex numbers and associated mathematical functions
> > [...]


> For those of us that works with complex numbers, having complex number as a
> natively supported data type is a big advantage. Non-native add-ons are not
> sufficient and lead to very awkward program code.


Like this?

use Math::Complex;

my $z = sqrt( -1);
print 1 + $z, "\n"; # prints "1+i"

Operator overloading makes it possible to work with complex numbers as if
they were a native data type.

Anno

 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      01-11-2005
It's me <(E-Mail Removed)> wrote in comp.lang.perl.misc:

[reply moved into context]

> "Anno Siegel" <(E-Mail Removed)-berlin.de> wrote in message
> news:cs145l$8d6
>
> <snip>
>
> >
> > Like this?
> >
> > use Math::Complex;
> >
> > my $z = sqrt( -1);
> > print 1 + $z, "\n"; # prints "1+i"
> >
> > Operator overloading makes it possible to work with complex numbers as if
> > they were a native data type.


> Operator overloading (and function overloading) helps but not enough. You
> have to be aware of the complex type *everywhere* you go and that's very
> annoying and error prone. I've been the works with C++, and later with
> Modelica. I am very happy that Python included *native* complex number
> support.


What kind of awareness do you mean?

There are some operations (as comparison) that work for reals, but not
for complex numbers. If you want your program to run with complex input,
you have to avoid such operations, whether the data type is native or not.

What other considerations are there? A typical numeric program should
just run and give complex output when fed complex input. I made the
experiment with the Perl module Statistics:escriptive, which was
certainly written without concern for complex input, and it works without
a hitch. I'm not sure if the (complex) variance of several complex
numbers is a reasonably interpretable quantity, but I'm certain the
maths is done right. What else do you want?

Anno
 
Reply With Quote
 
Big and Blue
Guest
Posts: n/a
 
      01-11-2005
It's me wrote:
>
> I am very happy that Python included *native* complex number
> support.


And I have always been happy that FORTRAN supports them.

> I really like Python's notion of having just one data type: the duck.


So have you considered using Python for your problem?

--
Just because I've written it doesn't mean that
either you or I have to believe it.
 
Reply With Quote
 
It's me
Guest
Posts: n/a
 
      01-11-2005

"Big and Blue" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> It's me wrote:
> >
> > I am very happy that Python included *native* complex

number
> > support.

>
> And I have always been happy that FORTRAN supports them.
>
> > I really like Python's notion of having just one data type: the duck.

>
> So have you considered using Python for your problem?
>


Yes, over the holiday, I wrote a somewhat complex program using Python -
just so I can apply what I have learned so far. It's a joy to use. I was
able to finished the program in a fraction of the time it used to take me in
Fortran (and later C).


 
Reply With Quote
 
It's me
Guest
Posts: n/a
 
      01-11-2005
You are focusing on computational type applications of complex numbers. For
those, you can do it with any languages - including machine language. It's
just a matter of how much headache you want.

For instance, when constructing "software lego parts" (such as the
Matlab/Simulink type), it's very annoying that you need to know what kind of
signal comes in and goes out. In Malab/Simulink, for instance, you specify
that the signal is of the "inherit" type (meaning you don't care what type
it is - just process it). In Python, it's of type "duck", just pass it
on...I don't need to care if it's real or complex. I don't need to devise
yet another overloaded operator or function whenever I encounter a situation
where the native language doesn't handle.



"Anno Siegel" <(E-Mail Removed)-berlin.de> wrote in message
news:cs17od$ag1$(E-Mail Removed)-Berlin.DE...

>
> What kind of awareness do you mean?
>
> There are some operations (as comparison) that work for reals, but not
> for complex numbers. If you want your program to run with complex input,
> you have to avoid such operations, whether the data type is native or not.
>
> What other considerations are there? A typical numeric program should
> just run and give complex output when fed complex input. I made the
> experiment with the Perl module Statistics:escriptive, which was
> certainly written without concern for complex input, and it works without
> a hitch. I'm not sure if the (complex) variance of several complex
> numbers is a reasonably interpretable quantity, but I'm certain the
> maths is done right. What else do you want?
>
> Anno



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How complex is complex? Kottiyath Python 22 03-28-2009 10:11 PM
wsdl2java: method parameter a complex type that extends another complex type Robert Mark Bram Java 0 02-04-2007 10:06 AM
Implementing Complex Numbers operation in bytecode oulan bator Java 29 12-04-2005 12:51 PM
[XML Schema] Content type of complex type definition with complex content Stanimir Stamenkov XML 2 10-25-2005 10:16 AM
For expert on complex loops (reposted) - complex looping problem news.amnet.net.au Java 1 04-13-2004 07:10 AM



Advertisments