Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   complex numbers (http://www.velocityreviews.com/forums/t890073-complex-numbers.html)

 xah@xahlee.org 01-09-2005 08:36 AM

complex numbers

#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
xah@xahlee.org
http://xahlee.org/PageTwo_dir/more.html

 Jürgen Exner 01-09-2005 08:58 AM

Re: complex numbers

xah@xahlee.org 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

Re: complex numbers

xah@xahlee.org <xah@xahlee.org> wrote:

> #python supports complex numbers.

> # Perl doesn't support complex numbers.

Then you should use Python and stop Perl programming immediately!

--
Fort Worth, Texas

 Alfred Z. Newmane 01-10-2005 05:51 PM

Re: complex numbers

J|rgen Exner wrote:
> xah@xahlee.org 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.

 It's me 01-11-2005 12:11 AM

Re: complex numbers

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" <jurgenex@hotmail.com> wrote in message
news:Fm6Ed.3556\$u47.321@trnddc09...
> xah@xahlee.org 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
>
>

 Anno Siegel 01-11-2005 05:59 PM

Re: complex numbers

It's me <itsme@yahoo.com> wrote in comp.lang.perl.misc:

[reply moved to bottom into context]

> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> news:Fm6Ed.3556\$u47.321@trnddc09...
> > xah@xahlee.org 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

 Anno Siegel 01-11-2005 07:00 PM

Re: complex numbers

It's me <itsme@yahoo.com> wrote in comp.lang.perl.misc:

> "Anno Siegel" <anno4000@lublin.zrz.tu-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.

> 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::Descriptive, 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

 Big and Blue 01-11-2005 08:50 PM

Re: complex numbers

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.

 It's me 01-11-2005 10:51 PM

Re: complex numbers

"Big and Blue" <No_4@dsl.pipex.com> wrote in message
news:6-Cdnfjyqs6coXncRVnyuA@pipex.net...
> 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).

 It's me 01-11-2005 11:01 PM

Re: complex numbers

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" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:cs17od\$ag1\$1@mamenchi.zrz.TU-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::Descriptive, 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

All times are GMT. The time now is 01:25 AM.