#11576: make it possible to generate sequences of variables easily
-------------------------------+--------------------------------------------
Reporter: kcrisman | Owner: burcin
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-5.11
Component: symbolics | Resolution:
Keywords: Cernay2012 | Work issues:
Report Upstream: N/A | Reviewers:
Authors: | Merged in:
Dependencies: | Stopgaps:
-------------------------------+--------------------------------------------
Changes (by vbraun):
* status: new => needs_review
Old description:
> People are ''always'' asking how to get sequences of variables, like
> `a1,a2,a3,a4` or the like. See [http://ask.sagemath.org/question/611
> /implicitly-defining-a-sequence-of-variables this ask.sagemath.org]
> question, for example.
>
> Jason Grout has an interesting possible solution that should find a home
> somewhere in Sage.
> {{{
>
> class VariableGenerator(object):
> def __init__(self, prefix):
> self.__prefix = prefix
> @cached_method
> def __getitem__(self, key):
> return SR.var("%s%s"%(self.__prefix,key))
> Now just specify a prefix, and then you can index to your heart's
> content to generate variables.
> a=VariableGenerator('a') # some people may like 'a_' as the prefix
> a[0], a[1], a[2] # all variables
> Of course, this can easily be extended to using function call syntax:
> a(0), or to using multiple indices: a[1,3]. Indeed, you can let your
> imagination run wild and even do things like return full symbolic
> matrices or vectors with slices: a[0:5, 0:5].
> }}}
New description:
People are ''always'' asking how to get sequences of variables, like
`a1,a2,a3,a4` or the like. See [http://ask.sagemath.org/question/611
/implicitly-defining-a-sequence-of-variables this ask.sagemath.org]
question, for example.
Jason Grout has an interesting possible solution that should find a home
somewhere in Sage.
{{{
class VariableGenerator(object):
def __init__(self, prefix):
self.__prefix = prefix
@cached_method
def __getitem__(self, key):
return SR.var("%s%s"%(self.__prefix,key))
Now just specify a prefix, and then you can index to your heart's
content to generate variables.
a=VariableGenerator('a') # some people may like 'a_' as the prefix
a[0], a[1], a[2] # all variables
Of course, this can easily be extended to using function call syntax:
a(0), or to using multiple indices: a[1,3]. Indeed, you can let your
imagination run wild and even do things like return full symbolic
matrices or vectors with slices: a[0:5, 0:5].
}}}
Apply [attachment:trac_11576-indexed_expression.patch]
--
Comment:
Rebased on top of Sage-5.10.rc2
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11576#comment:27>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.