PolyMath icon indicating copy to clipboard operation
PolyMath copied to clipboard

Any number isComplexNumber should answer true

Open olekscode opened this issue 4 years ago • 1 comments

I am not sure about this.

At the moment, isComplexNumber means "is this an instance of PMComplexNumber?" and isRealNumber means "is this an instance on Number which is not an instance of PMComplexNumber?" Therefore,

(5 + 0i) isComplexNumber. "true"
5 isComplexNumber. "false"

(5 + 0i) isRealNumber. "false"
5 isRealNumber. "true"

Even though

(5 + 0i) = 5. "true"

In mathematics though, a set of real numbers is fully included into the set of complex numbers: Every real number is complex.

Perhaps, we should have something like this:

Object >> isComplexNumber
    ^ self isNumber
    
Number >> isRealNumber
    ^ true
    
PMComplexNumber >> isRealNumber
    ^ false

The result would be:

(5 + 0i) isNumber. "true"
5 isNumber. "true"

(5 + 0i) isComplexNumber. "true"
5 isComplexNumber. "true"

(5 + 0i) isRealNumber. "false"
5 isRealNumber. "true"

Or maybe we should even have this:

(5 + 0i) isRealNumber. "true"
(5 + 2i) isRealNumber. "false"

What do you think?

olekscode avatar Feb 23 '21 15:02 olekscode

As discussed in #193 the implication of that would be: if any Number answer true to isComplexNumber, then it should also behave asComplexNumber.

For example, one implication would be

 [ -2 sqrt = -2 asComplexNumber sqrt ] assert.

In other words, usual mathematical functions should be extended to complex extension, instead of raising an Error... That's a change of previous contracts for every other client of sqrt & co.

An alternative would be to distinguish the complex extension: create complex-specific math functions (i.e. complexSqrt, complexArcCos, complexLn, ...).

Yet another alternative would be to make the behavior contextual. How to implement, and how to specify the context is yet to be defined.