# may an object in sage lose its type in a method within a class ?

Many thanks to @slelievre for his response and to @tmonteil for his comments. Here is the original Sage code. It and a little bit long but perhaps all these are useful to see what goes wrong:

class CCODEPARAM:
def __init__(self, liste_ent, prem, em):
self.liste_ent = liste_ent
self.prem = prem
self.em = em

def qu(CyclicCodeParam):
q = (CyclicCodeParam.prem)^(CyclicCodeParam.em)
return q

def long(CyclicCodeParam):
NN = CyclicCodeParam.liste_ent
r = len(NN)
n = 1
for i in range(r):
n = n * NN[i]
return n

def epsilon(CyclicCodeParam):
NN = CyclicCodeParam.liste_ent
from sage.arith.functions import LCM_list
eps = LCM_list(NN)
return eps

def t(CyclicCodeParam):
NN = CyclicCodeParam.liste_ent
p = CyclicCodeParam.prem
r = len(NN)
m = CyclicCodeParam.em
q = p^m
eps = CyclicCodeParam.epsilon()
k = 1
while not(mod(q^k-1, eps) == 0):
k += 1
return k

def cardn(CyclicCodeParam):
return (CyclicCodeParam.qu())^(CyclicCodeParam.long())

def Gqu(CyclicCodeParam):
Q = (CyclicCodeParam.qu())^(CyclicCodeParam.t())
return Q

def liste_groupes(CyclicCodeParam):
NN = CyclicCodeParam.liste_ent
r = len(NN)
Groupes = []
for i in range(r):
Groupes.append(Set(IntegerModRing(NN[i])))
return Groupes

def prod_groupes(CyclicCodeParam):
GR = CyclicCodeParam.liste_groupes()
GG = list(cartesian_product(tuple(GR)))
return GG

def corps(CyclicCodeParam):
F = GF((CyclicCodeParam.qu()))
FF = GF(CyclicCodeParam.Gqu())
return [F, FF]

def prim(CyclicCodeParam):
K = CyclicCodeParam.corps()
L = K[1]
a = L.multiplicative_generator()
return a

def primorderb(CyclicCodeParam):
Q = CyclicCodeParam.Gqu()
eps = CyclicCodeParam.epsilon()
a = CyclicCodeParam.prim()
b = a^((Q - 1) / eps)
return b

def primuroots(CyclicCodeParam):
NN = CyclicCodeParam.liste_ent
r = len(NN)
eps = CyclicCodeParam.epsilon()
b = CyclicCodeParam.primorderb()
e = []
for i in range(r):
e.append(b^(eps/NN[i]))
return e

def galois(CyclicCodeParam):
t = CyclicCodeParam.t()
q = CyclicCodeParam.qu()
MM = list(Set({q^nu for nu in range(t)}))
return MM

def orbites(CyclicCodeParam):
GG = CyclicCodeParam.prod_groupes()
MM = CyclicCodeParam.galois()
NN = CyclicCodeParam.liste_ent
O = orb(GG, MM, NN)
return O

def ambspace(CyclicCodeParam):
F = CyclicCodeParam.corps()[0]
n = CyclicCodeParam.long()
K = list(cartesian_product([F]*n))
return K

def zeros(PAR, A):
O = PAR.orbites()
Z = Set({O[i][0] for i in A})
return Z

def CCODE(PAR, A, Vars):
# order = 'lex'
CORPS = PAR.ambspace()
print type(CORPS)
Z = PAR.zeros(A)
# print Z
Exp = PAR.orbites()
# print Exp
e = PAR.epsilon()
print e
CODE = {Zvalpol2(c, Vars, Exp, e, Z) for c in CORPS}
return CODE

def oneorb(g, MM, NN):
O = Set({})
r = len(NN)
for u in MM:
B = []
for i in range(r):
B.append(mod((g[i])*u,NN[i]))
O = O.union(Set({tuple(B)}))
return O

def orb(GG, MM, NN):
Orb = Set({})
GG = Set(GG)
for g in GG:
t = oneorb(g,MM,NN)
Orb = Orb.union(Set({t}))
GG = GG.difference(Orb)
return Orb

def pol(c, Vars, Exp):
n = len(c)
m = len(Vars)
P = 0
M = []
for i in range(n):
M.append(0)
M = list(M)
for i in range(n):
M[i] = 1
for j in range(m):
M[i] *= Vars[j]**Exp[i][j]
for i in range(n):
P += c[i] * M[i]
return P

def Zvalpol2(c, Vars, Exp, e, Z):
P = pol(c, Vars, Exp)
print('poly')
r = len(Vars)
V = Set({})
for h in Z:
E = []
for i in range(r):
E.append(e[i]**h[i])
V = V + Set({P(tuple(E))})
if V == Set({0}):
mes2 = 'mot de code'
print mes2


In the fonction "CCODE", when constructing the objet "CORPS" by CORPS =PAR.ambspace(), Sage return "none" for its type, even though the fonction "ambspace" return the object "K", which is of type "list". As a consequence, when executing the function CCODE, Sage returns an error by saying that objet of nonetype (which is CORPS) is not iterable. This happens on the instruction above the "return CODE" in the function CCODE.

edit retag close merge delete

1

You should provide more code, in particular, how are F and n constructed.

( 2018-11-11 22:14:48 +0200 )edit

Sort by ยป oldest newest most voted

Only the Python object None has type NoneType.

Usually a return value of None means the function did not return anything.

This frequently happens when one defines a function which does a computation but forgets to return the result, as in:

def list_cartesian_product(F, n):
K = list(cartesian_product([F]*n))


def list_cartesian_product(F, n):
K = list(cartesian_product([F]*n))
return K

more

The set A is of the form

A =Set({ a_1,a_2,...,a_k})

where the a_i's are integer in the range 0,...,len(0), where len(O) is the length of O. for example, if len(O) =5, we may take A=Set({0,2,3}) .

Vars is a list of variables whose length is equal to that of liste_ent. Here are examples

PAR=CCODEPARAM( [ 2 , 2 ] , 3 , 1 ) ;PAR <__builtin__.CCODEPARAM instance at 0x7f3f482632d8>

O=PAR. o r b i t e s ( ) ;O {{(1, 1)}, {(1, 0)}, {(0, 0)}, {(0, 1)}}

A=Set ( { 1 , 3 } ) ;A {1, 3}

Here, liste_ent=[2,2], so we may put Vars=['x','y']. We call CCODE by

C=PAR.CCODE(A,['x','y']);C

The program is supposed to list all the polynomials in F_q[x,y] who vanish at the set Z=union of O[i] where i in A, which ...(more)

( 2018-11-13 10:31:53 +0200 )edit

the parameters of the class CCODEPARAM are :

liste_ent: a list of (small integers) , e.g [2,3] prem : a prime number which doesn't divide any of the integers in liste_ent e. g 5 em = a (small) integer, e;g 2

The monomials of the polynomials are of the form c*x^iy^j where 0<=i<=1, 0<=j<=2

( 2018-11-13 10:42:37 +0200 )edit