Can you give a sample session demonstrating how you want to use indexed
They are not wrapped in Sage, but it is fairly easy to do this. If
you can work out the user interface, I can do the rest quickly. I don't
have time to think about a user interface however.
> Well, it's a little dangerous for someone (me) who doesn't really
> understand how to *use* the tool to *design the interface* to the
> tool. But since I'm rarely bothered by my own ignorance, I'll charge
> ahead. :-)
> After writing a long, detailed email, I realized it's probably better
> to start a wiki page instead. See
> <http://wiki.sagemath.org/symbolics/Indexed expressions>
> for my thoughts. Thanks for your help!
The wiki page is a good idea. Thanks for taking the time to write your
Here is a patch with the first steps to use indexed expressions:
I used the slice notation to denote dimensions. If you have a
variable x, and you want an index with dimension 3, you write:
Dimensions are not printed, but they are there. :)
I'm afraid I don't understand what you expect sum() to do. We already
have a sum() method for symbolic expressions. Please take that into
account as well.
Note that GiNaC cannot take derivatives of indexed expressions .
Perhaps this is a show stopper for you.
On a completely different note... I prefer to use the brackets to access
the operands of an expression, instead of creating indexed expressions.
There has been several complaints about not being able to access the
operands lately, and I think this is the most natural way to do so.
You will see that there is already a __getitem__() method in
expression.pyx which was commented during the symbolics switch. I
suggest we uncomment that and use a different method (.indexed()?) for
the indexed expressions.
I like the slice syntax as well. I think it'd be nice to reserve the
__getitem__ notation for subscripts.
On Mon, 12 Jul 2010 22:52:24 -0700
Robert Bradshaw <robe...@math.washington.edu> wrote:
> > As for syntax, I think the slice syntax is clever and fairly
> > intuitive. I can also understand using brackets to access operands
> > in an expression. Personally, I think the brackets make more sense
> > for indexing, but they would probably see more use for operand
> > access. It wouldn't bother me to use an ``indexed()`` method
> > instead. I would be happy to review a patch to add either one.
> I like the slice syntax as well. I think it'd be nice to reserve the
> __getitem__ notation for subscripts.
We don't have to use __getitem__ to have access to the slice notation.
I suggest keeping __getitem__ to index operands of an expression and
adding an .index property, which provides __getitem__, to get indexed
expressions. For example:
(x, y, z)
sage: t = x+y+z; t
x + y + z
sage: x.index[i:3] #indexed expression
I was thinking
sage: latex(x, x, x[i])
(x_1, x_2, x_i)
The index notation would be a convenient way to get many new (related)
variables, much cleaner IMHO than creating a string to pass to vars. I
think this is what Mathematica and/or Maple to as well.
I think indexing into operands by number is a bit brittle, and
x.operands() is much more explicit.
On the other hand, then you get expressions like
which are a bit unwieldy especially since none of the later
.operands() tab-complete. One is more likely to need a deeper call of
operand calls the index calls.