Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any number isComplexNumber should answer true #194

Open
olekscode opened this issue Feb 23, 2021 · 1 comment
Open

Any number isComplexNumber should answer true #194

olekscode opened this issue Feb 23, 2021 · 1 comment

Comments

@olekscode
Copy link
Member

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?

@nicolas-cellier-aka-nice
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants