On Wed, Aug 19, 2009 at 2:56 PM, rjf<fate...@gmail.com> wrote:
>
> Let's see, in sage then you have the following syntax.
> (x,y)   means a list

Not at all.  (x, y) is a tuple.  [x, y] is a list.

> f(x,y)  means a function application
> (x+y) means grouping for arithmetic.
> RationalField(x)  means, uh, sortof  "in indeterminate..."
> Integer(4)  means, uh, set the type? force a coercion?
>
> Are there any other distinct uses of ()?
>
>
> However, the Sage choice is kind of confusing.
> x  //a variable
> (x )  // a list of one item or a group consisting of x alone, hence x.
> ((x))  // a list of one item, grouped alone.  Or a list of a list of
> one item.  Or just x.
>
> That is, if (a+1,a+2)  is a list of 2 items, is (a+1) not a list of
> one item?
>
> I'm sure there is a simple explanation.

Yes, the explanation is that you're mixing up ()'s and []'s.  You
*could* actually try out the above in Sage to see whether you're right
or not, instead of making it up:

sage: a = 1; a
1
sage: type(a)
<type 'sage.rings.integer.Integer'>
sage: a = (1); a
1
sage: type(a)
<type 'sage.rings.integer.Integer'>
sage: a = ((1)); a
1
sage: type(a)
<type 'sage.rings.integer.Integer'>
sage: a = (((((((1))))))); a
1

So in the absence of a function in front of (), and in the absence of
commas inside (), it's what you call "grouping for arithmetic".

Now for lists:

sage: a = [1]; a
[1]
sage: type(a)
<type 'list'>
sage: a[0]
1
sage: type(a[0])
<type 'sage.rings.integer.Integer'>
sage: a = [[1]]; a
[[1]]
sage: type(a)
<type 'list'>
sage: a[0]
[1]
sage: type(a[0])
<type 'list'>
sage: a[0][0]
1
sage: type(a[0][0])
<type 'sage.rings.integer.Integer'>

These seem unambiguous to me.  If you're after the tuple with one
element 1, a = (1,) does the trick, as Ondrej pointed out.


Best,
Alex




> >
>

























-- 
Alex Ghitza -- Lecturer in Mathematics -- The University of Melbourne
-- Australia -- http://www.ms.unimelb.edu.au/~aghitza/

--~--~---------~--~----~------------~-------~--~----~
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
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to