On Jun 7, 2009, at 15:23 , amps wrote:

>
> sorry, i meant
>
> g.subs({z[1]:value1...})
>
> I am not sure why you call this intriguing syntax, but it is what
> works.

My turn to say sorry.  I just mentally wiped out the '.subs' part.

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

Yup; the {x:i...} syntax is creating a dictionary, which doesn't work  
where you use it here (it does work in procedure calls, since that's  
how variable binding is done).

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

More or less like I indicated below:
    L = [i for i in range(n)]
    v = g(L)

There is some nuance to what you are doing above.  In the first place,  
z is a 'tuple', and as such, immutable, so the assignment 'z[i]=i'  
won't work.

In the second, even if it did, you are assigning values to the  
variables that define the ring R, not to the "variables" defining the  
polynomial g.

You may already know this, but I'm pointing it out for clarity.

Doing something like I suggest will get you what you want, I think.   
No need to use "g.subs()".

Think of it this way: R is defined in (say) the outer block (drawing  
an analogy with block structured languages), while the computation  
that g() implements is an inner block, so you want to assign values to  
those variables in the calling sequence, not in the block where R is  
defined.

HTH

Justin

>
> On 7 June, 21:48, "Justin C. Walker" <jus...@mac.com> 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
>> --------
> >

--
Justin C. Walker
Curmudgeon-at-large
Director
Institute for the Absorption of Federal Funds
----
186,000 Miles per Second
Not just a good idea:
   it's the law!
----


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to