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