On Apr 2, 12:14 pm, Jason Grout <jason-s...@creativetrax.com> wrote:
> On 04/02/2010 12:47 PM, Franco Saliola wrote:

> > Here is a very simple implementation of SymbolicVariables.
>
> >     class SymbolicVariables(SageObject):
> >         def __init__(self, prefix='x'):
> >             self._prefix = prefix
> >         def __getitem__(self, i):
> >             return var("%s%s"%(self._prefix, i))

> This has come up several times before on sage-devel, and I've always
> liked it.  For example, Nathann Cohen brought this up when he was first
> integrating the linear programming stuff.  I believe Robert Bradshaw
> suggested this "indexing creates a variable" approach a while ago too.
>
> When/if we wrap pynac vectors/matrices, though, or have "symbolic vector
> variables", we might have to be careful about how we treat the
> __getitem__ function.  I think in your case, where you explicitly are
> creating x with the understanding that indexing x creates new variables,
> things would be fine, though.

Not that it matters, but creating new symbols for indexed
variables seems to have some potential for unexpected behavior,
aside from cluttering the namespace.

Another approach is to represent an indexed variable as a
symbolic expression the same as an unevaluated function call,
but with an extra flag which essentially just shows it's
a subscripted expression instead of a function call.
(There isn't any real conceptual difference, right?
A subscripted variable is just a function on some countable
set.) That representation has the advantage that properties
of a collection of variables (e.g. x[1], x[2], ..., x[i])
can be associated with just the indexed symbol (x here).

There is an existing program which uses this scheme,
although it doesn't matter which one it is, so I won't
bother to mention it.

FWIW

Robert Dodier

-- 
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

To unsubscribe, reply using "remove me" as the subject.

Reply via email to