bugGNU Octave - Bugs: bug #60265, Negative zeros in matrices -...

 
 

bug #60265: Negative zeros in matrices - inconsistency

Submitter:  None
Submitted:  Sun 21 Mar 2021 07:56:55 AM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Wont Fix Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 6.2.0
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 21 Mar 2021 03:24:44 PM UTC, comment #2: 

This is expected and comes up from time to time.  Octave/Matlab are computer aids for performing numerical calculations, not pure math.  In pure math there is only one representation of zero.  But, as it happens, the IEEE standard for floating point numbers uses one bit for the sign and the rest for the magnitude of a number.  Thus, it is possible to have a magnitude of zero, and still have either a positive or negative sign bit.

Matlab is the same way.  They don't display the negative sign, but they remember it.  For example,


A = eye (2)
A = 2x2
    1   0
    0   1

1 ./ -A
ans = 2x2
      -1   -Inf
      -Inf -1


As @Markus mentioned, Octave has a special diagonal matrix class that behaves like sparse matrices which don't record the sign bit of zeros.  Because they don't care about sign, they will always return +Inf for 1/0.

So, it's really up to you whether you care about this and, if you do, which convention you want to adhere to.  If you want behavior more similar to pure math with only one, positive zero then continue to use diagonal matrices.  If you want the reverse convention, then disable diagonal matrices with


disable_diagonal_matrix (true)






Rik <rik5>
Group administrator
Sun 21 Mar 2021 12:14:21 PM UTC, comment #1: 

Octave has a dedicated type for diagonal matrices. Those are similar to sparse matrices but only store the elements on the diagonal. `eye` returns a diagonal matrix.

The unary `-` operator on a diagonal matrix returns a diagonal matrix.

On Ubuntu 20.10 with Octave 6.2.1 (hg id 75ba68c686ab), I see the following:

>> A = eye (2)

A =

Diagonal Matrix

   1   0
   0   1

>> B = [1 0; 0 1]

B =

   1   0
   0   1

>> 1 ./ (-A)

ans =

    -1   Inf
   Inf    -1

>> 1 ./ (-B)

ans =

    -1  -Inf
  -Inf    -1


Afaict, these are the expected results.

Could you please elaborate what you think is the issue and how that relates to sympy?

Markus Mützel <mmuetzel>
Group administrator
Sun 21 Mar 2021 07:56:55 AM UTC, original submission:  

```
A=eye(2)
-A
B=[1 0;0 1]
-B
```

-A is correct, whereas -B shows negative zeros. I didn't find this issue in sympy.

Anonymous

 

(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 (Posted a comment)
  • -email is unavailable- added by mmuetzel (Posted a comment)
  •  

    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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-03-21 rik5 CategoryNone Interpreter
        StatusNeed Info Wont Fix
        Open/ClosedOpen Closed
    2021-03-21 mmuetzel StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code