On 1/26/12 8:21 PM, Tom Boothby wrote:
On Thu, Jan 26, 2012 at 5:15 PM, David Roe<r...@math.harvard.edu>  wrote:
Another issue: do we allow [1..10; 10..20]?

We probably shouldn't go to extra effort to support it.

I can't seem to construct
matrices with matrix entries (this is not absurd) -- but should the
preparser grok it? [[1..10; 10..20] ; [2..12; 14..24]]

Yes, for sure. And [[1..10; 10..20].det() ; [2..12; 14..24].det()]

I'm not quite clear how these are square matrices (or even how the
rows have the same length).  What does [1..10; 10..20] translate to?

They aren't square... and worse, [1..10; 10..20] doesn't make sense
since the top row has 9 entries whereas the bottom has 10.  We're
being sloppy for the sake of conversation.  I tend to think that we
should support ellipses, though I admit it's a corner case of limited
utility.

[0..2; 10..12] ->  [[0,1,2],[10,11,12]]


Two comments:

1. If [0..2, 10..12] works, I think matrix([[0..2],[10..12]]) should work. Notice, with the current patch:

sage: matrix([[0..2],[10..12]])
[ 0  1  2]
[10 11 12]
sage: [0..2;10..12]
------------------------------------------------------------
   File "<ipython console>", line 1

(ellipsis_range(Integer(0),Ellipsis,Integer(2);Integer(10),Ellipsis,Integer(12)))
                                                   ^
SyntaxError: invalid syntax

sage: preparse('[0..1;3..4]')
'(ellipsis_range(Integer(0),Ellipsis,Integer(1);Integer(3),Ellipsis,Integer(4)))'

So maybe we just need to switch the order of preparsing? Indeed, moving the matrix preparsing call ahead of the ellipsis call gives:

sage: preparse('[0..2; 3..5]')
'matrix([(ellipsis_range(Integer(0),Ellipsis,Integer(2))),(ellipsis_range( Integer(3),Ellipsis,Integer(5)))])'
sage: [0..2; 3..5]
[0 1 2]
[3 4 5]


2. Matlab supports such notation (except they use a colon to give a range, like 0:10 for [0..10] and 0:2:10 for [0..10,step=2]). It would be nice if we supported it as well. With the above change, we also get that for free:

sage: [0..10,step=2; 1..11,step=2]
[ 0  2  4  6  8 10]
[ 1  3  5  7  9 11]
sage: [0,2,..,10; 2,4,..,12]
[ 0  2  4  6  8 10]
[ 2  4  6  8 10 12]

I'm not sure if there is a problem with moving the matrix parsing up that early in the preparsing stage, though.

Jason

        

--
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to