On Thursday, August 21, 2014 8:52:36 AM UTC-7, juaninf wrote:

>     q = 2
>     nvars = 2
>     k.<t> = GF(2^q)
>     Xi = []
>     xij = []
>     for i in range(nvars):
>         Xi.append(var('X'+str(i)))
>         for j in range(q):
>             xij.append(var('x'+str(i)+''+str(j)))
>


You never use these as "var", so it would probably be better to just create 
them as strings, i.e., just delete the "var".
Note that the second line gets problematic once you go to 11: what does 
x111 mean? Is it x_{1,11} or is it x_{11,1}? 

    Xi.append(t)         
>     P = PolynomialRing(k,names=Xi)
>     R = PolynomialRing(k,names=xij)
>     S = PolynomialRing(R,'t')
>     p = P.random_element(degree=2)
>     subsvar = [sum((t^i*R.gen(i+q*j) for i in range(q))) for j in 
> range(nvars)]
>     subsvar.append(t)
>     p =  p(subsvar)
>
 
you now have two objects called "t": the generator of k over GF(2) and a 
polynomial variable in P as well as S. That could cause some trouble. 

Anyway, the following seems to do what you ask, but I doubt it is what you 
need. Shouldn't R and S be defined over GF(2) instead of over k?

sum([S(a.polynomial())*b for a,b in p(subsvar)])

Also, it sort of "happens" to work, because apparently sage prefers to map 
the variable "t" you get from a.polynomial() (which lives in GF(2)['t']) to 
the polynomial variable t in S rather than to the generator t of k over 
GF(2). There's really no good reason why sage should choose one or the 
other.

If instead you *don't* append 't' to Xi and do:

sage: P = PolynomialRing(k,names=Xi)
sage: R = PolynomialRing(GF(2),names=xij)
sage: S = PolynomialRing(R,'t')
sage: p = P.random_element(degree=2)
sage: subsvar = [sum((t^i*R.gen(i+q*j) for i in range(q))) for j in 
range(nvars)]
sage: sum([S(a.polynomial())*R(b) for a,b in p(subsvar)])

there is no ambiguity, you do end up with a polynomial in 
GF(2)[x00,...,x11][t], and I think the efficiency isn't so bad (there may 
be implementation inefficiencies, but the work done here is roughly what 
needs to happen anyway). Note the key step of "lifting" an element of k to 
an element in GF(2)['t']. Also note that you have to explicitly push the 
monomial b into R.

If this is not efficient enough, you should probably go all the way and do 
the requisite manipulations on {exponent-vector: coefficient} dictionaries. 
In that case you might want to write the loops in specialized cython too.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to