Ask Your Question
0

Why does a polynomial become an element of a fraction field?

asked 1 year ago

HT gravatar image

updated 1 year ago

I have a multivariate polynomial f in x1,x2,x3,x4,x5,x6,x7 on a field k=GF2(a) and 2 lists z1=[1,a,0,x4,x5,0,0], z2=[1,a,0,a,a+1,x6,x7]. When I run f(z1), I have a polynomial, but with f(z2), I receive FractionFieldElement. So I can call f(z1).constant_coefficient(), but I could not do the same with f(z2).

F2=GF(2); Rr.<x> = F2[]
k.<a> = F2.extension(x^2+x+1) # looks like bad syntax: the dot in "F." on the left side
v=3
o1=2
o2=2
n=v+o1+o2
R=PolynomialRing(k,["x%d" %i for i in range (1,n+1)])
x=R.gens()
Fc=[] # o1 polynomials in the first layer
for im in range(o1):  # what's o1? Sorry, when I pasted, some mistakes appeared but I didn't control them
     f=0
     for i in range (v): # what's v?
          for j in range (i,v+o1):
                f+=k.random_element()*x[i]*x[j]
     for i in range (n-o2):
              f+=k.random_element()*x[i]
         f+=k.random_element()
         Fc.append(f)
for im in range(o1,o1+o2):
      f=0
      for i in range (v+o1):
           for j in range (i,n):
                f+=k.random_element()*x[i]*x[j]
      for i in range (n):
            f+=k.random_element()*x[i]
      f+=k.random_element()
      Fc.append(f)
w=vector([k.random_element() for i in range (o1+o2)])    
Fn=[R.random_element() for i in range (o1)]
while True:
        y_rd=[k.random_element() for j in range (v)]
        y=y_rd+[x[jj] for jj in range (v,v+o1)]+[0 for jjj in range (v+o1,n)]
        bc=[]
        Colist=[]
        for i in range (o1):
             Fn[i]=Fc[i](y)
             cc=w[i]-(Fn[i].constant_coefficient())
             bc.append(cc)
        mbc=vector(bc)
        for i in range (o1):
             Colist.append(Fn[i].coefficient(x[j]) for j in range (v,v+o1))
        Mtx=matrix(Colist)
        if rank(Mtx.augment(mbc))==rank(Mtx):
                break
yb=Mtx.solve_right(mbc)
ybb=list(yb)
zz1=y_rd+ybb
print(y)
for i in range (o1+o2):
      print(Fc[i])
      print(Fc[i](y))
      print(type(Fc[i](y)))
print('-----------------------------------------')
yy=zz1+[x[i] for i in range (v+o1,n)]
print(yy)
for i in range (o1+o2):
      print(Fc[i])
      print(Fc[i](yy))
      print(type(Fc[i](yy)))
Preview: (hide)

Comments

1

Please provide details about how you defined everything so that we can try to reproduce and troubleshoot the issue.

John Palmieri gravatar imageJohn Palmieri ( 1 year ago )

while True: y_rd=[k.random_element() for j in range (v)] y=y_rd+[x[jj] for jj in range (v,v+o1)]+[0 for jjj in range (v+o1,n)] bc=[] Colist=[] for i in range (o1): Fn[i]=Fci

    cc=w[i]-(Fn[i].constant_coefficient())
    bc.append(cc)
mbc=vector(bc)
for i in range (o1):
    Colist.append(Fn[i].coefficient(x[j]) for j in range (v,v+o1))
Mtx=matrix(Colist)
if rank(Mtx.augment(mbc))==rank(Mtx):
        break

yb=Mtx.solve_right(mbc) ybb=list(yb) zz1=y_rd+ybb print(y) for i in range (o1+o2): print(Fc[i]) print(Fci) print(type(Fci)) print('-----------------------------------------')

HT gravatar imageHT ( 1 year ago )

yy=zz1+[x[i] for i in range (v+o1,n)] print(yy) for i in range (o1+o2): print(Fc[i]) print(Fci) print(type(Fci))

HT gravatar imageHT ( 1 year ago )

Please edit the actual question to add this information; it's really hard to read like this.

John Palmieri gravatar imageJohn Palmieri ( 1 year ago )

1 Answer

Sort by » oldest newest most voted
1

answered 1 year ago

Max Alekseyev gravatar image

updated 1 year ago

In short, the reason for appearance of FractionFieldElements is the base ring of matrix Mtx, which is R, making Sage think it divides polynomials.

The easiest solution in this case is to use method .monomial_coefficient() instead of .coefficient() for extracting polynomial coefficients so that they will be in k rather than in R.

Preview: (hide)
link

Comments

Many thanks!

HT gravatar imageHT ( 1 year ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 1 year ago

Seen: 288 times

Last updated: Nov 19 '23