bugGNU Octave - Bugs: bug #51556, function isreal applied on complex...

 
 

bug #51556: function isreal applied on complex numbers with zero imaginary part

Submitter:  Ernst Reissner <ernstreissner>
Submitted:  Mon 24 Jul 2017 12:02:48 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  None Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 24 Jul 2017 02:23:01 PM UTC, comment #4: 

In Matlab 2016a, sorry not the latest, "isreal (0i)" returns true. The sequence from comment #2 returns the results in comments. So I guess this report can be closed as invalid.

Pantxo Diribarne <pantxo>
Group Member
Mon 24 Jul 2017 02:04:33 PM UTC, comment #3: 

To confirm JWE's presumption, Matlab r2017b prerelease gives:

>> isreal (0i)
ans =
  logical
   1
>>


and r2016b does exactly the same.

Furthermore,

>> format compact
>> x = complex (12, 0)  %% 12+0i
isreal (x)           %% false
y = 1 + x            %% 13
isreal (y)           %% true
x =
  12.0000 + 0.0000i
ans =
  logical
   0
y =
    13
ans =
  logical
   1
>>


Philip Nienhuis <philipnienhuis>
Group Member
Mon 24 Jul 2017 01:26:20 PM UTC, comment #2: 

In Matlab, (and Octave, for compatibility reasons) if you want to create a complex value with a zero imaginary part, you need to use something like "complex (r, 0)".  And even then, if you use that value in an expression like this:


x = complex (12, 0)  %% 12+0i
isreal (x)           %% false
y = 1 + x            %% 13
isreal (y)           %% true


you will get a real value as the final result because of the automatic complex -> real conversion rules for (nearly all) expression results.

I'm certainly not claiming this is mathematically correct or necessarily the best programming language design.  But it is the way Matlab works and we have to do the same for compatibility reasons.  If we didn't, we'd be constantly getting bug reports that Octave fails on code that works perfectly well in Matlab.

John W. Eaton <jwe>
Group administrator
Mon 24 Jul 2017 01:16:41 PM UTC, comment #1: 

I'm pretty sure that Matlab automatically narrows the result of the expression 0i to be real, so that isreal (0i) actually returns true.

Could someone please verify with the latest Matlab?

John W. Eaton <jwe>
Group administrator
Mon 24 Jul 2017 12:02:48 PM UTC, original submission:  

According to
https://www.mathworks.com/help/matlab/ref/isreal.html

isreal(x) determines whether a has real type.
Consequently, isreal(0i) is false in matlab.
also isreal([0i 1]) is just false, a single scalar value
because the type is meant, not zero imaginary part in all components.

The current usage of isreal(A)
which means imag(A) is nonzero may be substituted by

~any(imag(A)).

Ernst Reissner <ernstreissner>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by ernstreissner (Submitted the item)
  • -email is unavailable- added by ernstreissner
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-07-24 rik5 Open/ClosedOpen Closed
    2017-07-24 ernstreissner Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code