bugGNU Octave - Bugs: bug #34365, pascal(n,2) returns different...

 
 

bug #34365: pascal(n,2) returns different permutation than ML; pascal() for n=0 inaccurately returns [1]

Submitter:  Vanya Sergeev <vsergeev>
Submitted:  Fri 23 Sep 2011 09:20:59 AM UTC
   
 
Category:  Libraries Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed 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
   

Sun 20 Nov 2011 09:36:57 PM UTC, comment #1: 

Thanks for the hg changeset.  It applied cleanly here (http://hg.savannah.gnu.org/hgweb/octave/rev/d4404589498c).  It will be part of the 3.6.0 release scheduled for December 2011.

Rik <rik5>
Group administrator
Fri 23 Sep 2011 09:20:59 AM UTC, original submission:  

ML's pascal(n,2) returns the horizontal permutation of pascal(n,1)', whereas Octave's pascal(n,2) returns the vertical permutation of pascal(n,1)'. They're both valid permutations of pascal(n,1)' in that pascal(n,2)^3 = eye(n), but using the same permutation as ML might be warranted for compatibility purposes.

Octave also does not handle the n=0 case correctly, it returns a 1x1 matrix [1] for pascal(0) and pascal(0,1), and errors out for pascal(0,2). ML returns the 0x0 empty matrix for pascal(n), 0x1 empty matrix for pascal(n,1), and 1x0 empty matrix for pascal(n,2).

MATLAB's pascal():

>> pascal(3,1)

ans =

     1     0     0
     1    -1     0
     1    -2     1

>> pascal(3,1)'

ans =

     1     1     1
     0    -1    -2
     0     0     1

>> pascal(3,2)

ans =

     1     1     1
    -2    -1     0
     1     0     0

>> pascal(4,2)

ans =

    -1    -1    -1    -1
     3     2     1     0
    -3    -1     0     0
     1     0     0     0

>> pascal(0)

ans =

     []

>> pascal(0,1)

ans =

   Empty matrix: 0-by-1

>> pascal(0,2)

ans =

   Empty matrix: 1-by-0

>>


Octave's pascal():

octave:162> pascal(3,1)
ans =

   1   0   0
   1  -1   0
   1  -2   1

octave:163> pascal(3,1)'
ans =

   1   1   1
   0  -1  -2
   0   0   1

octave:164> pascal(3,2)
ans =

   0   0  -1
   0  -1   2
  -1  -1   1

octave:165> pascal(4,2)
ans =

  -0  -0  -0  -1
  -0  -0  -1   3
  -0   1   2  -3
   1   1   1  -1

octave:166> pascal(0)
ans =  1
octave:167> pascal(0,1)
ans =  1
octave:168> pascal(0,2)
error: pascal: subscript indices must be either positive integers or logicals
error: called from:
error:   /usr/share/octave/3.4.2/m/special-matrix/pascal.m at line 75, column 17
octave:169>


Attached is hg patch to scripts/special-matrix/pascal.m for improved ML compatibility with pascal(), as well as a fix for the n=0 case.

The patched pascal() octave output:

octave:1> pascal(3,2)
ans =

   1   1   1
  -2  -1   0
   1   0   0

octave:2> pascal(4,2)
ans =

  -1  -1  -1  -1
   3   2   1  -0
  -3  -1  -0  -0
   1  -0  -0  -0

octave:3> pascal(0)
ans = [](0x0)
octave:4> pascal(0,1)
ans = [](0x0)
octave:5> pascal(0,2)
ans = [](0x0)
octave:6>


For simplicity, I didn't make the modifications to reflect ML's dimensions of the empty matrix with pascal(0,1) and pascal(0,2), but this can probably be easily added if it's necessary.

~vsergeev

Vanya Sergeev <vsergeev>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #24017:  pascal.diff added by vsergeev (1KiB - text/x-patch - hg changeset patch for pascal.m)

 

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 vsergeev (Submitted the item)
  •  

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

    Date Changed by Updated Field Previous Value => Replaced by
    2011-11-20 rik5 StatusNone Fixed
        Open/ClosedOpen Closed
    2011-09-23 vsergeev Attached File- Added pascal.diff, #24017

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code