That's a pretty wild and crazy idea. Cool. Does any other math
software do that?
Are there any obvious gotcha's?
William
I think any system where things are left unevaluated can do something
like this. For example, I know people who use this in Maple to have
polynomials infinitely many variables. We have something like this in
Sage now:
sage: R.<x> = InfinitePolynomialRing(QQ)
sage: x[0] + x[100]
x100 + x0
I would still like to use __getitem__ to return the operands of a
symbolic expression. Since symbols have no operands, these two things
aren't totally incompatible.
--Mike
So as far as printing, a[0] would look the same as a0 would look the
same as a_0? Would a[0] actually be the variable a_0 or a0?
Do we ever want to make symbolic expressions indexable? If so, it would
be confusing to have:
(x+1)[0]
have totally different behavior than
(x)[0].
Jason
P.S. It seems like Maple did something like this---Maple experts can
comment on it, though.
--
Jason Grout
-1 to the a_3. That goes against all of the slicing conventions in Python.
It is kind of a cool idea, though. I'd like some time to try it out
before committing one way or the other.
What about having a "experiment mode" in Sage that turns on things like
this? Some variable in some module somewhere that people can set to
switch on some experimental behavior so they can test it out and give
feedback. In other words, setting sage.misc.misc.EXPERIMENT_MODE=True
turns it on.
Jason
--
Jason Grout
> William Stein wrote:
>> On Wed, Jun 3, 2009 at 11:45 AM, Robert Bradshaw
>> <robe...@math.washington.edu> wrote:
>>> Currently symbolic variables are un-indexable. What would people
>>> think of having indexing create new subscripted variables?
>>>
>>> sage: a = var('a')
>>> sage: a[0]
>>> a_0
>>> sage: latex(a[1,2])
>>> a_{1,2}
>>
>> That's a pretty wild and crazy idea. Cool. Does any other math
>> software do that?
>> Are there any obvious gotcha's?
>
> So as far as printing, a[0] would look the same as a0 would look the
> same as a_0? Would a[0] actually be the variable a_0 or a0?
I'm not sure. My first intent was that a[0] would actually be a0, but
it's unclear how to format multiple indices (I'd want a[1, 23] != a
[12, 3]). Also, should we support a[i]? Then I'd want a[i].subs(i=5)
== a[5]. What about v[5].subs(v=vector(range(10)))?
> Do we ever want to make symbolic expressions indexable? If so, it
> would
> be confusing to have:
>
> (x+1)[0]
>
> have totally different behavior than
>
> (x)[0].
They're not now. Having both would be confusing. I'd vote for the
latter--if (x+1)[0] worked, would it be the same as (1+x)[0], or (x+1-
x)[0]?
Answering your question about experimental mode, you're talking about
something easier and more permanent than applying a patch from trac?
Would people start depending on it, meaning we can't remove it
without sacrificing backwards compatibility (despite the name
"experimental")?
- Robert
There is some pdf cut-and-paste corruption of the example above. The
correct Maple code is:
with(combinat):
P:=(d,x,y)->add(add(a[i,j]*x**i*y**j,i=0..d-j),j=0..d);
V:=d->{seq(seq(a[i,j],i=0..d-j),j=0..d)};
E:=d->{seq(P(d,fibonacci(n),fibonacci(n+1)),n=1..nops(V(d))+5) };
Q:=(d,x,y)->subs(solve(E(d),V(d)),P(d,x,y));
A more direct translation to Sage might be something like this:
sage: P=lambda d,x,y: sum([ sum([ var("a"+str(i)+str(j))*x^i*y^j for i
in [0..d-j]]) for j in [0..d]])
sage: V=lambda d:sum([[var("a"+str(i)+str(j)) for i in [0..d-j]] for j
in [0..d]],[])
sage: E=lambda d: [ P(d,fibonacci(n),fibonacci(n+1)) for n in [1..len(V(d))+5] ]
sage: Q=lambda d,x,y:P(d,x,y).subs_expr(solve(E(d),V(d),solution_dict=True)[0])
sage: Q(1,x,y)
0
sage: Q(2,x,y)
0
sage: Q(3,x,y)
0
sage: Q(4,x,y).factor()
r21*(-y^2 + x*y + x^2 - 1)*(-y^2 + x*y + x^2 + 1)
Regards,
Bill Page.
Two options:
(1) Just type inject_on() and then aij will be defined:
sage: inject_on()
Redefining: FiniteField Frac FractionField FreeMonoid GF
LaurentSeriesRing NumberField PolynomialRing quo quotient
sage: Inds = CartesianProduct(range(5), range(5))
sage: vars = ["a"+str(i)+str(j) for i,j in Inds]
sage: PolynomialRing(QQ,25,vars)
Defining a00, a01, a02, a03, a04, a10, a11, a12, a13, a14, a20, a21,
a22, a23, a24, a30, a31, a32, a33, a34, a40, a41, a42, a43, a44
Multivariate Polynomial Ring in a00, a01, a02, a03, a04, a10, a11,
a12, a13, a14, a20, a21, a22, a23, a24, a30, a31, a32, a33, a34, a40,
a41, a42, a43, a44 over Rational Field
sage: a00 + a01
a00 + a01
sage: (a00 + a01)^3
a00^3 + 3*a00^2*a01 + 3*a00*a01^2 + a01^3
(2) Edit the globals dictionary:
sage: Inds = CartesianProduct(range(5), range(5))
sage: vars = ["a"+str(i)+str(j) for i,j in Inds]
sage: R = PolynomialRing(QQ,25,vars)
sage: for v in R.gens(): globals()[str(v)] = v
....:
sage: (a00 + a01)^3
a00^3 + 3*a00^2*a01 + 3*a00*a01^2 + a01^3