[3.9] 7033 available

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
25 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: which fix is the best for Complex?

Matej Kosik-2
Thomas Koenig wrote:
> Steph, I recommend harvesting Nicolas cellier' fixes.  Certainly in
> preference to mine (to in elegant) and even in preference to (isNumber
> ignores issues discussed in Complex class comments.) Nicolas appears to have
> spent the time working with Complex.  Tom
>

Hello,

Once upon a time the `Complex' class was in a separate package called
`Algebraic'. Its intention was to brings things like complex numbers,
matrices, polynoms and such to the image. Since it was rather
incomplete, I deleted it. Later someone put these classes into the core
image.

The problem with the Complex class (and I thought that it was obvious)
is, that it cannot be implemented correctly without traits. Complex
certainly is a number (roughly) (you can do arithmetic with it, it plays
well with other numbers etc). The problem is, that it is not a magnitude
(they cannot be sensibly totally ordered).

Other things are problematic. If `Complex' is a `Number' then methods:

        to:
        to:by:
        to:by:do:
        to:do:
        even
        odd
        isDivisibleBy:
        negative
        positive
        sign
        strictlyPositive
        ceiling
        detentBy: detent atMultiplesOf: grid snap: snap
        floor
        fractionPart
        integerPart
        reduce
        roundTo:
        roundUpTo:
        rounded
        truncateTo:
        truncated

do not have sense.

Finer classification would be more appropriate, but the whole stuff
would be a bit more complicated. I am not sure if it could be done
without traits (I guess).
--
Matej Kosik



signature.asc (264 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: which fix is the best for Complex?

Mathieu SUEN
In reply to this post by stéphane ducasse-2


2006/6/10, stéphane ducasse <[hidden email]>:
Ok I will when I do the next batch (My home network access just broke
down two days ago and now nothing works and I do not know why this is
down.....arghhhhhhh)
So I do not have internet access the evening and week-ends. Rather
cool situation.

Stef


Indeed :(
It just make me think  that  Internet is becoming the <span onclick="dr4sdgryt(event)">electricity of the twenty-first century. :)


On 10 juin 06, at 18:54, Thomas Koenig wrote:

> Steph, I recommend harvesting Nicolas cellier' fixes.  Certainly in
> preference to mine (to in elegant) and even in preference to (isNumber
> ignores issues discussed in Complex class comments.) Nicolas
> appears to have
> spent the time working with Complex.  Tom
>
> stéphane ducasse
>> So which fix is the best?
>>
>> Stef
>>
>> On 1 juin 06, at 01:38, nicolas cellier wrote:
>>
>>> Hi Diego,
>>>
>>> Le Jeudi 01 Juin 2006 01:20, Diego Fernandez a écrit :
>>>> Hi Nicolas, I have submitted the fix at
>>>> http://bugs.impara.de/view.php?id=3725
>>>
>>> i did guess your initials.
>>>
>>>> Oops! I did't see your previous bug fix in Mantis, so the mine is
>>>> a dupe.
>>>> (and thanks for the comments).
>>>
>>> You're welcome, better have two fixes than one (three with tom's
>>> one, and
>>> maybe four with hilaire's). It is good to have other opinions.
>>> Of course, we should always look in mantis first, and the site is
>>> quite
>>> efficient with keyword search, but me too i forget sometimes...
>>>
>>> Nicolas
>>>
>>>
>>>
>>
>
>
>
>
>





Reply | Threaded
Open this post in threaded view
|

Re: which fix is the best for Complex?

stéphane ducasse-2
In reply to this post by Matej Kosik-2
Ok so could the mathematical guys sync and propose a nice solution  
and let me
know what to do?

Stef


On 10 juin 06, at 22:04, Matej Kosik wrote:

> Thomas Koenig wrote:
>> Steph, I recommend harvesting Nicolas cellier' fixes.  Certainly in
>> preference to mine (to in elegant) and even in preference to  
>> (isNumber
>> ignores issues discussed in Complex class comments.) Nicolas  
>> appears to have
>> spent the time working with Complex.  Tom
>>
>
> Hello,
>
> Once upon a time the `Complex' class was in a separate package called
> `Algebraic'. Its intention was to brings things like complex numbers,
> matrices, polynoms and such to the image. Since it was rather
> incomplete, I deleted it. Later someone put these classes into the  
> core
> image.
>
> The problem with the Complex class (and I thought that it was obvious)
> is, that it cannot be implemented correctly without traits. Complex
> certainly is a number (roughly) (you can do arithmetic with it, it  
> plays
> well with other numbers etc). The problem is, that it is not a  
> magnitude
> (they cannot be sensibly totally ordered).
>
> Other things are problematic. If `Complex' is a `Number' then methods:
>
> to:
> to:by:
> to:by:do:
> to:do:
> even
> odd
> isDivisibleBy:
> negative
> positive
> sign
> strictlyPositive
> ceiling
> detentBy: detent atMultiplesOf: grid snap: snap
> floor
> fractionPart
> integerPart
> reduce
> roundTo:
> roundUpTo:
> rounded
> truncateTo:
> truncated
>
> do not have sense.
>
> Finer classification would be more appropriate, but the whole stuff
> would be a bit more complicated. I am not sure if it could be done
> without traits (I guess).
> --
> Matej Kosik
>


Reply | Threaded
Open this post in threaded view
|

Re: which fix is the best for Complex?

Adrian Lienhard
In reply to this post by Matej Kosik-2
you may want to have a look at the TraitsExample package in the  
Traits repository on SqueakSource (http://www.squeaksource.com/ 
Traits.html).

It contains an implementation of Complex using a trait.

Adrian


On Jun 10, 2006, at 22:04 , Matej Kosik wrote:

> Thomas Koenig wrote:
>> Steph, I recommend harvesting Nicolas cellier' fixes.  Certainly in
>> preference to mine (to in elegant) and even in preference to  
>> (isNumber
>> ignores issues discussed in Complex class comments.) Nicolas  
>> appears to have
>> spent the time working with Complex.  Tom
>>
>
> Hello,
>
> Once upon a time the `Complex' class was in a separate package called
> `Algebraic'. Its intention was to brings things like complex numbers,
> matrices, polynoms and such to the image. Since it was rather
> incomplete, I deleted it. Later someone put these classes into the  
> core
> image.
>
> The problem with the Complex class (and I thought that it was obvious)
> is, that it cannot be implemented correctly without traits. Complex
> certainly is a number (roughly) (you can do arithmetic with it, it  
> plays
> well with other numbers etc). The problem is, that it is not a  
> magnitude
> (they cannot be sensibly totally ordered).
>
> Other things are problematic. If `Complex' is a `Number' then methods:
>
> to:
> to:by:
> to:by:do:
> to:do:
> even
> odd
> isDivisibleBy:
> negative
> positive
> sign
> strictlyPositive
> ceiling
> detentBy: detent atMultiplesOf: grid snap: snap
> floor
> fractionPart
> integerPart
> reduce
> roundTo:
> roundUpTo:
> rounded
> truncateTo:
> truncated
>
> do not have sense.
>
> Finer classification would be more appropriate, but the whole stuff
> would be a bit more complicated. I am not sure if it could be done
> without traits (I guess).
> --
> Matej Kosik
>


Reply | Threaded
Open this post in threaded view
|

Re: which fix is the best for Complex?

Nicolas Cellier-3
In reply to this post by Matej Kosik-2
Hello,

Le Samedi 10 Juin 2006 22:04, Matej Kosik a écrit :

> Thomas Koenig wrote:
> > Steph, I recommend harvesting Nicolas cellier' fixes.  Certainly in
> > preference to mine (to in elegant) and even in preference to (isNumber
> > ignores issues discussed in Complex class comments.) Nicolas appears to
> > have spent the time working with Complex.  Tom
>
> Hello,
>
> Once upon a time the `Complex' class was in a separate package called
> `Algebraic'. Its intention was to brings things like complex numbers,
> matrices, polynoms and such to the image. Since it was rather
> incomplete, I deleted it. Later someone put these classes into the core
> image.
>

Good idea, and Complex still can easily be separated from base image if we
want to, because it does not have any user...

However, it's better to maintain Complex-compatible methods in Number
implemented in base image rather than having to override these methods with
an algebraic package.
The less we override, the better we feel.

> The problem with the Complex class (and I thought that it was obvious)
> is, that it cannot be implemented correctly without traits. Complex
> certainly is a number (roughly) (you can do arithmetic with it, it plays
> well with other numbers etc). The problem is, that it is not a magnitude
> (they cannot be sensibly totally ordered).
>

Agree and Disagree...
Traits will certainly help factor more code, and it is a good idea to use it
in algebra.
But i do not see why it would be the only solution to get a correct
implementation.

> Other things are problematic. If `Complex' is a `Number' then methods:
>
>  to:
>  to:by:
>  to:by:do:
>  to:do:
>  even
>  odd
>  isDivisibleBy:
>  negative
>  positive
>  sign
>  strictlyPositive
>  ceiling
>  detentBy: detent atMultiplesOf: grid snap: snap
>  floor
>  fractionPart
>  integerPart
>  reduce
>  roundTo:
>  roundUpTo:
>  rounded
>  truncateTo:
>  truncated
>
> do not have sense.
>
> Finer classification would be more appropriate, but the whole stuff
> would be a bit more complicated. I am not sure if it could be done
> without traits (I guess).

In VW they have an intermediate class, ArithmeticValue, superclass of both
Number and Complex, though subclass of Magnitude...
But subclassing is not the only design pattern...
This can be achieved well with isAlgebraic isArithmetic isNumerable
isNumberExtension or whatever message alike
And yes, Traits can be an elegant way to implement it.

Concerning the question of equality bug, there is another solution: if (1 + 0
i) would reduce its generality automatically to Number, rather than answering
a Complex with null imaginary part, then we would not care of comparing
Number and Complex anymore... However then, Number should implement some
Complex protocol (like realPart, imaginaryPart, conjugated or whatever...),
and yes Traits would do it again...

See how Fraction and Integer work, we don't care comparing a (reduced)
Fraction and an Integer... And Integer canimplement numerator and denominator
as a special case of Fraction...

I think this approach is used in VW Complex.

Squeak strategy is rather to honour programmer intention to have a memory slot
for holding Complex value, something more static like say FORTRAN x = (1.,0.)

Both approach have their advantages; i have a slight preference for the
former, but i'am not sure...

Nicolas


12