Ask Your Question
0

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

asked 2023-11-13 18:28:58 +0200

HT gravatar image

updated 2023-11-19 02:00:11 +0200

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)))
edit retag flag offensive close merge delete

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 ( 2023-11-13 19:47:46 +0200 )edit

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 ( 2023-11-14 21:44:28 +0200 )edit

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 ( 2023-11-14 21:46:06 +0200 )edit

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

John Palmieri gravatar imageJohn Palmieri ( 2023-11-14 22:18:19 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-11-19 05:49:22 +0200

Max Alekseyev gravatar image

updated 2023-11-19 06:15:46 +0200

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.

edit flag offensive delete link more

Comments

Many thanks!

HT gravatar imageHT ( 2023-11-26 16:05:35 +0200 )edit

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: 2023-11-13 18:28:58 +0200

Seen: 195 times

Last updated: Nov 19 '23