Package sage :: Package crypto :: Package mq :: Module mpolynomialsystem :: Class MPolynomialSystem_generic
[hide private]
[frames] | no frames]

Class MPolynomialSystem_generic

source code

                      object --+    
                               |    
structure.sage_object.SageObject --+
                                   |
                                  MPolynomialSystem_generic
Known Subclasses:
MPolynomialSystem_gf2, MPolynomialSystem_gf2e

Instance Methods [hide private]
 
__init__(self, R, rounds)
Construct a new system of multivariate polynomials.
source code
 
__copy__(self)
Return a copy of self.
source code
 
__cmp__(self, other)
Compare the ring and rounds of self and other.
source code
 
ring(self)
Return base ring.
source code
 
ngens(self)
Return number polynomials in self...
source code
 
gens(self)
Return list of polynomials in self...
source code
 
gen(self, ij)
Return an element of self.
source code
 
nrounds(self)
Return number of rounds of self.
source code
 
rounds(self)
Return list of rounds of self.
source code
 
round(self, i)
Return $i$-th round of self.
source code
 
ideal(self)
Return SAGE ideal spanned by self.gens() EXAMPLE: These computations use pseudo-random numbers, so we set the seed for reproducible testing.
source code
 
groebner_basis(self, *args, **kwargs)
Compute and return a Groebner basis for self.
source code
 
monomials(self)
Return a list of monomials in self.
source code
 
nmonomials(self)
Return the number of monomials present in self.
source code
 
variables(self)
Return all variables present in self.
source code
 
nvariables(self)
Return number of variables present in self.
source code
 
coefficient_matrix(self, sparse=True)
Return tuple (A,v) where A is the coefficent matrix of self and v the matching monomial vector.
source code
 
subs(self, *args, **kwargs)
Substitute variables for every polynomial in self.
source code
 
_singular_(self)
Return SINGULAR ideal representation of this system.
source code
 
_magma_(self)
Return MAGMA ideal representation of this system as an ideal.
source code
 
_repr_(self)
Return a string representation of this system.
source code
 
__add__(self, right)
Add polynomial systems together, i.e.
source code
 
__getitem__(self, ij)
See \code{self.gen()}.
source code
 
__contains__(self, element)
Return \code{True} if element is in \code{self} or \code{False} else.
source code
 
__iter__(self)
Return an iterator for \code{self} where all polynomials in \code{self} are yielded in order as they appear in \code{self}.
source code

Inherited from structure.sage_object.SageObject: __hash__, __new__, __repr__, _axiom_, _axiom_init_, _gap_, _gap_init_, _gp_, _gp_init_, _interface_, _interface_init_, _interface_is_cached_, _kash_, _kash_init_, _macaulay2_, _macaulay2_init_, _magma_init_, _maple_, _maple_init_, _mathematica_, _mathematica_init_, _maxima_, _maxima_init_, _octave_, _octave_init_, _pari_, _pari_init_, _r_init_, _sage_, _singular_init_, category, db, dump, dumps, plot, rename, reset_name, save, version

Inherited from object: __delattr__, __getattribute__, __reduce__, __reduce_ex__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, R, rounds)
(Constructor)

source code 

Construct a new system of multivariate polynomials. That is, a
set of multivariate polynomials with at least one common root.

INPUT:
    arg1 -- a multivariate polynomial ring or an ideal
    arg2 -- an iterable object of rounds, preferable MPolynomialRoundSystem,
              or polynomials (default:None)

EXAMPLES:
    sage: P.<a,b,c,d> = PolynomialRing(GF(127),4)
    sage: I = sage.rings.ideal.Katsura(P)

    If a list of MPolynomialRoundSystems is provided those
    form the rounds.
    
    sage: mq.MPolynomialSystem(I.ring(), [mq.MPolynomialRoundSystem(I.ring(),I.gens())])
    Polynomial System with 4 Polynomials in 4 Variables

    If an ideal is provided the generators are used.
    
    sage: mq.MPolynomialSystem(I)
    Polynomial System with 4 Polynomials in 4 Variables

    If a list of polynomials is provided the system has only
    one round.

    sage: mq.MPolynomialSystem(I.ring(), I.gens())
    Polynomial System with 4 Polynomials in 4 Variables

Overrides: object.__init__

__copy__(self)

source code 

Return a copy of self. While this is not a deep copy only
mutable members of this system are copied.

EXAMPLE:
    sage: sr = mq.SR(allow_zero_inversions=True)
    sage: F,s = sr.polynomial_system()
    sage: copy(F) # indirect doctest
    Polynomial System with 40 Polynomials in 20 Variables

__cmp__(self, other)
(Comparison operator)

source code 

Compare the ring and rounds of self and other.

EXAMPLE:
    sage: sr = mq.SR(allow_zero_inversions=True)
    sage: F,s = sr.polynomial_system()
    sage: F == copy(F) # indirect doctest
    True

ring(self)

source code 

Return base ring.

EXAMPLE:
    sage: sr = mq.SR(allow_zero_inversions=True,gf2=True,order='block')
    sage: F,s = sr.polynomial_system()
    sage: print F.ring().repr_long()
    Polynomial Ring
     Base Ring : Finite Field of size 2
          Size : 20 Variables
      Block  0 : Ordering : degrevlex
                 Names    : k100, k101, k102, k103, x100, x101, x102, x103, w100, w101, w102, w103, s000, s001, s002, s003
      Block  1 : Ordering : degrevlex
                 Names    : k000, k001, k002, k003

ngens(self)

source code 

Return number polynomials in self

EXAMPLE:
    sage: sr = mq.SR(allow_zero_inversions=True,gf2=True,order='block')
    sage: F,s = sr.polynomial_system()
    sage: F.ngens()
    56

gens(self)

source code 

Return list of polynomials in self

EXAMPLE:
    sage: sr = mq.SR(allow_zero_inversions=True)
    sage: F,s = sr.polynomial_system()
    sage: l = F.gens()
    sage: len(l), type(l)
    (40, <type 'tuple'>)

gen(self, ij)

source code 

Return an element of self.

INPUT:
    ij -- tuple, slice, integer

EXAMPLES:
    sage: P.<a,b,c,d> = PolynomialRing(GF(127),4)
    sage: F = mq.MPolynomialSystem(sage.rings.ideal.Katsura(P))

    $ij$-th polynomial overall

    sage: F[0] # indirect doctest
    a + 2*b + 2*c + 2*d - 1
    
    $i$-th to $j$-th polynomial overall

    sage: F[0:2]
    [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a]

    $i$-th round, $j$-th polynomial
    
    sage: F[0,1]
    a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a

nrounds(self)

source code 

Return number of rounds of self.

EXAMPLE:
    sage: sr = mq.SR(allow_zero_inversions=True)
    sage: F,s = sr.polynomial_system()
    sage: F.nrounds()
    4

rounds(self)

source code 

Return list of rounds of self.

EXAMPLE:
    sage: sr = mq.SR(allow_zero_inversions=True)
    sage: F,s = sr.polynomial_system()
    sage: l = F.rounds()
    sage: len(l)
    4

round(self, i)

source code 

Return $i$-th round of self.

EXAMPLE:
    sage: sr = mq.SR(allow_zero_inversions=True)
    sage: F,s = sr.polynomial_system()
    sage: R0 = F.round(1)
    sage: R0
    [k000^2 + k001, k001^2 + k002, k002^2 + k003, k003^2 + k000]

ideal(self)

source code 

Return SAGE ideal spanned by self.gens()

EXAMPLE:
These computations use pseudo-random numbers, so we set the
seed for reproducible testing.
    sage: set_random_seed(0)

    sage: sr = mq.SR(allow_zero_inversions=True)
    sage: F,s = sr.polynomial_system()
    sage: P = F.ring()
    sage: I = F.ideal()
    sage: I.elimination_ideal(P('s000*s001*s002*s003*w100*w101*w102*w103*x100*x101*x102*x103'))
    Ideal (k002 + (a^2)*k003 + 1, (a^3)*k001 + (a^3 + a^2)*k003 + 
    (a^3 + a + 1), k000 + (a^3 + a^2 + a)*k003 + (a^3 + a^2 + a), 
    (a^2)*k103 + (a^2 + a)*k003 + (a^2 + a + 1), (a^3)*k102 + 
    (a^3 + 1)*k003 + (a^2), (a^3)*k101 + (a^3)*k003 + (a^2 + 1), 
    (a^3)*k100 + (a^2 + a)*k003 + (a^2 + 1), k003^2 + 
    (a^3 + a^2 + a)*k003 + (a^3 + a^2 + a)) of Multivariate 
    Polynomial Ring in k100, k101, k102, k103, x100, x101, x102, 
    x103, w100, w101, w102, w103, s000, s001, s002, s003, 
    k000, k001, k002, k003 over Finite Field in a of size 2^4

groebner_basis(self, *args, **kwargs)

source code 

Compute and return a Groebner basis for self.

INPUT:
    args -- list of arguments passed to MPolynomialIdeal.groebner_basis call
    kwargs -- dictionary of arguments passed to MPolynomialIdeal.groebner_basis call

EXAMPLE:
    sage: sr = mq.SR(allow_zero_inversions=True)
    sage: F,s = sr.polynomial_system()
    sage: gb = F.groebner_basis()
    sage: Ideal(gb).basis_is_groebner()
    True

monomials(self)

source code 

Return a list of monomials in self.

EXAMPLE:
    sage: sr = mq.SR(allow_zero_inversions=True)
    sage: F,s = sr.polynomial_system()
    sage: len(F.monomials())
    49

nmonomials(self)

source code 

Return the number of monomials present in self.

EXAMPLE:
    sage: sr = mq.SR(allow_zero_inversions=True)
    sage: F,s = sr.polynomial_system()
    sage: F.nmonomials()
    49

variables(self)

source code 

Return all variables present in self. This list may or may not
be equal to the generators of the ring of self.

EXAMPLE:
    sage: sr = mq.SR(allow_zero_inversions=True)
    sage: F,s = sr.polynomial_system()
    sage: F.variables()[:10]  # this output ordering depends on a hash and so might change if __hash__ changes
    [s000, k101, k100, s003, x102, x103, s002, w103, w102, x100]        # 32-bit
    [k101, k100, s003, x102, x103, s002, w103, w102, x100, x101]        # 64-bit

nvariables(self)

source code 

Return number of variables present in self.

EXAMPLE:
    sage: sr = mq.SR(allow_zero_inversions=True)
    sage: F,s = sr.polynomial_system()
    sage: F.nvariables()
    20

coefficient_matrix(self, sparse=True)

source code 

Return tuple (A,v) where A is the coefficent matrix of self
and v the matching monomial vector. Monomials are order w.r.t.
the term ordering of self.ring() in reverse order.

INPUT:
    sparse -- construct a sparse matrix (default: True)

EXAMPLE:
    sage: P.<a,b,c,d> = PolynomialRing(GF(127),4)
    sage: I = sage.rings.ideal.Katsura(P)
    sage: I.gens()
    (a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c
    + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c)

    sage: F = mq.MPolynomialSystem(I)
    sage: A,v = F.coefficient_matrix()
    sage: A
    [  0   0   0   0   0   0   0   0   0   1   2   2   2 126]
    [  1   0   2   0   0   2   0   0   2 126   0   0   0   0]
    [  0   2   0   0   2   0   0   2   0   0 126   0   0   0]
    [  0   0   1   2   0   0   2   0   0   0   0 126   0   0]
    
    sage: v
    [a^2]
    [a*b]
    [b^2]
    [a*c]
    [b*c]
    [c^2]
    [b*d]
    [c*d]
    [d^2]
    [  a]
    [  b]
    [  c]
    [  d]
    [  1]
    
    sage: A*v
    [        a + 2*b + 2*c + 2*d - 1]
    [a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a]
    [      2*a*b + 2*b*c + 2*c*d - b]
    [        b^2 + 2*a*c + 2*b*d - c]

subs(self, *args, **kwargs)

source code 

Substitute variables for every polynomial in self. See
MPolynomial.subs for calling convention.


EXAMPLE:
    sage: sr = mq.SR(allow_zero_inversions=True)
    sage: F,s = sr.polynomial_system(); F
    Polynomial System with 40 Polynomials in 20 Variables
    sage: F.subs(s); F
    Polynomial System with 40 Polynomials in 16 Variables

INPUT:
    args -- arguments to be passed to MPolynomial.subs
    kwargs -- keyword arguments to be passed to MPolynomial.subs

_singular_(self)

source code 

Return SINGULAR ideal representation of this system.

EXAMPLE:
    sage: P.<a,b,c,d> = PolynomialRing(GF(127))
    sage: I = sage.rings.ideal.Katsura(P)
    sage: F = mq.MPolynomialSystem(I); F
    Polynomial System with 4 Polynomials in 4 Variables
    sage: F._singular_()
    a+2*b+2*c+2*d-1,
    a^2+2*b^2+2*c^2+2*d^2-a,
    2*a*b+2*b*c+2*c*d-b,
    b^2+2*a*c+2*b*d-c

Overrides: structure.sage_object.SageObject._singular_

_magma_(self)

source code 

Return MAGMA ideal representation of this system as an ideal.

EXAMPLE:
    sage: sr = mq.SR(allow_zero_inversions=True,gf2=True)
    sage: F,s = sr.polynomial_system()
    sage: F._magma_() # optional, requires MAGMA

Overrides: structure.sage_object.SageObject._magma_

_repr_(self)

source code 

Return a string representation of this system.

EXAMPLE:
    sage: P.<a,b,c,d> = PolynomialRing(GF(127))
    sage: I = sage.rings.ideal.Katsura(P)
    sage: F = mq.MPolynomialSystem(I); F # indirect doctest
    Polynomial System with 4 Polynomials in 4 Variables

__add__(self, right)
(Addition operator)

source code 

Add polynomial systems together, i.e. create a union of their
polynomials.

EXAMPLE:
    sage: P.<a,b,c,d> = PolynomialRing(GF(127))
    sage: I = sage.rings.ideal.Katsura(P)
    sage: F = mq.MPolynomialSystem(I)
    sage: F + [a^127 + a]
    Polynomial System with 5 Polynomials in 4 Variables

    sage: F + P.ideal([a^127 + a])
    Polynomial System with 5 Polynomials in 4 Variables
    
    sage: F + mq.MPolynomialSystem(P,[a^127 + a])
    Polynomial System with 5 Polynomials in 4 Variables

__getitem__(self, ij)
(Indexing operator)

source code 

See \code{self.gen()}.

EXAMPLE:
    sage: P.<a,b,c,d> = PolynomialRing(GF(127),4)
    sage: F = mq.MPolynomialSystem(sage.rings.ideal.Katsura(P))

    $ij$-th polynomial overall

    sage: F[0] # indirect doctest
    a + 2*b + 2*c + 2*d - 1
    
    $i$-th to $j$-th polynomial overall

    sage: F[0:2]
    [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a]

    $i$-th round, $j$-th polynomial
    
    sage: F[0,1]
    a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a

__contains__(self, element)
(In operator)

source code 

Return \code{True} if element is in \code{self} or
\code{False} else. This method does not return an answer for
the ideal spanned by the generators of this system but
literately whether a polynomial is in the list of generators.

EXAMPLE:
    sage: P.<x0,x1,x2,x3> = PolynomialRing(GF(37))
    sage: I = sage.rings.ideal.Katsura(P)
    sage: F = mq.MPolynomialSystem(I)
    sage: f = x0 + 2*x1 + 2*x2 + 2*x3 -1 
    sage: f in F
    True
    sage: x0*f in F
    False
    sage: x0*f in F.ideal()
    True

__iter__(self)

source code 

Return an iterator for \code{self} where all polynomials in
\code{self} are yielded in order as they appear in \code{self}.

EXAMPLE:
    sage: P.<x0,x1,x2,x3> = PolynomialRing(GF(37))
    sage: I = sage.rings.ideal.Katsura(P)
    sage: F = mq.MPolynomialSystem(P,I.gens())
    sage: list(F)
    [x0 + 2*x1 + 2*x2 + 2*x3 - 1,
    x0^2 + 2*x1^2 + 2*x2^2 + 2*x3^2 - x0,
    2*x0*x1 + 2*x1*x2 + 2*x2*x3 - x1,
    x1^2 + 2*x0*x2 + 2*x1*x3 - x2]