Ask Your Question

andriam's profile - activity

2020-08-24 19:47:36 -0500 received badge  Popular Question (source)
2020-08-14 06:04:20 -0500 received badge  Nice Question (source)
2020-08-13 13:45:18 -0500 asked a question In Sage Notebook, does sage compile all programs in a cell ?

Sometimes, in Sagenotebook, when I put many programs in the same cell, for example, the definition of a class, methods within this class and functions , it seems that Sage compiles the class defintions and methods, but ignores the functions.

2020-08-13 08:13:18 -0500 marked best answer does sage allow computation of a groebner basis of an ideal J in the quotient ring Z/pZ[X_1,...X_r]/I?

I define the following rings and ideals:

sage: F = ZZ.quo(3*ZZ); F
Ring of integers modulo 3

sage: A.<X, Y, Z> = PolynomialRing(F); A
Multivariate Polynomial Ring in X, Y, Z
over Ring of integers modulo 3

sage: I = ideal(X^2 - 1, Y^2 - 1, Z^2 - 1); I
Ideal (X^2 + 2, Y^2 + 2, Z^2 + 2)
of Multivariate Polynomial Ring in X, Y, Z
over Ring of integers modulo 3

sage: R = A.quotient_ring(I); R
Quotient of Multivariate Polynomial Ring in X, Y, Z
over Ring of integers modulo 3
by the ideal (X^2 + 2, Y^2 + 2, Z^2 + 2)

sage: x, y, z = R.gens()

sage: J = ideal(x*y + z, x + x*z, x*z + y); J
Ideal (Xbar*Ybar + Zbar, Xbar*Zbar + Xbar, Xbar*Zbar + Ybar)
of Quotient of Multivariate Polynomial Ring in X, Y, Z
over Ring of integers modulo 3
by the ideal (X^2 + 2, Y^2 + 2, Z^2 + 2)

I then compute:

sage: B = J.groebner_basis()

and examine the result of that computation:

sage: B
[Xbar + 2*Ybar, Zbar + 1]

Is it really the Groebner basis of J?

Did Sage really compute in A/I and not in A?

2020-08-13 08:12:03 -0500 marked best answer how to delete all programs, inputs and output in the sage console ?

I've tried all commands I know : reset(), !clear, %clear i, -ipython history clear, ipython history trim, --ipython locate profile default to clear history in my sage console but all of these do not work ,

,

2020-08-13 08:11:00 -0500 marked best answer 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.

2020-08-13 08:10:15 -0500 marked best answer how to evaluate a polynomial in a quotient ring ?

I define a polynomial ring and its quotient by an ideal:

sage: F = ZZ.quo(3*ZZ); F
Ring of integers modulo 3
sage: A.<X, Y, Z> = PolynomialRing(F); A
Multivariate Polynomial Ring in X, Y, Z
over Ring of integers modulo 3
sage: R.<x, y, z> = A.quotient(ideal(X^2 - 1, Y^2 - 1, Z^2 - 1)); R
Quotient of Multivariate Polynomial Ring in X, Y, Z
over Ring of integers modulo 3
by the ideal (X^2 + 2, Y^2 + 2, Z^2 + 2)

I define an element in this quotient ring:

sage: f = x*y*z; f
x*y*z
sage: f.parent()
Quotient of Multivariate Polynomial Ring in X, Y, Z
over Ring of integers modulo 3
by the ideal (X^2 + 2, Y^2 + 2, Z^2 + 2)

I want to evaluate this element at $(x, y, z) = (2, 3, 4)$.

I tried this, and got this error message:

sage: f(2, 3, 4)
Traceback (most recent call last)
...
TypeError: 'QuotientRing_generic_with_category.element_class' object is not callable

How can I calculate f(2, 3, 4) with Sage?

2020-08-13 08:09:27 -0500 marked best answer how to get the coefficient of a multivariate polynomial with respect to a specific variable and degree, in a quotient ring ?

Here is what I tried.

sage: F = ZZ.quo(3*ZZ); F
sage: A.<X, Y, Z> = PolynomialRing(F); A
sage: R.<x, y, z> = A.quotient(ideal(X^2 - 1, Y^2 - 1, Z^2 - 1))
sage: f = x*z + x*y*z + y + 1
sage: f.coefficient(z, 1)
sage: f.coefficient({z: 1})
sage: f.coeffcient(z)
2020-08-13 08:06:54 -0500 received badge  Supporter (source)
2020-08-13 08:06:32 -0500 marked best answer How to make Sage know that a set is an ideal

I have constructed the following ideal

J = {0, x*y*z - x*y - x*z + y*z - x + y - z, x*z - y*z - x + y - 1, x*y*z + x*y + x*z + y*z - z - 1, x*y + x*z + x - y + z, -x*y*z - x*y + x*z - y*z - x - y - z, ....}

in the ring

$$ R = F[X,Y,Z]/(X^2-1,Y^2-1,Z^2-1) $$

where $F=GF(3)$ and $x$ (resp; $y$, $z$) is the residue class of $X$ (resp. $Y$, $Z$) modulo the ideal $(X^2-1, Y^2-1, Z^2-1)$. By its construction, the set $J$ is indeed an ideal, containing 2187 elements, so it is hard to write or copy all its elements. I want to find a Groebner basis of $J$, by writing

B = J.groebner_basis(),

but Sage returns

TypeError: R must be a commutative ring.

This error seems to mean that Sage doesn' t remember that $J$ is the above set anymore and consider $J$ as an inappropriate new objet of a new ring $R$!

I must first construct the ideal

H = ideal(0, x*y*z - x*y - x*z + y*z - x + y - z, x*z - y*z - x + y - 1, x*y*z + x*y + x*z + y*z - z - 1, x*y + x*z + x - y + z, -x*y*z - x*y + x*z - y*z - x - y - z, ....)

and then compute

B = H.groebner_basis().

That works, but, as I previously said, it is not easy to construct the ideal $H$ because that needs copy and paste 2187 elements!

Therefore I'd like to know whether there is another way to the task, without copying and pasting all of the elements of $J$, and declaring the ideal of these elements, is there a way to convert a set of elements in a ring (which is already an ideal) to the underlying ideal?

2020-08-13 08:06:32 -0500 received badge  Scholar (source)
2020-08-13 03:55:15 -0500 commented question How to make Sage know that a set is an ideal

Strangely, when I write the Sage programs in the text editor of Asksage, the line containing "def" (for example def vect2pol(c,Vars in the preceeding code) is outside of the box containing the remaining part of the program. Can you explain how to correct it ?

2020-08-13 03:45:33 -0500 commented answer How to make Sage know that a set is an ideal

Strangely, the method groebner_basis() works for an ideal in the quotient ring R (see the above example, in the comments in response to slelievre). Perhaps, as you have said, Sage use the lift() method to compute a Gröbner basis in $F3[X,Y,Z]$ and the returned to $R$. I was confused when I first used this for ideals in quotient ring, this is why I asked the question "Does sage allow computation of a groebner basis of an ideal J in the quotient ring Z/pZ[X_1,...X_r]/I?

2020-08-13 03:35:49 -0500 commented question How to make Sage know that a set is an ideal

The set $J$ is then those of the polynomials of $R$ which vanishes on ${(1,2,1)}$ (It may be not be equal to the initial $J$ in my question), but that doesn't matter, it also contains 2187 elements). Using the command nbruin gave below, I entered

J1=ideal(*J);J1

B=J1.groebner_basis();B

and Sage returned

[x - 1, y + 1, z - 1].

The problem is solved : $J1$ is the ideal whose elements are the same as those of $J$ and no copy and paste were needeed!

2020-08-13 02:55:22 -0500 commented question How to make Sage know that a set is an ideal

For the construction of the POLS, I used the following program :

def vect2pol(c,Vars):

       n=len(c)
       po=0
       for i in range(n):
           po=po+c[i]*Vars[i]
       return po

where : c is a tuple of an element from a finite field

Vars a list of monomials with the same length as c

for example

list2pol((1, 2, 1, 2, 0, 0, 1, 1),[1, z, y, yz, x, xz, xy, xy*z])

produces

xyz + xy - yz + y - z + 1.

In my case, POLS is the list of elements of $R$. I first construct the cartesian product $F3^8$ :

S=Set(list(cartesian_product([F3]*8))).

Then I apply the function vect2pol to the elements of S, with Vars =[1, z, y, yz, x, xz, xy, xy*z]:

POLS={vect2pol(c,Vars) for c in S ... (more)

2020-08-13 02:30:05 -0500 commented answer How to make Sage know that a set is an ideal

Thank you very much, the command you give works : using the ideal $J$ from above, I write

H=ideal(*J)

then

B =H.groebner_basis()

and Sage return the result! No copy and paste of the elements of $J$ are needed, wonderful !

2020-08-13 00:21:28 -0500 commented question How to make Sage know that a set is an ideal

Thank for your remarks, the set $F$ is the finite field $GF(3)$ as you knew. The ideal $J$ is a "multicyclic code" of dimension $3$, and is equal the set of polynomials of $R$ which vanishes on a finite subset of $F^3$. Here is the code :

def code(POLS,ZER):

     C=Set({})
     for f in ENS:
         V={f.lift()(c) for c in POLS}
         if V=={0}:
            C=C+Set({f})                        
     return C

In my case, POLS is the set of polynomials of $R$ ( of degree $\leqslant (1,1)$, using the lexicographical order) and ZER a subset of $F^3$ consisting of a unique element. More time is needed to provide the codes for constructing POLS, I will provide these latter on.