Skip to content

Commit a7bc60c

Browse files
committed
using more libgap instead of gap
1 parent 80f6d77 commit a7bc60c

File tree

4 files changed

+34
-37
lines changed

4 files changed

+34
-37
lines changed

src/sage/arith/misc.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -377,22 +377,18 @@ def bernoulli(n, algorithm='default', num_threads=1):
377377
warn("flint is known to not be accurate for large Bernoulli numbers")
378378
from sage.libs.flint.arith import bernoulli_number as flint_bernoulli
379379
return flint_bernoulli(n)
380-
elif algorithm == 'pari':
380+
elif algorithm == 'pari' or algorithm == 'gp':
381381
from sage.libs.pari.all import pari
382382
x = pari(n).bernfrac() # Use the PARI C library
383383
return Rational(x)
384384
elif algorithm == 'gap':
385-
import sage.interfaces.gap
386-
x = sage.interfaces.gap.gap('Bernoulli(%s)' % n)
385+
from sage.libs.gap.libgap import libgap
386+
x = libgap.Bernoulli(n).sage()
387387
return Rational(x)
388388
elif algorithm == 'magma':
389389
import sage.interfaces.magma
390390
x = sage.interfaces.magma.magma('Bernoulli(%s)' % n)
391391
return Rational(x)
392-
elif algorithm == 'gp':
393-
import sage.interfaces.gp
394-
x = sage.interfaces.gp.gp('bernfrac(%s)' % n)
395-
return Rational(x)
396392
elif algorithm == 'bernmm':
397393
import sage.rings.bernmm
398394
return sage.rings.bernmm.bernmm_bern_rat(n, num_threads)
@@ -448,12 +444,10 @@ def factorial(n, algorithm='gmp'):
448444
sage: factorial(mpz(4))
449445
24
450446
451-
452447
PERFORMANCE: This discussion is valid as of April 2006. All timings
453448
below are on a Pentium Core Duo 2Ghz MacBook Pro running Linux with
454449
a 2.6.16.1 kernel.
455450
456-
457451
- It takes less than a minute to compute the factorial of
458452
`10^7` using the GMP algorithm, and the factorial of
459453
`10^6` takes less than 4 seconds.
@@ -482,7 +476,7 @@ def factorial(n, algorithm='gmp'):
482476
raise ValueError('unknown algorithm')
483477

484478

485-
def is_prime(n):
479+
def is_prime(n) -> bool:
486480
r"""
487481
Determine whether `n` is a prime element of its parent ring.
488482

src/sage/combinat/matrices/latin.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@
135135
from sage.matrix.matrix_integer_dense import Matrix_integer_dense
136136
from sage.groups.perm_gps.permgroup_element import PermutationGroupElement
137137
from sage.groups.perm_gps.constructor import PermutationGroupElement as PermutationConstructor
138-
from sage.interfaces.gap import GapElement
138+
from sage.libs.gap.libgap import libgap
139+
from sage.libs.gap.element import GapElement
139140
from sage.combinat.permutation import Permutation
140-
from sage.interfaces.gap import gap
141141
from sage.groups.perm_gps.permgroup import PermutationGroup
142142
from sage.arith.misc import is_prime
143143
from sage.rings.finite_rings.finite_field_constructor import FiniteField
@@ -2327,14 +2327,14 @@ def group_to_LatinSquare(G):
23272327
23282328
::
23292329
2330-
sage: G = gap.Group(PermutationGroupElement((1,2,3)))
2330+
sage: G = libgap.Group(PermutationGroupElement((1,2,3)))
23312331
sage: group_to_LatinSquare(G)
23322332
[0 1 2]
23332333
[1 2 0]
23342334
[2 0 1]
23352335
"""
23362336
if isinstance(G, GapElement):
2337-
rows = (list(x) for x in list(gap.MultiplicationTable(G)))
2337+
rows = (list(x) for x in list(libgap.MultiplicationTable(G)))
23382338
new_rows = []
23392339

23402340
for x in rows:
@@ -2454,15 +2454,15 @@ def p3_group_bitrade_generators(p):
24542454
24552455
sage: from sage.combinat.matrices.latin import *
24562456
sage: p3_group_bitrade_generators(3)
2457-
((2,6,7)(3,8,9), (1,2,3)(4,7,8)(5,6,9), (1,9,2)(3,7,4)(5,8,6), Permutation Group with generators [(2,6,7)(3,8,9), (1,2,3)(4,7,8)(5,6,9)])
2457+
((2,6,7)(3,8,9),
2458+
(1,2,3)(4,7,8)(5,6,9),
2459+
(1,9,2)(3,7,4)(5,8,6),
2460+
Permutation Group with generators [(2,6,7)(3,8,9), (1,2,3)(4,7,8)(5,6,9)])
24582461
"""
24592462
assert is_prime(p)
24602463

2461-
F = gap.new("FreeGroup(3)")
2462-
2463-
a = F.gen(1)
2464-
b = F.gen(2)
2465-
c = F.gen(3)
2464+
F = libgap.FreeGroup(3)
2465+
a, b, c = F.GeneratorsOfInverseSemigroup()
24662466

24672467
rels = []
24682468
rels.append(a**p)
@@ -2473,11 +2473,12 @@ def p3_group_bitrade_generators(p):
24732473
rels.append(c*b*((b*c)**(-1)))
24742474

24752475
G = F.FactorGroupFpGroupByRels(rels)
2476+
u, v, _ = G.GeneratorsOfInverseSemigroup()
24762477

2477-
iso = gap.IsomorphismPermGroup(G)
2478+
iso = libgap.IsomorphismPermGroup(G)
24782479

2479-
x = PermutationConstructor(gap.Image(iso, G.gen(1)))
2480-
y = PermutationConstructor(gap.Image(iso, G.gen(2)))
2480+
x = PermutationConstructor(libgap.Image(iso, u))
2481+
y = PermutationConstructor(libgap.Image(iso, v))
24812482

24822483
return (x, y, (x*y)**(-1), PermutationGroup([x, y]))
24832484

@@ -2504,7 +2505,7 @@ def check_bitrade_generators(a, b, c):
25042505
if a*b != c**(-1):
25052506
return False
25062507

2507-
X = gap.Intersection(gap.Intersection(A, B), C)
2508+
X = libgap.Intersection(libgap.Intersection(A, B), C)
25082509
return X.Size() == 1
25092510

25102511

@@ -2648,11 +2649,11 @@ def bitrade_from_group(a, b, c, G):
26482649
[ 2 1 3 -1]
26492650
[ 0 3 -1 2]
26502651
"""
2651-
hom = gap.ActionHomomorphism(G, gap.RightCosets(G, gap.TrivialSubgroup(G)), gap.OnRight)
2652+
hom = libgap.ActionHomomorphism(G, libgap.RightCosets(G, libgap.TrivialSubgroup(G)), libgap.OnRight)
26522653

2653-
t1 = gap.Image(hom, a)
2654-
t2 = gap.Image(hom, b)
2655-
t3 = gap.Image(hom, c)
2654+
t1 = libgap.Image(hom, a)
2655+
t2 = libgap.Image(hom, b)
2656+
t3 = libgap.Image(hom, c)
26562657

26572658
t1 = Permutation(str(t1).replace('\n', ''))
26582659
t2 = Permutation(str(t2).replace('\n', ''))

src/sage/combinat/root_system/weyl_group.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from sage.groups.perm_gps.permgroup import PermutationGroup_generic
4646
from sage.rings.integer_ring import ZZ
4747
from sage.rings.rational_field import QQ
48-
from sage.interfaces.gap import gap
48+
from sage.libs.gap.libgap import libgap
4949
from sage.misc.cachefunc import cached_method
5050
from sage.combinat.root_system.cartan_type import CartanType
5151
from sage.combinat.root_system.cartan_matrix import CartanMatrix
@@ -252,7 +252,6 @@ def __init__(self, domain, prefix):
252252
# FinitelyGeneratedMatrixGroup_gap takes plain matrices as input
253253
gens_matrix = [self.morphism_matrix(self.domain().simple_reflection(i))
254254
for i in self.index_set()]
255-
from sage.libs.gap.libgap import libgap
256255
if not gens_matrix:
257256
libgap_group = libgap.Group([], matrix(ZZ, 1, 1, [1]))
258257
else:
@@ -435,8 +434,8 @@ def character_table(self):
435434
X.4 3 -1 1 . -1
436435
X.5 1 1 1 1 1
437436
"""
438-
gens_str = ', '.join(str(g.gap()) for g in self.gens())
439-
ctbl = gap('CharacterTable(Group({0}))'.format(gens_str))
437+
G = libgap.Group([libgap(g) for g in self.gens()])
438+
ctbl = libgap.CharacterTable(G)
440439
return ctbl.Display()
441440

442441
@cached_method

src/sage/modular/arithgroup/arithgroup_perm.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,14 +1551,15 @@ def surgroups(self):
15511551
sage: l
15521552
[6, 3, 4, 8, 4, 8, 4, 12, 4, 6, 6, 8, 8]
15531553
"""
1554-
from sage.interfaces.gap import gap
1555-
P = self.perm_group()._gap_()
1554+
from sage.libs.gap.libgap import libgap
1555+
P = libgap(self.perm_group())
15561556
for b in P.AllBlocks():
1557-
orbit = P.Orbit(b, gap.OnSets)
1558-
action = P.Action(orbit, gap.OnSets)
1559-
S2,S3,L,R = action.GeneratorsOfGroup()
1557+
orbit = P.Orbit(b, libgap.OnSets)
1558+
action = P.Action(orbit, libgap.OnSets)
1559+
S2, S3, L, R = action.GeneratorsOfGroup()
15601560
yield ArithmeticSubgroup_Permutation(S2=S2, S3=S3, L=L, R=R, check=False)
15611561

1562+
15621563
class OddArithmeticSubgroup_Permutation(ArithmeticSubgroup_Permutation_class):
15631564
r"""
15641565
An arithmetic subgroup of `\SL(2, \ZZ)` not containing `-1`,
@@ -2635,6 +2636,7 @@ def odd_subgroups(self):
26352636

26362637
return res
26372638

2639+
26382640
def HsuExample10():
26392641
r"""
26402642
An example of an index 10 arithmetic subgroup studied by Tim Hsu.
@@ -2654,6 +2656,7 @@ def HsuExample10():
26542656
R="(1,7,9,10,6)(2,3)(4,5,8)",
26552657
relabel=False)
26562658

2659+
26572660
def HsuExample18():
26582661
r"""
26592662
An example of an index 18 arithmetic subgroup studied by Tim Hsu.

0 commit comments

Comments
 (0)