> my Complex $c = 3+4i;
> my Complex $d = 4i;
> my $plain = $c / $d;
>
> Does $plain (which is actually '3' after reducing) get promoted to
> Complex, or does the result from the division get demoted?

In a related matter, computer languages with Symbolic Mathematics
capabilities, like Mapple, let you explicitly demand where do you want the
operation to take place.

This could be done naturally in perl6 using the colon meta-operator:

my $plain = $c - $d : Math::Reals     # 3.0
my $plain = $c - $d : Math::Complex   # 3.0 + 0i

As long it is well documented and consistent, it doesn't really matter which
one is the default.

Adding this feature is useful in a wider area of applications:

2 ^ 4 : Math::FiniteField(7) # -> 1

Or even:

sqrt(2 : Math::Integers)       # -> exception or not-a-number
sqrt(2 : Math::FiniteField(7)) # -> 3
sqrt(2 : Math::TrueReals)      # -> "sqrt(2)"

In general, any mathematical operation should be capable of taking
optionally the structure where the operations is defined, and a whole
universe of fun will open for us mathematicians.. :-)

(Just think of factoring polynomials in F[25][X] over its algebraic
closure... mmm...)

This can be implemented having operations defined as:

sub operator:DIV($a, $b : $structure) {
        if      $structure and $strcture.can('DIV') {$structure.DIV($a,$b)}
        elsif $a.can('DIV') {$a.DIV($a,$b)}
        elsif $b.can('DIV') {$c.DIV($a,$b)}
        else  {..throw exception..}
}

On the other hand, it is (it will be) perfectly possible to do it as an user
module, so this post it's actually a big OT, and you should better forget
it, in case you have been unfortunate enough to read until here...

Oh. Damn.

-angel

Reply via email to