Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/misc/citation.pyx
8814 views
1
from sage.misc.all import tmp_filename, preparse
2
from sage.env import SAGE_ROOT
3
4
systems = {}
5
systems['PARI'] = ['sage.libs.pari', 'sage.interfaces.gp']
6
systems['Singular'] = ['sage.interfaces.singular', '_libsingular',
7
'sage.libs.singular']
8
systems['Maxima'] = ['sage.interfaces.maxima']
9
systems['GAP'] = ['sage.interfaces.gap']
10
systems['Magma'] = ['sage.interfaces.magma', 'sage.interfaces.magma_free']
11
systems['Axiom'] = ['sage.interfaces.axiom']
12
systems['ECM'] = ['sage.interfaces.ecm']
13
systems['scipy'] = ['scipy']
14
systems['numpy'] = ['numpy']
15
systems['ginac'] = ['sage.symbolic']
16
systems['Maple'] = ['sage.interfaces.maple']
17
systems['Mathematica'] = ['sage.interfaces.mathematica']
18
systems['MuPAD'] = ['sage.interfaces.mupad']
19
systems['Octave'] = ['sage.interfaces.octave']
20
systems['povray'] = ['sage.interfaces.povray']
21
systems['qsieve'] = ['sage.interfaces.qsieve']
22
systems['Macaulay2'] = ['sage.interfaces.macaulay2']
23
systems['mwrank'] = ['sage.interfaces.mwrank', 'sage.libs.mwrank']
24
systems['matlab'] = ['sage.interfaces.matlab']
25
systems['LiE'] = ['sage.interfaces.lie']
26
systems['Tachyon'] = ['sage.interfaces.tachyon']
27
systems['Frobby'] = ['sage.interfaces.frobby']
28
systems['gfan'] = ['sage.interfaces.gfan']
29
systems['R'] = ['sage.interfaces.r']
30
systems['KASH'] = ['sage.interfaces.kash']
31
systems['Linbox'] = ['sage.libs.linbox']
32
systems['Symmetrica'] = ['sage.libs.symmetrica']
33
systems['NTL'] = ['sage.libs.ntl',
34
'sage.rings.finite_rings.element_ntl_gf2e']
35
systems['FLINT'] = ['_flint']
36
systems['GMP'] = ['sage.rings.integer.Integer']
37
systems['MPFR'] = ['sage.rings.real_mpfr',
38
'sage.rings.complex_number']
39
systems['MPFI'] = ['sage.rings.real_mpfi',
40
'sage.rings.complex_interval']
41
systems['M4RI'] = ['sage.matrix.matrix_mod2_dense']
42
systems['Givaro'] = ['sage.rings.finite_rings.element_givaro']
43
systems['PolyBoRi'] = ['sage.rings.polynomial.pbori']
44
45
def get_systems(cmd):
46
"""
47
Returns a list of the systems used in running the command
48
cmd. Note that the results can sometimes include systems
49
that did not actually contribute to the computation. Due
50
to caching and the inability to follow all C calls, it
51
could miss some dependencies as well.
52
53
INPUT:
54
55
- ``cmd`` - a string to run
56
57
EXAMPLES::
58
59
sage: from sage.misc.citation import get_systems
60
sage: s = get_systems('integrate(x^2, x)'); #priming coercion model
61
sage: get_systems('integrate(x^2, x)')
62
['ginac', 'Maxima']
63
sage: R.<x,y,z> = QQ[]
64
sage: I = R.ideal(x^2+y^2, z^2+y)
65
sage: get_systems('I.primary_decomposition()')
66
['Singular']
67
68
sage: a = var('a')
69
sage: get_systems('((a+1)^2).expand()')
70
['ginac', 'GMP']
71
"""
72
import cProfile, pstats, re
73
74
if not isinstance(cmd, basestring):
75
raise TypeError, "command must be a string"
76
77
cmd = preparse(cmd)
78
79
#Run the command and get the stats
80
filename = tmp_filename()
81
cProfile.runctx(cmd, globals(), {}, filename)
82
stats = pstats.Stats(filename)
83
84
#Strings is a list of method names and modules which get run
85
strings = [a[0].replace(SAGE_ROOT, "") + " " + a[2] for a in stats.stats.keys()]
86
87
#Remove trivial functions
88
bad_res = [re.compile(r'is_.*Element')]
89
for bad_re in bad_res:
90
i = 0
91
while i < len(strings):
92
if bad_re.findall(strings[i]):
93
strings.pop(i)
94
else:
95
i += 1
96
97
#Check to see which systems appear in the profiled run
98
systems_used = []
99
for system in systems:
100
if any([(r in s) or (r.replace('.','/') in s) for r in systems[system] for s in strings]):
101
systems_used.append(system)
102
return systems_used
103
104