History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: BOO-429
Type: Wish Wish
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Norbert Nemec
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Boo

Complex number literals and builtin type

Created: 07/Aug/05 02:11 PM   Updated: 02/Nov/05 01:45 AM
Component/s: None
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. File ComplexUnit.boo (4 kb)

Issue Links:
dependent
 


 Description  « Hide
In python, there is a native complex type and a very convenient literal notation, yet lacking in boo:

>>> a = 1j
>>> type(a)
<type 'complex'>
>>> a**2
-1+0j

Of course, complex numbers could be implemented in the library, but I believe there is good reason for a native complex type: They are fundamental throughout physics and engineering. Python already has become a major player in the community of scientific computing (see www.scipy.org). Boo could be the natural successor. Having a native complex type would be the first sign to show that boo is meant for serious numerics as well.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Norbert Nemec - 27/Oct/05 05:14 AM
Just did a little research on this issue. Turns out, it is quite a tricky issue: there is no standard complex type anywhere in the standard libraries. Neither the .NET System, nor Mono define such a type.

This means: every library dealing with complex arithmetics has to define its own complex type. Which again means that all these libraries are incompatible with each other. Not a good idea at all!

For the moment, boo could probably just define some standard complex type but keep everything modular enough that it could be easily replaced by a more standard version in .NET or somewhere else.


Doug H - 27/Oct/05 10:23 AM
If BOO-1 is added to boo, and if a units library were added to boo, like a boo.science.dll or something, I think adding a built-in complex number type would make sense too.

I attached a sample that uses the dnAnalytics complex number class. Read the comments at the top of the file for instructions. Here's a sample:

I put in support for both "i" and "j". If we had to decide, I'd say use "i" since it is what most people normally use, even though python uses "j" for some reason.

import dnA.Math from "dnA"
x = 3 + 5j
y = 6 - 2j
print x+y //9+3i


Doug H - 27/Oct/05 01:06 PM
this version adds AfterStep listener just once

Cameron Kenneth Knight - 31/Oct/05 07:37 PM
I've been making a science library for boo that uses the unit literals, and I have included Complex number support for it.

svn://ckknight.no-ip.org/Science


Norbert Nemec - 02/Nov/05 01:45 AM
Nice work! Would be great if this were to find its way into the standard library.

One basic issue remains, though: Is there a chance for one standard complex type that can be used across various libraries or should every numerics library reinvent the wheel?

I fear that ultimately, the only one who could set a standard is Microsoft. If boo introduced a standard complex type, libraries like dnA or math.Net will not see it. If Mono introduces it, one cannot use it with microsoft .NET

Just for the record: 'i' or 'j' are not necessarily "more or less common", but they are used by different communities. Physics and mathematics generally use 'i' while engineering uses 'j'. This is also why Python has the 'j'.

However: neither of the two letters is used for any physical unit or as a type suffix for any type but complex in any other language (to my knowledge) So there is no harm in simply allowing both letters as synonyms.