When I say that n is not predetermined, I mean that I want my script
to work for any n.  So before I define the polynomial ring, n is
determined, but I want this to work for all n.  So my question is how
do I do the following.

n=6
R=PolynomialRing(QQ,n,'z')
z=R.gens()
g=sum(z[i] for i in range(n))

now how would I substitute into g the values z[i]=i?  I want to keep n
as a variable.

On 7 June, 23:23, amps <[email protected]> wrote:
> sorry, i meant
>
> g.subs({z[1]:value1...})
>
> I am not sure why you call this intriguing syntax, but it is what
> works.
>
> Example:
> g=x+y
> g.subs({x:2,y:4})
> 6
>
> My problem is that I don't know how to do this if the number of
> variables is not predetermined.
> I tried to make a list with
> a=list()
> for i in range(n):
>         a.append(z[i]:value[i])
> but it does not like this kind of list (gives an error).
>
> you can think of it this way.  Suppose n is not predetermined.
> R=PolynomialRing(QQ,n,'z')
> z=R.gens()
> g=sum(z[i] for i in range(n))
>
> now how would I substitute into g the values z[i]=i?
> On 7 June, 21:48, "Justin C. Walker" <[email protected]> wrote:
>
> > On Jun 7, 2009, at 13:03 , amps wrote:
>
> > > I want to substitute n values into polynomial with n variables.
>
> > > I guess the syntax to do this is (if g is my polynomial with
> > > indeterminates z[1], ..., z[n]).
>
> > > f.subs({z[1]:value1, z[2]:value2, ..., z[n]:valuen})
>
> > > but how do I actually do this?  n is not set, so I just can't type
> > > this out.
>
> > That's intriguing syntax, but I don't think it will work.
>
> > Assuming that, at the call site, you know all your values, you can  
> > cobble up a tuple or list, something like the following:
>
> >    L = [f(i+1) for i in range(n)]
> >    print g(L)
>
> > You can do this to determine 'n', assuming you don't know it at the  
> > call site:
>
> >    n = len(g.variables())
>
> > HTH
>
> > Justin
>
> > --
> > Justin C. Walker, Curmudgeon-At-Large
> > Director
> > Institute for the Enhancement of the Director's Income
> > --------
> > "Weaseling out of things is what separates us from the animals.
> >   Well, except the weasel."
> >        - Homer J Simpson
> > --------
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to