本文整理汇总了Python中sage.interfaces.gap.gap.eval函数的典型用法代码示例。如果您正苦于以下问题:Python eval函数的具体用法?Python eval怎么用?Python eval使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了eval函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProjectiveGeometryDesign
def ProjectiveGeometryDesign(n, d, F, algorithm=None):
"""
Returns a projective geometry design.
A projective geometry design of parameters `n,d,F` has for points the lines
of `F^{n+1}`, and for blocks the `d+1`-dimensional subspaces of `F^{n+1}`,
each of which contains `\\frac {|F|^{d+1}-1} {|F|-1}` lines.
INPUT:
- ``n`` is the projective dimension
- ``d`` is the dimension of the subspaces of `P = PPn(F)` which
make up the blocks.
- ``F`` is a finite field.
- ``algorithm`` -- set to ``None`` by default, which results in using Sage's
own implementation. In order to use GAP's implementation instead (i.e. its
``PGPointFlatBlockDesign`` function) set ``algorithm="gap"``. Note that
GAP's "design" package must be available in this case, and that it can be
installed with the ``gap_packages`` spkg.
EXAMPLES:
The points of the following design are the `\\frac {2^{2+1}-1} {2-1}=7`
lines of `\mathbb{Z}_2^{2+1}`. It has `7` blocks, corresponding to each
2-dimensional subspace of `\mathbb{Z}_2^{2+1}`::
sage: designs.ProjectiveGeometryDesign(2, 1, GF(2))
Incidence structure with 7 points and 7 blocks
sage: BD = designs.ProjectiveGeometryDesign(2, 1, GF(2), algorithm="gap") # optional - gap_packages (design package)
sage: BD.is_block_design() # optional - gap_packages (design package)
(True, [2, 7, 3, 1])
"""
q = F.order()
from sage.interfaces.gap import gap, GapElement
from sage.sets.set import Set
if algorithm is None:
V = VectorSpace(F, n+1)
points = list(V.subspaces(1))
flats = list(V.subspaces(d+1))
blcks = []
for p in points:
b = []
for i in range(len(flats)):
if p.is_subspace(flats[i]):
b.append(i)
blcks.append(b)
v = (q**(n+1)-1)/(q-1)
return BlockDesign(v, blcks, name="ProjectiveGeometryDesign")
if algorithm == "gap": # Requires GAP's Design
gap.load_package("design")
gap.eval("D := PGPointFlatBlockDesign( %s, %s, %d )"%(n,q,d))
v = eval(gap.eval("D.v"))
gblcks = eval(gap.eval("D.blocks"))
gB = []
for b in gblcks:
gB.append([x-1 for x in b])
return BlockDesign(v, gB, name="ProjectiveGeometryDesign")
示例2: WittDesign
def WittDesign(n):
"""
INPUT:
- ``n`` is in `9,10,11,12,21,22,23,24`.
Wraps GAP Design's WittDesign. If ``n=24`` then this function returns the
large Witt design `W_{24}`, the unique (up to isomorphism) `5-(24,8,1)`
design. If ``n=12`` then this function returns the small Witt design
`W_{12}`, the unique (up to isomorphism) `5-(12,6,1)` design. The other
values of `n` return a block design derived from these.
.. NOTE:
Requires GAP's Design package (included in the gap_packages Sage spkg).
EXAMPLES::
sage: BD = designs.WittDesign(9) # optional - gap_packages (design package)
sage: BD.is_t_design(return_parameters=True) # optional - gap_packages (design package)
(True, (2, 9, 3, 1))
sage: BD # optional - gap_packages (design package)
Incidence structure with 9 points and 12 blocks
sage: print BD # optional - gap_packages (design package)
Incidence structure with 9 points and 12 blocks
"""
from sage.interfaces.gap import gap, GapElement
gap.load_package("design")
gap.eval("B:=WittDesign(%s)"%n)
v = eval(gap.eval("B.v"))
gblcks = eval(gap.eval("B.blocks"))
gB = []
for b in gblcks:
gB.append([x-1 for x in b])
return BlockDesign(v, gB, name="WittDesign", check=True)
示例3: dual
def dual(self, algorithm=None):
"""
Return the dual of the incidence structure.
INPUT:
- ``algorithm`` -- whether to use Sage's implementation
(``algorithm=None``, default) or use GAP's (``algorithm="gap"``).
.. NOTE::
The ``algorithm="gap"`` option requires GAP's Design package
(included in the gap_packages Sage spkg).
EXAMPLES:
The dual of a projective plane is a projective plane::
sage: PP = designs.DesarguesianProjectivePlaneDesign(4)
sage: PP.dual().is_t_design(return_parameters=True)
(True, (2, 21, 5, 1))
TESTS::
sage: D = designs.IncidenceStructure(4, [[0,2],[1,2,3],[2,3]])
sage: D
Incidence structure with 4 points and 3 blocks
sage: D.dual()
Incidence structure with 3 points and 4 blocks
sage: print D.dual(algorithm="gap") # optional - gap_packages
IncidenceStructure<points=[0, 1, 2], blocks=[[0], [0, 1, 2], [1], [1, 2]]>
sage: blocks = [[0,1,2],[0,3,4],[0,5,6],[1,3,5],[1,4,6],[2,3,6],[2,4,5]]
sage: BD = designs.IncidenceStructure(7, blocks, name="FanoPlane");
sage: BD
Incidence structure with 7 points and 7 blocks
sage: print BD.dual(algorithm="gap") # optional - gap_packages
IncidenceStructure<points=[0, 1, 2, 3, 4, 5, 6], blocks=[[0, 1, 2], [0, 3, 4], [0, 5, 6], [1, 3, 5], [1, 4, 6], [2, 3, 6], [2, 4, 5]]>
sage: BD.dual()
Incidence structure with 7 points and 7 blocks
REFERENCE:
- Soicher, Leonard, Design package manual, available at
http://www.gap-system.org/Manuals/pkg/design/htm/CHAP003.htm
"""
if algorithm == "gap":
from sage.interfaces.gap import gap
gap.load_package("design")
gD = self._gap_()
gap.eval("DD:=DualBlockDesign("+gD+")")
v = eval(gap.eval("DD.v"))
gblcks = eval(gap.eval("DD.blocks"))
gB = []
for b in gblcks:
gB.append([x-1 for x in b])
return IncidenceStructure(range(v), gB, name=None, check=False)
else:
return IncidenceStructure(
incidence_matrix=self.incidence_matrix().transpose(),
check=False)
示例4: AffineGeometryDesign
def AffineGeometryDesign(n, d, F):
r"""
Return an Affine Geometry Design.
INPUT:
- `n` (integer) -- the Euclidean dimension. The number of points is
`v=|F^n|`.
- `d` (integer) -- the dimension of the (affine) subspaces of `P = GF(q)^n`
which make up the blocks.
- `F` -- a Finite Field (i.e. ``FiniteField(17)``), or a prime power
(i.e. an integer)
`AG_{n,d} (F)`, as it is sometimes denoted, is a `2` - `(v, k, \lambda)`
design of points and `d`- flats (cosets of dimension `n`) in the affine
geometry `AG_n (F)`, where
.. math::
v = q^n,\ k = q^d ,
\lambda =\frac{(q^{n-1}-1) \cdots (q^{n+1-d}-1)}{(q^{n-1}-1) \cdots (q-1)}.
Wraps some functions used in GAP Design's ``PGPointFlatBlockDesign``. Does
*not* require GAP's Design package.
EXAMPLES::
sage: BD = designs.AffineGeometryDesign(3, 1, GF(2))
sage: BD.is_t_design(return_parameters=True)
(True, (2, 8, 2, 1))
sage: BD = designs.AffineGeometryDesign(3, 2, GF(2))
sage: BD.is_t_design(return_parameters=True)
(True, (3, 8, 4, 1))
With an integer instead of a Finite Field::
sage: BD = designs.AffineGeometryDesign(3, 2, 4)
sage: BD.is_t_design(return_parameters=True)
(True, (2, 64, 16, 5))
"""
try:
q = int(F)
except TypeError:
q = F.order()
from sage.interfaces.gap import gap, GapElement
from sage.sets.set import Set
gap.eval("V:=GaloisField(%s)^%s"%(q,n))
gap.eval("points:=AsSet(V)")
gap.eval("Subs:=AsSet(Subspaces(V,%s));"%d)
gap.eval("CP:=Cartesian(points,Subs)")
flats = gap.eval("flats:=List(CP,x->Sum(x))") # affine spaces
gblcks = eval(gap.eval("Set(List(flats,f->Filtered([1..Length(points)],i->points[i] in f)));"))
v = q**n
gB = []
for b in gblcks:
gB.append([x-1 for x in b])
return BlockDesign(v, gB, name="AffineGeometryDesign")
示例5: invariant_quadratic_form
def invariant_quadratic_form(self):
"""
This wraps GAP's command "InvariantQuadraticForm". From the GAP
documentation:
INPUT:
- ``self`` - a matrix group G
OUTPUT:
- ``Q`` - the matrix satisfying the property: The
quadratic form q on the natural vector space V on which G acts is
given by `q(v) = v Q v^t`, and the invariance under G is
given by the equation `q(v) = q(v M)` for all
`v \in V` and `M \in G`.
EXAMPLES::
sage: G = GO( 4, GF(7), 1)
sage: G.invariant_quadratic_form()
[0 1 0 0]
[0 0 0 0]
[0 0 3 0]
[0 0 0 1]
"""
F = self.base_ring()
G = self._gap_init_()
cmd = "r := InvariantQuadraticForm("+G+")"
gap.eval(cmd)
cmd = "r.matrix"
Q = gap(cmd)
return Q._matrix_(F)
示例6: dual_incidence_structure
def dual_incidence_structure(self, algorithm=None):
"""
Wraps GAP Design's DualBlockDesign (see [1]). The dual of a block
design may not be a block design.
Also can be called with ``dual_design``.
.. NOTE:
The algorithm="gap" option requires GAP's Design package (included in
the gap_packages Sage spkg).
EXAMPLES::
sage: from sage.combinat.designs.block_design import BlockDesign
sage: D = BlockDesign(4, [[0,2],[1,2,3],[2,3]], test=False)
sage: D
Incidence structure with 4 points and 3 blocks
sage: D.dual_design()
Incidence structure with 3 points and 4 blocks
sage: print D.dual_design(algorithm="gap") # optional - gap_design
IncidenceStructure<points=[0, 1, 2], blocks=[[0], [0, 1, 2], [1], [1, 2]]>
sage: BD = IncidenceStructure(range(7),[[0,1,2],[0,3,4],[0,5,6],[1,3,5],[1,4,6],[2,3,6],[2,4,5]], name="FanoPlane")
sage: BD
Incidence structure with 7 points and 7 blocks
sage: print BD.dual_design(algorithm="gap") # optional - gap_design
IncidenceStructure<points=[0, 1, 2, 3, 4, 5, 6], blocks=[[0, 1, 2], [0, 3, 4], [0, 5, 6], [1, 3, 5], [1, 4, 6], [2, 3, 6], [2, 4, 5]]>
sage: BD.dual_incidence_structure()
Incidence structure with 7 points and 7 blocks
REFERENCE:
- Soicher, Leonard, Design package manual, available at
http://www.gap-system.org/Manuals/pkg/design/htm/CHAP003.htm
"""
from sage.interfaces.gap import gap, GapElement
from sage.sets.set import Set
from sage.misc.flatten import flatten
from sage.combinat.designs.block_design import BlockDesign
from sage.misc.functional import transpose
if algorithm == "gap":
gap.load_package("design")
gD = self._gap_()
gap.eval("DD:=DualBlockDesign(" + gD + ")")
v = eval(gap.eval("DD.v"))
gblcks = eval(gap.eval("DD.blocks"))
gB = []
for b in gblcks:
gB.append([x - 1 for x in b])
return IncidenceStructure(range(v), gB, name=None, test=False)
pts = self.blocks()
M = transpose(self.incidence_matrix())
blks = self.points()
return IncidenceStructure(pts, blks, M, name=None, test=False)
示例7: AffineGeometryDesign
def AffineGeometryDesign(n, d, F):
r"""
INPUT:
- ``n`` is the Euclidean dimension, so the number of points is
- ``v`` is the number of points `v = |F^n|` (`F = GF(q)`, some `q`)
- `d` is the dimension of the (affine) subspaces of `P = GF(q)^n` which make
up the blocks.
`AG_{n,d} (F)`, as it is sometimes denoted, is a `2` - `(v, k, \lambda)`
design of points and `d`- flats (cosets of dimension `n`) in the affine
geometry `AG_n (F)`, where
.. math::
v = q^n,\ k = q^d ,
\lambda =\frac{(q^{n-1}-1) \cdots (q^{n+1-d}-1)}{(q^{n-1}-1) \cdots (q-1)}.
Wraps some functions used in GAP Design's PGPointFlatBlockDesign.
Does *not* require GAP's Design.
EXAMPLES::
sage: BD = designs.AffineGeometryDesign(3, 1, GF(2))
sage: BD.parameters()
(2, 8, 2, 2)
sage: BD.is_block_design()
(True, [2, 8, 2, 2])
sage: BD = designs.AffineGeometryDesign(3, 2, GF(2))
sage: BD.parameters()
(2, 8, 4, 12)
sage: BD.is_block_design()
(True, [3, 8, 4, 4])
"""
q = F.order()
from sage.interfaces.gap import gap, GapElement
from sage.sets.set import Set
gap.eval("V:=GaloisField(%s)^%s"%(q,n))
gap.eval("points:=AsSet(V)")
gap.eval("Subs:=AsSet(Subspaces(V,%s));"%d)
gap.eval("CP:=Cartesian(points,Subs)")
flats = gap.eval("flats:=List(CP,x->Sum(x))") # affine spaces
gblcks = eval(gap.eval("AsSortedList(List(flats,f->Filtered([1..Length(points)],i->points[i] in f)));"))
v = q**n
gB = []
for b in gblcks:
gB.append([x-1 for x in b])
return BlockDesign(v, gB, name="AffineGeometryDesign")
示例8: ProjectiveGeometryDesign
def ProjectiveGeometryDesign(n, d, F, algorithm=None):
"""
INPUT:
- ``n`` is the projective dimension
- ``v`` is the number of points `PPn(GF(q))`
- ``d`` is the dimension of the subspaces of `P = PPn(GF(q))` which
make up the blocks
- ``b`` is the number of `d`-dimensional subspaces of `P`
Wraps GAP Design's PGPointFlatBlockDesign. Does *not* require
GAP's Design.
EXAMPLES::
sage: designs.ProjectiveGeometryDesign(2, 1, GF(2))
Incidence structure with 7 points and 7 blocks
sage: BD = designs.ProjectiveGeometryDesign(2, 1, GF(2), algorithm="gap") # optional - gap_packages (design package)
sage: BD.is_block_design() # optional - gap_packages (design package)
(True, [2, 7, 3, 1])
"""
q = F.order()
from sage.interfaces.gap import gap, GapElement
from sage.sets.set import Set
if algorithm == None:
V = VectorSpace(F, n+1)
points = list(V.subspaces(1))
flats = list(V.subspaces(d+1))
blcks = []
for p in points:
b = []
for i in range(len(flats)):
if p.is_subspace(flats[i]):
b.append(i)
blcks.append(b)
v = (q**(n+1)-1)/(q-1)
return BlockDesign(v, blcks, name="ProjectiveGeometryDesign")
if algorithm == "gap": # Requires GAP's Design
gap.load_package("design")
gap.eval("D := PGPointFlatBlockDesign( %s, %s, %d )"%(n,q,d))
v = eval(gap.eval("D.v"))
gblcks = eval(gap.eval("D.blocks"))
gB = []
for b in gblcks:
gB.append([x-1 for x in b])
return BlockDesign(v, gB, name="ProjectiveGeometryDesign")
示例9: points_from_gap
def points_from_gap(self):
"""
Literally pushes this block design over to GAP and returns the
points of that. Other than debugging, usefulness is unclear.
REQUIRES: GAP's Design package.
EXAMPLES::
sage: from sage.combinat.designs.block_design import BlockDesign
sage: BD = BlockDesign(7,[[0,1,2],[0,3,4],[0,5,6],[1,3,5],[1,4,6],[2,3,6],[2,4,5]])
sage: BD.points_from_gap() # optional - gap_packages (design package)
doctest:1: DeprecationWarning: Unless somebody protests this method will be removed, as nobody seems to know why it is there.
See http://trac.sagemath.org/14499 for details.
[1, 2, 3, 4, 5, 6, 7]
"""
from sage.misc.superseded import deprecation
deprecation(14499, ('Unless somebody protests this method will be '
'removed, as nobody seems to know why it is there.'))
from sage.interfaces.gap import gap, GapElement
from sage.sets.set import Set
gap.load_package("design")
gD = self._gap_()
gP = gap.eval("BlockDesignPoints("+gD+")").replace("..",",")
return range(eval(gP)[0],eval(gP)[1]+1)
示例10: _gap_latex_
def _gap_latex_(self):
r"""
Return the GAP latex version of this matrix.
AUTHORS:
- S. Kohl: Wrote the GAP function.
EXAMPLES::
sage: F = GF(3); MS = MatrixSpace(F,2,2)
sage: gens = [MS([[1,0],[0,1]]),MS([[1,1],[0,1]])]
sage: G = MatrixGroup(gens)
sage: g = G([[1, 1], [0, 1]])
sage: print g._gap_latex_()
\left(\begin{array}{rr}%
Z(3)^{0}&Z(3)^{0}\\%
0*Z(3)&Z(3)^{0}\\%
\end{array}\right)%
Type view(g._latex_()) to see the object in an xdvi window
(assuming you have latex and xdvi installed).
"""
s1 = self.__mat._gap_init_()
s2 = gap.eval("LaTeX(" + s1 + ")")
return eval(s2)
示例11: points_from_gap
def points_from_gap(self):
"""
Literally pushes this block design over to GAP and returns the
points of that. Other than debugging, usefulness is unclear.
REQUIRES: GAP's Design package.
EXAMPLES::
sage: from sage.combinat.designs.block_design import BlockDesign
sage: BD = BlockDesign(7,[[0,1,2],[0,3,4],[0,5,6],[1,3,5],[1,4,6],[2,3,6],[2,4,5]])
sage: BD.points_from_gap() # optional - gap_packages (design package)
[1, 2, 3, 4, 5, 6, 7]
"""
from sage.interfaces.gap import gap, GapElement
from sage.sets.set import Set
gap.eval('LoadPackage("design")')
gD = self._gap_()
gP = gap.eval("BlockDesignPoints("+gD+")").replace("..",",")
return range(eval(gP)[0],eval(gP)[1]+1)
示例12: WittDesign
def WittDesign(n):
"""
Input: n is in 9,10,11,12,21,22,23,24.
Wraps GAP Design's WittDesign. If n=24 then this function returns
the large Witt design W24, the unique (up to isomorphism)
5-(24,8,1) design. If n=12 then this function returns the small
Witt design W12, the unique (up to isomorphism) 5-(12,6,1) design.
The other values of n return a block design derived from these.
REQUIRES: GAP's Design package.
EXAMPLES::
sage: BD = WittDesign(9) # optional - gap_packages (design package)
sage: BD.parameters() # optional - gap_packages (design package)
(2, 9, 3, 1)
sage: BD # optional - gap_packages (design package)
Incidence structure with 9 points and 12 blocks
sage: print BD # optional - gap_packages (design package)
WittDesign<points=[0, 1, 2, 3, 4, 5, 6, 7, 8], blocks=[[0, 1, 7], [0, 2, 5], [0, 3, 4], [0, 6, 8], [1, 2, 6], [1, 3, 5], [1, 4, 8], [2, 3, 8], [2, 4, 7], [3, 6, 7], [4, 5, 6], [5, 7, 8]]>
sage: BD = WittDesign(12) # optional - gap_packages (design package)
sage: BD.parameters(t=5) # optional - gap_packages (design package)
(5, 12, 6, 1)
"""
from sage.interfaces.gap import gap, GapElement
gap.eval('LoadPackage("design")')
gap.eval("B:=WittDesign(%s)"%n)
v = eval(gap.eval("B.v"))
gblcks = eval(gap.eval("B.blocks"))
gB = []
for b in gblcks:
gB.append([x-1 for x in b])
return BlockDesign(v, gB, name="WittDesign", test=True)
示例13: __init__
def __init__(self, homset, imgsH, check=True):
MatrixGroupMorphism.__init__(self, homset) # sets the parent
G = homset.domain()
H = homset.codomain()
gaplist_gens = [gap(x) for x in G.gens()]
gaplist_imgs = [gap(x) for x in imgsH]
genss = '[%s]'%(','.join(str(v) for v in gaplist_gens))
imgss = '[%s]'%(','.join(str(v) for v in gaplist_imgs))
args = '%s, %s, %s, %s'%(G._gap_init_(), H._gap_init_(), genss, imgss)
self._gap_str = 'GroupHomomorphismByImages(%s)'%args
phi0 = gap(self)
if gap.eval("IsGroupHomomorphism(%s)"%phi0.name())!="true":
raise ValueError,"The map "+str(gensG)+"-->"+str(imgsH)+" isn't a homomorphism."
示例14: pushforward
def pushforward(self, J, *args,**kwds):
"""
The image of an element or a subgroup.
INPUT:
``J`` -- a subgroup or an element of the domain of ``self``.
OUTPUT:
The image of ``J`` under ``self``
NOTE:
``pushforward`` is the method that is used when a map is called on
anything that is not an element of its domain. For historical reasons,
we keep the alias ``image()`` for this method.
EXAMPLES::
sage: F = GF(7); MS = MatrixSpace(F,2,2)
sage: F.multiplicative_generator()
3
sage: G = MatrixGroup([MS([3,0,0,1])])
sage: a = G.gens()[0]^2
sage: phi = G.hom([a])
sage: phi.image(G.gens()[0]) # indirect doctest
[2 0]
[0 1]
sage: H = MatrixGroup([MS(a.list())])
sage: H
Matrix group over Finite Field of size 7 with 1 generators:
[[[2, 0], [0, 1]]]
The following tests against trac ticket #10659::
sage: phi(H) # indirect doctestest
Matrix group over Finite Field of size 7 with 1 generators:
[[[4, 0], [0, 1]]]
"""
phi = gap(self)
F = self.codomain().base_ring()
from sage.all import MatrixGroup
gapJ = gap(J)
if gap.eval("IsGroup(%s)"%gapJ.name()) == "true":
return MatrixGroup([x._matrix_(F) for x in phi.Image(gapJ).GeneratorsOfGroup()])
return phi.Image(gapJ)._matrix_(F)
示例15: character_table
def character_table(self):
"""
Returns the GAP character table as a string. For larger tables you
may preface this with a command such as
gap.eval("SizeScreen([120,40])") in order to widen the screen.
EXAMPLES::
sage: print WeylGroup(['A',3]).character_table()
CT1
<BLANKLINE>
2 3 2 2 . 3
3 1 . . 1 .
<BLANKLINE>
1a 4a 2a 3a 2b
<BLANKLINE>
X.1 1 -1 -1 1 1
X.2 3 1 -1 . -1
X.3 2 . . -1 2
X.4 3 -1 1 . -1
X.5 1 1 1 1 1
"""
return gap.eval("Display(CharacterTable(%s))" % gap(self).name())