passagemath-repl 10.4.62__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. passagemath_repl-10.4.62.data/scripts/sage-cachegrind +25 -0
  2. passagemath_repl-10.4.62.data/scripts/sage-callgrind +16 -0
  3. passagemath_repl-10.4.62.data/scripts/sage-cleaner +230 -0
  4. passagemath_repl-10.4.62.data/scripts/sage-coverage +327 -0
  5. passagemath_repl-10.4.62.data/scripts/sage-eval +14 -0
  6. passagemath_repl-10.4.62.data/scripts/sage-fixdoctests +708 -0
  7. passagemath_repl-10.4.62.data/scripts/sage-inline-fortran +12 -0
  8. passagemath_repl-10.4.62.data/scripts/sage-ipynb2rst +50 -0
  9. passagemath_repl-10.4.62.data/scripts/sage-ipython +16 -0
  10. passagemath_repl-10.4.62.data/scripts/sage-massif +25 -0
  11. passagemath_repl-10.4.62.data/scripts/sage-notebook +267 -0
  12. passagemath_repl-10.4.62.data/scripts/sage-omega +25 -0
  13. passagemath_repl-10.4.62.data/scripts/sage-preparse +302 -0
  14. passagemath_repl-10.4.62.data/scripts/sage-run +27 -0
  15. passagemath_repl-10.4.62.data/scripts/sage-run-cython +10 -0
  16. passagemath_repl-10.4.62.data/scripts/sage-runtests +9 -0
  17. passagemath_repl-10.4.62.data/scripts/sage-startuptime.py +163 -0
  18. passagemath_repl-10.4.62.data/scripts/sage-valgrind +34 -0
  19. passagemath_repl-10.4.62.dist-info/METADATA +77 -0
  20. passagemath_repl-10.4.62.dist-info/RECORD +162 -0
  21. passagemath_repl-10.4.62.dist-info/WHEEL +5 -0
  22. passagemath_repl-10.4.62.dist-info/top_level.txt +1 -0
  23. sage/all__sagemath_repl.py +119 -0
  24. sage/doctest/__init__.py +4 -0
  25. sage/doctest/__main__.py +236 -0
  26. sage/doctest/all.py +4 -0
  27. sage/doctest/check_tolerance.py +261 -0
  28. sage/doctest/control.py +1727 -0
  29. sage/doctest/external.py +534 -0
  30. sage/doctest/fixtures.py +383 -0
  31. sage/doctest/forker.py +2665 -0
  32. sage/doctest/marked_output.py +102 -0
  33. sage/doctest/parsing.py +1708 -0
  34. sage/doctest/parsing_test.py +79 -0
  35. sage/doctest/reporting.py +733 -0
  36. sage/doctest/rif_tol.py +124 -0
  37. sage/doctest/sources.py +1657 -0
  38. sage/doctest/test.py +584 -0
  39. sage/doctest/tests/1second.rst +4 -0
  40. sage/doctest/tests/99seconds.rst +4 -0
  41. sage/doctest/tests/abort.rst +5 -0
  42. sage/doctest/tests/atexit.rst +7 -0
  43. sage/doctest/tests/fail_and_die.rst +6 -0
  44. sage/doctest/tests/initial.rst +15 -0
  45. sage/doctest/tests/interrupt.rst +7 -0
  46. sage/doctest/tests/interrupt_diehard.rst +14 -0
  47. sage/doctest/tests/keyboardinterrupt.rst +11 -0
  48. sage/doctest/tests/longtime.rst +5 -0
  49. sage/doctest/tests/nodoctest +5 -0
  50. sage/doctest/tests/random_seed.rst +4 -0
  51. sage/doctest/tests/show_skipped.rst +18 -0
  52. sage/doctest/tests/sig_on.rst +9 -0
  53. sage/doctest/tests/simple_failure.rst +8 -0
  54. sage/doctest/tests/sleep_and_raise.rst +106 -0
  55. sage/doctest/tests/tolerance.rst +31 -0
  56. sage/doctest/util.py +750 -0
  57. sage/interfaces/cleaner.py +48 -0
  58. sage/interfaces/quit.py +163 -0
  59. sage/misc/all__sagemath_repl.py +51 -0
  60. sage/misc/banner.py +235 -0
  61. sage/misc/benchmark.py +221 -0
  62. sage/misc/classgraph.py +131 -0
  63. sage/misc/copying.py +22 -0
  64. sage/misc/cython.py +694 -0
  65. sage/misc/dev_tools.py +745 -0
  66. sage/misc/edit_module.py +304 -0
  67. sage/misc/explain_pickle.py +3079 -0
  68. sage/misc/gperftools.py +361 -0
  69. sage/misc/inline_fortran.py +212 -0
  70. sage/misc/messaging.py +86 -0
  71. sage/misc/pager.py +21 -0
  72. sage/misc/profiler.py +179 -0
  73. sage/misc/python.py +70 -0
  74. sage/misc/remote_file.py +53 -0
  75. sage/misc/sage_eval.py +246 -0
  76. sage/misc/sage_input.py +3621 -0
  77. sage/misc/sagedoc.py +1742 -0
  78. sage/misc/sh.py +38 -0
  79. sage/misc/trace.py +90 -0
  80. sage/repl/__init__.py +16 -0
  81. sage/repl/all.py +15 -0
  82. sage/repl/attach.py +625 -0
  83. sage/repl/configuration.py +186 -0
  84. sage/repl/display/__init__.py +1 -0
  85. sage/repl/display/fancy_repr.py +354 -0
  86. sage/repl/display/formatter.py +318 -0
  87. sage/repl/display/jsmol_iframe.py +290 -0
  88. sage/repl/display/pretty_print.py +153 -0
  89. sage/repl/display/util.py +163 -0
  90. sage/repl/image.py +302 -0
  91. sage/repl/inputhook.py +91 -0
  92. sage/repl/interface_magic.py +298 -0
  93. sage/repl/interpreter.py +854 -0
  94. sage/repl/ipython_extension.py +593 -0
  95. sage/repl/ipython_kernel/__init__.py +1 -0
  96. sage/repl/ipython_kernel/__main__.py +4 -0
  97. sage/repl/ipython_kernel/all_jupyter.py +10 -0
  98. sage/repl/ipython_kernel/install.py +301 -0
  99. sage/repl/ipython_kernel/interact.py +278 -0
  100. sage/repl/ipython_kernel/kernel.py +217 -0
  101. sage/repl/ipython_kernel/widgets.py +466 -0
  102. sage/repl/ipython_kernel/widgets_sagenb.py +587 -0
  103. sage/repl/ipython_tests.py +163 -0
  104. sage/repl/load.py +326 -0
  105. sage/repl/preparse.py +2218 -0
  106. sage/repl/prompts.py +90 -0
  107. sage/repl/rich_output/__init__.py +4 -0
  108. sage/repl/rich_output/backend_base.py +648 -0
  109. sage/repl/rich_output/backend_doctest.py +316 -0
  110. sage/repl/rich_output/backend_emacs.py +151 -0
  111. sage/repl/rich_output/backend_ipython.py +596 -0
  112. sage/repl/rich_output/buffer.py +311 -0
  113. sage/repl/rich_output/display_manager.py +829 -0
  114. sage/repl/rich_output/example.avi +0 -0
  115. sage/repl/rich_output/example.canvas3d +1 -0
  116. sage/repl/rich_output/example.dvi +0 -0
  117. sage/repl/rich_output/example.flv +0 -0
  118. sage/repl/rich_output/example.gif +0 -0
  119. sage/repl/rich_output/example.jpg +0 -0
  120. sage/repl/rich_output/example.mkv +0 -0
  121. sage/repl/rich_output/example.mov +0 -0
  122. sage/repl/rich_output/example.mp4 +0 -0
  123. sage/repl/rich_output/example.ogv +0 -0
  124. sage/repl/rich_output/example.pdf +0 -0
  125. sage/repl/rich_output/example.png +0 -0
  126. sage/repl/rich_output/example.svg +54 -0
  127. sage/repl/rich_output/example.webm +0 -0
  128. sage/repl/rich_output/example.wmv +0 -0
  129. sage/repl/rich_output/example_jmol.spt.zip +0 -0
  130. sage/repl/rich_output/example_wavefront_scene.mtl +7 -0
  131. sage/repl/rich_output/example_wavefront_scene.obj +17 -0
  132. sage/repl/rich_output/output_basic.py +391 -0
  133. sage/repl/rich_output/output_browser.py +103 -0
  134. sage/repl/rich_output/output_catalog.py +54 -0
  135. sage/repl/rich_output/output_graphics.py +320 -0
  136. sage/repl/rich_output/output_graphics3d.py +345 -0
  137. sage/repl/rich_output/output_video.py +231 -0
  138. sage/repl/rich_output/preferences.py +432 -0
  139. sage/repl/rich_output/pretty_print.py +339 -0
  140. sage/repl/rich_output/test_backend.py +201 -0
  141. sage/repl/user_globals.py +214 -0
  142. sage/tests/__init__.py +1 -0
  143. sage/tests/all.py +3 -0
  144. sage/tests/article_heuberger_krenn_kropf_fsm-in-sage.py +630 -0
  145. sage/tests/arxiv_0812_2725.py +351 -0
  146. sage/tests/benchmark.py +1923 -0
  147. sage/tests/book_schilling_zabrocki_kschur_primer.py +795 -0
  148. sage/tests/book_stein_ent.py +651 -0
  149. sage/tests/book_stein_modform.py +558 -0
  150. sage/tests/cmdline.py +790 -0
  151. sage/tests/combinatorial_hopf_algebras.py +52 -0
  152. sage/tests/finite_poset.py +623 -0
  153. sage/tests/functools_partial_src.py +27 -0
  154. sage/tests/gosper-sum.py +218 -0
  155. sage/tests/lazy_imports.py +28 -0
  156. sage/tests/modular_group_cohomology.py +80 -0
  157. sage/tests/numpy.py +21 -0
  158. sage/tests/parigp.py +76 -0
  159. sage/tests/startup.py +27 -0
  160. sage/tests/symbolic-series.py +76 -0
  161. sage/tests/sympy.py +16 -0
  162. sage/tests/test_deprecation.py +31 -0
@@ -0,0 +1,1923 @@
1
+ # sage_setup: distribution = sagemath-repl
2
+ # sage.doctest: needs sage.symbolic
3
+ """
4
+ Benchmarks
5
+
6
+ COMMENTS:
7
+
8
+ Taken as a whole these benchmarks suggest that by far the fastest math
9
+ software is MAGMA, Mathematica, and Sage (with appropriate tuning and
10
+ choices -- it can also be very slow !). Maxima is very slow, at least
11
+ in the form that comes with Sage (perhaps this is because of using
12
+ clisp, at least partly). GP is slow at some thing and very fast at
13
+ others.
14
+
15
+ TESTS::
16
+
17
+ sage: import sage.tests.benchmark
18
+ """
19
+ from cysignals.alarm import alarm, cancel_alarm, AlarmInterrupt
20
+ from sage.combinat.combinat import fibonacci
21
+ from sage.functions.other import factorial
22
+ from sage.interfaces.gp import gp
23
+ from sage.interfaces.macaulay2 import macaulay2
24
+ from sage.interfaces.magma import magma, Magma
25
+ from sage.interfaces.maple import maple
26
+ from sage.interfaces.mathematica import mathematica
27
+ from sage.interfaces.maxima import maxima
28
+ from sage.interfaces.singular import singular
29
+ from sage.libs.pari import pari
30
+ from sage.libs.gap.libgap import libgap
31
+ from sage.matrix.matrix_space import MatrixSpace
32
+ from sage.misc.functional import log
33
+ from sage.misc.timing import cputime, walltime
34
+ from sage.modular.modsym.modsym import ModularSymbols
35
+ from sage.rings.complex_mpfr import ComplexField
36
+ from sage.rings.finite_rings.finite_field_constructor import GF
37
+ from sage.rings.finite_rings.integer_mod_ring import Integers
38
+ from sage.rings.rational_field import QQ
39
+ from sage.rings.integer import Integer
40
+ from sage.rings.integer_ring import ZZ
41
+ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
42
+ from sage.schemes.elliptic_curves.constructor import EllipticCurve
43
+
44
+
45
+ def avg(X):
46
+ """
47
+ Return the average of the list X.
48
+
49
+ EXAMPLES::
50
+
51
+ sage: from sage.tests.benchmark import avg
52
+ sage: avg([1,2,3])
53
+ 2.0
54
+ """
55
+ s = sum(X, 0)
56
+ return s / float(len(X))
57
+
58
+
59
+ STD_SYSTEMS = ['sage', 'maxima', 'libgap', 'gp', 'pari', 'python']
60
+ OPT_SYSTEMS = ['magma', 'macaulay2', 'maple', 'mathematica']
61
+
62
+
63
+ class Benchmark:
64
+ """
65
+ A class for running specific benchmarks against different systems.
66
+
67
+ In order to implement an extension of this class, one must write
68
+ functions named after the different systems one wants to test. These
69
+ functions must perform the same task for each function. Calling
70
+ the run command with a list of systems will then show the timings.
71
+
72
+ EXAMPLES::
73
+
74
+ sage: from sage.tests.benchmark import Benchmark
75
+ sage: B = Benchmark()
76
+ sage: def python():
77
+ ....: t = cputime()
78
+ ....: 2+2
79
+ ....: return cputime(t)
80
+ sage: B.python = python
81
+ sage: B.run(systems=['python'])
82
+ sage.tests.benchmark.Benchmark instance
83
+ System min avg max trials cpu or wall
84
+ * python ...
85
+ """
86
+ def run(self, systems=None, timeout=60, trials=1, sort=False, optional=False):
87
+ """
88
+ Run the benchmarking functions for the current benchmark on the systems
89
+ given.
90
+
91
+ INPUT:
92
+
93
+ - ``systems`` -- (optional) list of strings of which systems to run tests on;
94
+ if ``None``, runs the standard systems
95
+ - ``timeout`` -- integer (default: 60); how long (in seconds)
96
+ to run each test for
97
+ - ``trials`` -- integer (default: 1); number of trials
98
+ - ``sort`` -- boolean (default: ``False``); whether to sort system names
99
+ - ``optional`` -- boolean (default: ``False``); if systems is ``None``,
100
+ whether to test optional systems
101
+
102
+ EXAMPLES::
103
+
104
+ sage: from sage.tests.benchmark import PolyFactor
105
+ sage: PolyFactor(10, QQ).run()
106
+ Factor a product of 2 polynomials of degree 10 over Rational Field.
107
+ System min avg max trials cpu or wall
108
+ * sage ...
109
+ * gp ...
110
+ """
111
+ if sort:
112
+ systems.sort()
113
+ print('\n\n\n' + str(self))
114
+ print(' %-12s%-12s%-12s%-12s%-12s%15s' % ('System', 'min',
115
+ 'avg', 'max',
116
+ 'trials', 'cpu or wall'))
117
+ if systems is None:
118
+ systems = STD_SYSTEMS
119
+ if optional:
120
+ systems += OPT_SYSTEMS
121
+ for S in systems:
122
+ try:
123
+ X = []
124
+ wall = False
125
+ for i in range(trials):
126
+ alarm(timeout)
127
+ t = getattr(self, S)()
128
+ cancel_alarm()
129
+ if isinstance(t, tuple):
130
+ wall = True
131
+ t = t[1]
132
+ X.append(t)
133
+ mn = min(X)
134
+ mx = max(X)
135
+ av = avg(X)
136
+ s = '* %-12s%-12f%-12f%-12f%-12s' % (S, mn, av,
137
+ mx, trials)
138
+ if wall:
139
+ s += '%15fw' % t
140
+ else:
141
+ s += '%15fc' % t
142
+ print(s)
143
+ except AlarmInterrupt:
144
+ print('%-12sinterrupted (timeout: %s seconds wall time)' %
145
+ (S, timeout))
146
+ except AttributeError:
147
+ pass
148
+ except Exception as msg:
149
+ print(msg)
150
+
151
+ bench = run
152
+
153
+ def __repr__(self):
154
+ """
155
+ Print representation of self, simply coming from self.repr_str.
156
+
157
+ EXAMPLES::
158
+
159
+ sage: from sage.tests.benchmark import Benchmark
160
+ sage: B = Benchmark()
161
+ sage: B.repr_str = 'spam'
162
+ sage: B
163
+ spam
164
+ """
165
+ try:
166
+ return self.repr_str
167
+ except AttributeError:
168
+ return 'sage.tests.benchmark.Benchmark instance'
169
+
170
+
171
+ class Divpoly(Benchmark):
172
+ def __init__(self, n):
173
+ """
174
+ Class for benchmarking computation of the division polynomial
175
+ of the following elliptic curve.
176
+
177
+ EXAMPLES::
178
+
179
+ sage: E = EllipticCurve([1,2,3,4,5])
180
+ sage: E.division_polynomial(3)
181
+ 3*x^4 + 9*x^3 + 33*x^2 + 87*x + 35
182
+ sage: E.division_polynomial(5)
183
+ 5*x^12 + 45*x^11 + 422*x^10 + ... - 426371
184
+
185
+ sage: from sage.tests.benchmark import Divpoly
186
+ sage: B = Divpoly(99)
187
+ sage: B
188
+ 99-Division polynomial
189
+ """
190
+ self.__n = n
191
+ self.repr_str = "%s-Division polynomial" % self.__n
192
+
193
+ def sage(self):
194
+ """
195
+ Time the computation in Sage.
196
+
197
+ EXAMPLES::
198
+
199
+ sage: from sage.tests.benchmark import Divpoly
200
+ sage: B = Divpoly(3)
201
+ sage: isinstance(B.sage(), float)
202
+ True
203
+ """
204
+ n = self.__n
205
+ t = cputime()
206
+ E = EllipticCurve([1, 2, 3, 4, 5])
207
+ E.division_polynomial(n)
208
+ return cputime(t)
209
+
210
+ def magma(self):
211
+ """
212
+ Time the computation in Magma.
213
+
214
+ EXAMPLES::
215
+
216
+ sage: from sage.tests.benchmark import Divpoly
217
+ sage: B = Divpoly(3)
218
+ sage: isinstance(B.magma(), float) # optional - magma
219
+ True
220
+ """
221
+ n = self.__n
222
+ t = magma.cputime()
223
+ magma('DivisionPolynomial(EllipticCurve([1,2,3,4,5]), %s)' % n)
224
+ return magma.cputime(t)
225
+
226
+
227
+ class PolySquare(Benchmark):
228
+ def __init__(self, n, R):
229
+ self.__n = n
230
+ self.__R = R
231
+ self.repr_str = 'Square a polynomial of degree %s over %s' % (self.__n, self.__R)
232
+
233
+ def sage(self):
234
+ """
235
+ Time the computation in Sage.
236
+
237
+ EXAMPLES::
238
+
239
+ sage: from sage.tests.benchmark import PolySquare
240
+ sage: B = PolySquare(3, QQ)
241
+ sage: isinstance(B.sage(), float)
242
+ True
243
+ """
244
+ R = self.__R
245
+ n = self.__n
246
+ f = R['x'](range(1, n + 1))
247
+ t = cputime()
248
+ f**2
249
+ return cputime(t)
250
+
251
+ def magma(self):
252
+ """
253
+ Time the computation in Magma.
254
+
255
+ EXAMPLES::
256
+
257
+ sage: from sage.tests.benchmark import PolySquare
258
+ sage: B = PolySquare(3, QQ)
259
+ sage: isinstance(B.magma(), float) # optional - magma
260
+ True
261
+ """
262
+ R = magma(self.__R)
263
+ f = magma('PolynomialRing(%s)![1..%s]' % (R.name(), self.__n))
264
+ t = magma.cputime()
265
+ f * f
266
+ return magma.cputime(t)
267
+
268
+ def maple(self):
269
+ """
270
+ Time the computation in Maple.
271
+
272
+ EXAMPLES::
273
+
274
+ sage: from sage.tests.benchmark import PolySquare
275
+ sage: B = PolySquare(3, QQ)
276
+ sage: isinstance(B.maple()[1], float) # optional - maple
277
+ True
278
+ """
279
+ R = self.__R
280
+ if not (R == ZZ or R == QQ):
281
+ raise NotImplementedError
282
+ n = self.__n
283
+ f = maple(str(R['x'](range(1, n + 1))))
284
+ t = walltime()
285
+ f * f
286
+ return False, walltime(t)
287
+
288
+
289
+ class MPolynomialPower(Benchmark):
290
+ def __init__(self, nvars=2, exp=10, base=QQ, allow_singular=True):
291
+ self.nvars = nvars
292
+ self.exp = exp
293
+ self.base = base
294
+ self.allow_singular = allow_singular
295
+ s = 'Compute (x_0 + ... + x_%s)^%s over %s' % (
296
+ self.nvars - 1, self.exp, self.base)
297
+ if self.allow_singular:
298
+ s += ' (use singular for Sage mult.)'
299
+ self.repr_str = s
300
+
301
+ def sage(self):
302
+ """
303
+ Time the computation in Sage.
304
+
305
+ EXAMPLES::
306
+
307
+ sage: from sage.tests.benchmark import MPolynomialPower
308
+ sage: B = MPolynomialPower()
309
+ sage: isinstance(B.sage()[1], float)
310
+ True
311
+ """
312
+ R = PolynomialRing(self.base, self.nvars, 'x')
313
+ z = sum(R.gens())
314
+ if self.allow_singular:
315
+ z = singular(sum(R.gens()))
316
+ t = walltime()
317
+ z**self.exp
318
+ return False, walltime(t)
319
+ t = cputime()
320
+ z**self.exp
321
+ return cputime(t)
322
+
323
+ def macaulay2(self):
324
+ """
325
+ Time the computation in Macaulay2.
326
+
327
+ EXAMPLES::
328
+
329
+ sage: from sage.tests.benchmark import MPolynomialPower
330
+ sage: B = MPolynomialPower()
331
+ sage: isinstance(B.macaulay2()[1], float) # optional - macaulay2
332
+ True
333
+ """
334
+ R = PolynomialRing(self.base, self.nvars, 'x')
335
+ z = macaulay2(sum(R.gens()))
336
+ t = walltime()
337
+ z**self.exp
338
+ return False, walltime(t)
339
+
340
+ def maxima(self):
341
+ """
342
+ Time the computation in Maxima.
343
+
344
+ EXAMPLES::
345
+
346
+ sage: from sage.tests.benchmark import MPolynomialPower
347
+ sage: B = MPolynomialPower()
348
+ sage: isinstance(B.maxima()[1], float)
349
+ True
350
+ """
351
+ R = PolynomialRing(self.base, self.nvars, 'x')
352
+ z = maxima(str(sum(R.gens())))
353
+ w = walltime()
354
+ (z**self.exp).expand()
355
+ return False, walltime(w)
356
+
357
+ def maple(self):
358
+ """
359
+ Time the computation in Maple.
360
+
361
+ EXAMPLES::
362
+
363
+ sage: from sage.tests.benchmark import MPolynomialPower
364
+ sage: B = MPolynomialPower()
365
+ sage: isinstance(B.maple()[1], float) # optional - maple
366
+ True
367
+ """
368
+ R = PolynomialRing(self.base, self.nvars, 'x')
369
+ z = maple(str(sum(R.gens())))
370
+ w = walltime()
371
+ (z**self.exp).expand()
372
+ return False, walltime(w)
373
+
374
+ def mathematica(self):
375
+ """
376
+ Time the computation in Mathematica.
377
+
378
+ EXAMPLES::
379
+
380
+ sage: from sage.tests.benchmark import MPolynomialPower
381
+ sage: B = MPolynomialPower()
382
+ sage: isinstance(B.mathematica()[1], float) # optional - mathematica
383
+ True
384
+ """
385
+ R = PolynomialRing(self.base, self.nvars, 'x')
386
+ z = mathematica(str(sum(R.gens())))
387
+ w = walltime()
388
+ (z**self.exp).Expand()
389
+ return False, walltime(w)
390
+
391
+ # this doesn't really expand out -- pari has no function to do so,
392
+ # as far as I know.
393
+ # def gp(self):
394
+ # R = PolynomialRing(self.base, self.nvars)
395
+ # z = gp(str(sum(R.gens())))
396
+ # gp.eval('gettime')
397
+ # z**self.exp
398
+ # return float(gp.eval('gettime/1000.0'))
399
+
400
+ def magma(self):
401
+ """
402
+ Time the computation in Magma.
403
+
404
+ EXAMPLES::
405
+
406
+ sage: from sage.tests.benchmark import MPolynomialPower
407
+ sage: B = MPolynomialPower()
408
+ sage: isinstance(B.magma(), float) # optional - magma
409
+ True
410
+ """
411
+ R = magma.PolynomialRing(self.base, self.nvars)
412
+ z = R.gen(1)
413
+ for i in range(2, self.nvars + 1):
414
+ z += R.gen(i)
415
+ t = magma.cputime()
416
+ z**magma(self.exp)
417
+ return magma.cputime(t)
418
+
419
+
420
+ class MPolynomialMult(Benchmark):
421
+ def __init__(self, nvars=2, base=QQ, allow_singular=True):
422
+ if nvars % 2:
423
+ nvars += 1
424
+ self.nvars = nvars
425
+ self.base = base
426
+ self.allow_singular = allow_singular
427
+ s = 'Compute (x_0 + ... + x_%s) * (x_%s + ... + x_%s) over %s' % (
428
+ self.nvars // 2 - 1, self.nvars // 2, self.nvars, self.base)
429
+ if self.allow_singular:
430
+ s += ' (use singular for Sage mult.)'
431
+ self.repr_str = s
432
+
433
+ def maxima(self):
434
+ """
435
+ Time the computation in Maxima.
436
+
437
+ EXAMPLES::
438
+
439
+ sage: from sage.tests.benchmark import MPolynomialMult
440
+ sage: B = MPolynomialMult()
441
+ sage: isinstance(B.maxima()[1], float)
442
+ True
443
+ """
444
+ R = PolynomialRing(self.base, self.nvars, 'x')
445
+ k = self.nvars // 2
446
+ z0 = maxima(str(sum(R.gens()[:k])))
447
+ z1 = maxima(str(sum(R.gens()[k:])))
448
+ w = walltime()
449
+ (z0 * z1).expand()
450
+ return False, walltime(w)
451
+
452
+ def maple(self):
453
+ """
454
+ Time the computation in Maple.
455
+
456
+ EXAMPLES::
457
+
458
+ sage: from sage.tests.benchmark import MPolynomialMult
459
+ sage: B = MPolynomialMult()
460
+ sage: isinstance(B.maple()[1], float) # optional - maple
461
+ True
462
+ """
463
+ R = PolynomialRing(self.base, self.nvars, 'x')
464
+ k = self.nvars // 2
465
+ z0 = maple(str(sum(R.gens()[:k])))
466
+ z1 = maple(str(sum(R.gens()[k:])))
467
+ w = walltime()
468
+ (z0 * z1).expand()
469
+ return False, walltime(w)
470
+
471
+ def mathematica(self):
472
+ """
473
+ Time the computation in Mathematica.
474
+
475
+ EXAMPLES::
476
+
477
+ sage: from sage.tests.benchmark import MPolynomialMult
478
+ sage: B = MPolynomialMult()
479
+ sage: isinstance(B.mathematica()[1], float) # optional - mathematica
480
+ True
481
+ """
482
+ R = PolynomialRing(self.base, self.nvars, 'x')
483
+ k = self.nvars // 2
484
+ z0 = mathematica(str(sum(R.gens()[:k])))
485
+ z1 = mathematica(str(sum(R.gens()[k:])))
486
+ w = walltime()
487
+ (z0 * z1).Expand()
488
+ return False, walltime(w)
489
+
490
+ # def gp(self):
491
+ # R = PolynomialRing(self.base, self.nvars)
492
+ # k = self.nvars // 2
493
+ # z0 = gp(str(sum(R.gens()[:k])))
494
+ # z1 = gp(str(sum(R.gens()[k:])))
495
+ # gp.eval('gettime')
496
+ # z0*z1
497
+ # return float(gp.eval('gettime/1000.0'))
498
+
499
+ def sage(self):
500
+ """
501
+ Time the computation in Sage.
502
+
503
+ EXAMPLES::
504
+
505
+ sage: from sage.tests.benchmark import MPolynomialMult
506
+ sage: B = MPolynomialMult()
507
+ sage: isinstance(B.sage()[1], float)
508
+ True
509
+ """
510
+ R = PolynomialRing(self.base, self.nvars, 'x')
511
+ k = self.nvars // 2
512
+ z0 = sum(R.gens()[:k])
513
+ z1 = sum(R.gens()[k:])
514
+ if self.allow_singular:
515
+ z0 = singular(z0)
516
+ z1 = singular(z1)
517
+ t = walltime()
518
+ z0 * z1
519
+ return False, walltime(t)
520
+ else:
521
+ t = cputime()
522
+ z0 * z1
523
+ return cputime(t)
524
+
525
+ def macaulay2(self):
526
+ """
527
+ Time the computation in Macaulay2.
528
+
529
+ EXAMPLES::
530
+
531
+ sage: from sage.tests.benchmark import MPolynomialMult
532
+ sage: B = MPolynomialMult()
533
+ sage: isinstance(B.macaulay2()[1], float) # optional - macaulay2
534
+ True
535
+ """
536
+ R = PolynomialRing(self.base, self.nvars, 'x')
537
+ k = self.nvars // 2
538
+ z0 = macaulay2(sum(R.gens()[:k]))
539
+ z1 = macaulay2(sum(R.gens()[k:]))
540
+ t = walltime()
541
+ z0 * z1
542
+ return False, walltime(t)
543
+
544
+ def magma(self):
545
+ """
546
+ Time the computation in Magma.
547
+
548
+ EXAMPLES::
549
+
550
+ sage: from sage.tests.benchmark import MPolynomialMult
551
+ sage: B = MPolynomialMult()
552
+ sage: isinstance(B.magma(), float) # optional - magma
553
+ True
554
+ """
555
+ R = magma.PolynomialRing(self.base, self.nvars)
556
+ z0 = R.gen(1)
557
+ k = self.nvars // 2
558
+ for i in range(2, k + 1):
559
+ z0 += R.gen(i)
560
+ z1 = R.gen(k + 1)
561
+ for i in range(k + 1, self.nvars + 1):
562
+ z1 += R.gen(i)
563
+ t = magma.cputime()
564
+ z0 * z1
565
+ return magma.cputime(t)
566
+
567
+
568
+ class MPolynomialMult2(Benchmark):
569
+ def __init__(self, nvars=2, base=QQ, allow_singular=True):
570
+ if nvars % 2:
571
+ nvars += 1
572
+ self.nvars = nvars
573
+ self.base = base
574
+ self.allow_singular = allow_singular
575
+ s = 'Compute (x_1 + 2*x_2 + 3*x_3 + ... + %s*x_%s) * (%s * x_%s + ... + %s*x_%s) over %s' % (
576
+ self.nvars // 2, self.nvars // 2, self.nvars // 2 + 1, self.nvars // 2 + 1,
577
+ self.nvars + 1, self.nvars + 1, self.base)
578
+ if self.allow_singular:
579
+ s += ' (use singular for Sage mult.)'
580
+ self.repr_str = s
581
+
582
+ # def gp(self):
583
+ # R = PolynomialRing(self.base, self.nvars)
584
+ # k = self.nvars // 2
585
+ # z0 = R(0)
586
+ # z1 = R(0)
587
+ # for i in range(k):
588
+ # z0 += (i+1)*R.gen(i)
589
+ # for i in range(k,self.nvars):
590
+ # z1 += (i+1)*R.gen(i)
591
+ # z0 = gp(str(z0))
592
+ # z1 = gp(str(z1))
593
+ # gp.eval('gettime')
594
+ # z0*z1
595
+ # return float(gp.eval('gettime/1000.0'))
596
+
597
+ def maxima(self):
598
+ """
599
+ Time the computation in Maxima.
600
+
601
+ EXAMPLES::
602
+
603
+ sage: from sage.tests.benchmark import MPolynomialMult2
604
+ sage: B = MPolynomialMult2()
605
+ sage: isinstance(B.maxima()[1], float)
606
+ True
607
+ """
608
+ R = PolynomialRing(self.base, self.nvars, 'x')
609
+ k = self.nvars // 2
610
+ z0 = R(0)
611
+ z1 = R(0)
612
+ for i in range(k):
613
+ z0 += (i + 1) * R.gen(i)
614
+ for i in range(k, self.nvars):
615
+ z1 += (i + 1) * R.gen(i)
616
+ z0 = maxima(str(z0))
617
+ z1 = maxima(str(z1))
618
+ w = walltime()
619
+ (z0 * z1).expand()
620
+ return False, walltime(w)
621
+
622
+ def macaulay2(self):
623
+ """
624
+ Time the computation in Macaulay2.
625
+
626
+ EXAMPLES::
627
+
628
+ sage: from sage.tests.benchmark import MPolynomialMult2
629
+ sage: B = MPolynomialMult2()
630
+ sage: isinstance(B.macaulay2()[1], float) # optional - macaulay2
631
+ True
632
+ """
633
+ R = PolynomialRing(self.base, self.nvars, 'x')
634
+ k = self.nvars // 2
635
+ z0 = R(0)
636
+ z1 = R(0)
637
+ for i in range(k):
638
+ z0 += (i + 1) * R.gen(i)
639
+ for i in range(k, self.nvars):
640
+ z1 += (i + 1) * R.gen(i)
641
+ z0 = macaulay2(z0)
642
+ z1 = macaulay2(z1)
643
+ t = walltime()
644
+ z0 * z1
645
+ return False, walltime(t)
646
+
647
+ def maple(self):
648
+ """
649
+ Time the computation in Maple.
650
+
651
+ EXAMPLES::
652
+
653
+ sage: from sage.tests.benchmark import MPolynomialMult2
654
+ sage: B = MPolynomialMult2()
655
+ sage: isinstance(B.maple()[1], float) # optional - maple
656
+ True
657
+ """
658
+ R = PolynomialRing(self.base, self.nvars, 'x')
659
+ k = self.nvars // 2
660
+ z0 = R(0)
661
+ z1 = R(0)
662
+ for i in range(k):
663
+ z0 += (i + 1) * R.gen(i)
664
+ for i in range(k, self.nvars):
665
+ z1 += (i + 1) * R.gen(i)
666
+ z0 = maple(str(z0))
667
+ z1 = maple(str(z1))
668
+ w = walltime()
669
+ (z0 * z1).expand()
670
+ return False, walltime(w)
671
+
672
+ def mathematica(self):
673
+ """
674
+ Time the computation in Mathematica.
675
+
676
+ EXAMPLES::
677
+
678
+ sage: from sage.tests.benchmark import MPolynomialMult2
679
+ sage: B = MPolynomialMult2()
680
+ sage: isinstance(B.mathematica()[1], float) # optional - mathematica
681
+ True
682
+ """
683
+ R = PolynomialRing(self.base, self.nvars, 'x')
684
+ k = self.nvars // 2
685
+ z0 = R(0)
686
+ z1 = R(0)
687
+ for i in range(k):
688
+ z0 += (i + 1) * R.gen(i)
689
+ for i in range(k, self.nvars):
690
+ z1 += (i + 1) * R.gen(i)
691
+ z0 = mathematica(str(z0))
692
+ z1 = mathematica(str(z1))
693
+ w = walltime()
694
+ (z0 * z1).Expand()
695
+ return False, walltime(w)
696
+
697
+ def sage(self):
698
+ """
699
+ Time the computation in Sage.
700
+
701
+ EXAMPLES::
702
+
703
+ sage: from sage.tests.benchmark import MPolynomialMult2
704
+ sage: B = MPolynomialMult2()
705
+ sage: isinstance(B.sage()[1], float)
706
+ True
707
+ """
708
+ R = PolynomialRing(self.base, self.nvars, 'x')
709
+ k = self.nvars // 2
710
+ z0 = R(0)
711
+ z1 = R(0)
712
+ for i in range(k):
713
+ z0 += (i + 1) * R.gen(i)
714
+ for i in range(k, self.nvars):
715
+ z1 += (i + 1) * R.gen(i)
716
+ if self.allow_singular:
717
+ z0 = singular(z0)
718
+ z1 = singular(z1)
719
+ t = walltime()
720
+ z0 * z1
721
+ return False, walltime(t)
722
+ else:
723
+ t = cputime()
724
+ z0 * z1
725
+ return cputime(t)
726
+
727
+ def magma(self):
728
+ """
729
+ Time the computation in Magma.
730
+
731
+ EXAMPLES::
732
+
733
+ sage: from sage.tests.benchmark import MPolynomialMult2
734
+ sage: B = MPolynomialMult2()
735
+ sage: isinstance(B.magma(), float) # optional - magma
736
+ True
737
+ """
738
+ R = magma.PolynomialRing(self.base, self.nvars)
739
+ z0 = R.gen(1)
740
+ k = self.nvars // 2
741
+ for i in range(2, k + 1):
742
+ z0 += magma(i) * R.gen(i)
743
+ z1 = R.gen(k + 1)
744
+ for i in range(k + 1, self.nvars + 1):
745
+ z1 += magma(i) * R.gen(i)
746
+ t = magma.cputime()
747
+ z0 * z1
748
+ return magma.cputime(t)
749
+
750
+
751
+ class CharPolyTp(Benchmark):
752
+ def __init__(self, N=37, k=2, p=2, sign=1):
753
+ self.N = N
754
+ self.k = k
755
+ self.p = p
756
+ self.sign = sign
757
+ self.repr_str = "Compute the charpoly (given the matrix) of T_%s on S_%s(Gamma_0(%s)) with sign %s." % (self.p, self.k, self.N, self.sign)
758
+
759
+ def matrix(self):
760
+ try:
761
+ return self._matrix
762
+ except AttributeError:
763
+ self._matrix = ModularSymbols(group=self.N, weight=self.k, sign=self.sign).T(self.p).matrix()
764
+ return self._matrix
765
+
766
+ def sage(self):
767
+ """
768
+ Time the computation in Sage.
769
+
770
+ EXAMPLES::
771
+
772
+ sage: from sage.tests.benchmark import CharPolyTp
773
+ sage: B = CharPolyTp()
774
+ sage: isinstance(B.sage(), float)
775
+ True
776
+ """
777
+ m = self.matrix()
778
+ t = cputime()
779
+ m.charpoly('x')
780
+ return cputime(t)
781
+
782
+ def gp(self):
783
+ """
784
+ Time the computation in GP.
785
+
786
+ EXAMPLES::
787
+
788
+ sage: from sage.tests.benchmark import CharPolyTp
789
+ sage: B = CharPolyTp()
790
+ sage: isinstance(B.gp(), float)
791
+ True
792
+ """
793
+ m = gp(self.matrix())
794
+ gp.eval('gettime')
795
+ m.charpoly('x')
796
+ return float(gp.eval('gettime/1000.0'))
797
+
798
+ def pari(self):
799
+ """
800
+ Time the computation in Pari.
801
+
802
+ EXAMPLES::
803
+
804
+ sage: from sage.tests.benchmark import CharPolyTp
805
+ sage: B = CharPolyTp()
806
+ sage: isinstance(B.pari(), float)
807
+ True
808
+ """
809
+ m = pari(self.matrix())
810
+ t = cputime()
811
+ m.charpoly('x')
812
+ return cputime(t)
813
+
814
+ def magma(self):
815
+ """
816
+ Time the computation in Magma.
817
+
818
+ EXAMPLES::
819
+
820
+ sage: from sage.tests.benchmark import CharPolyTp
821
+ sage: B = CharPolyTp()
822
+ sage: isinstance(B.magma(), float) # optional - magma
823
+ True
824
+ """
825
+ m = magma(self.matrix())
826
+ t = magma.cputime()
827
+ m.CharacteristicPolynomial()
828
+ return magma.cputime(t)
829
+
830
+
831
+ class PolyFactor(Benchmark):
832
+ def __init__(self, n, R):
833
+ self.__n = n
834
+ self.__R = R
835
+ self.repr_str = "Factor a product of 2 polynomials of degree %s over %s." % (self.__n, self.__R)
836
+
837
+ def sage(self):
838
+ """
839
+ Time the computation in Sage.
840
+
841
+ EXAMPLES::
842
+
843
+ sage: from sage.tests.benchmark import PolyFactor
844
+ sage: B = PolyFactor(3, QQ)
845
+ sage: isinstance(B.sage(), float)
846
+ True
847
+ """
848
+ R = PolynomialRing(self.__R, 'x')
849
+ f = R(range(1, self.__n + 1))
850
+ g = R(range(self.__n + 1, 2 * (self.__n + 1)))
851
+ h = f * g
852
+ t = cputime()
853
+ h.factor()
854
+ return cputime(t)
855
+
856
+ def magma(self):
857
+ """
858
+ Time the computation in Magma.
859
+
860
+ EXAMPLES::
861
+
862
+ sage: from sage.tests.benchmark import PolyFactor
863
+ sage: B = PolyFactor(3, QQ)
864
+ sage: isinstance(B.magma(), float) # optional - magma
865
+ True
866
+ """
867
+ R = magma(self.__R)
868
+ f = magma('PolynomialRing(%s)![1..%s]' % (R.name(), self.__n))
869
+ g = magma('PolynomialRing(%s)![%s+1..2*(%s+1)]' % (
870
+ R.name(), self.__n, self.__n))
871
+ h = f * g
872
+ t = magma.cputime()
873
+ h.Factorization()
874
+ return magma.cputime(t)
875
+
876
+ def gp(self):
877
+ """
878
+ Time the computation in GP.
879
+
880
+ EXAMPLES::
881
+
882
+ sage: from sage.tests.benchmark import PolyFactor
883
+ sage: B = PolyFactor(3, QQ)
884
+ sage: isinstance(B.gp(), float)
885
+ True
886
+ """
887
+ R = PolynomialRing(self.__R, 'x')
888
+ f = R(range(1, self.__n + 1))
889
+ g = R(range(self.__n + 1, 2 * (self.__n + 1)))
890
+ h = f * g
891
+ f = gp(h)
892
+ gp.eval('gettime')
893
+ f.factor()
894
+ return float(gp.eval('gettime/1000.0'))
895
+
896
+
897
+ class SquareInts(Benchmark):
898
+ def __init__(self, base=10, ndigits=10**5):
899
+ self.__ndigits = ndigits
900
+ self.base = base
901
+ self.repr_str = "Square the integer %s^%s" % (self.base, self.__ndigits)
902
+
903
+ def sage(self):
904
+ """
905
+ Time the computation in Sage.
906
+
907
+ EXAMPLES::
908
+
909
+ sage: from sage.tests.benchmark import SquareInts
910
+ sage: B = SquareInts()
911
+ sage: isinstance(B.sage(), float)
912
+ True
913
+ """
914
+ n = Integer(self.base)**self.__ndigits
915
+ t = cputime()
916
+ n**2
917
+ return cputime(t)
918
+
919
+ def gp(self):
920
+ """
921
+ Time the computation in GP.
922
+
923
+ EXAMPLES::
924
+
925
+ sage: from sage.tests.benchmark import SquareInts
926
+ sage: B = SquareInts()
927
+ sage: isinstance(B.gp(), float)
928
+ True
929
+ """
930
+ n = gp('%s^%s' % (self.base, self.__ndigits))
931
+ gp.eval('gettime')
932
+ n**2
933
+ return float(gp.eval('gettime/1000.0'))
934
+
935
+ def maxima(self):
936
+ """
937
+ Time the computation in Maxima.
938
+
939
+ EXAMPLES::
940
+
941
+ sage: from sage.tests.benchmark import SquareInts
942
+ sage: B = SquareInts()
943
+ sage: isinstance(B.maxima()[1], float)
944
+ True
945
+ """
946
+ n = maxima('%s^%s' % (self.base, self.__ndigits))
947
+ t = walltime()
948
+ n**2
949
+ return False, walltime(t)
950
+
951
+ def magma(self):
952
+ """
953
+ Time the computation in Magma.
954
+
955
+ EXAMPLES::
956
+
957
+ sage: from sage.tests.benchmark import SquareInts
958
+ sage: B = SquareInts()
959
+ sage: isinstance(B.magma(), float) # optional - magma
960
+ True
961
+ """
962
+ n = magma('%s^%s' % (self.base, self.__ndigits))
963
+ t = magma.cputime()
964
+ n**2
965
+ return magma.cputime(t)
966
+
967
+ def python(self):
968
+ """
969
+ Time the computation in Python.
970
+
971
+ EXAMPLES::
972
+
973
+ sage: from sage.tests.benchmark import SquareInts
974
+ sage: B = SquareInts()
975
+ sage: isinstance(B.python(), float)
976
+ True
977
+ """
978
+ n = self.base**self.__ndigits
979
+ t = cputime()
980
+ n**2
981
+ return cputime(t)
982
+
983
+ def maple(self):
984
+ """
985
+ Time the computation in Maple.
986
+
987
+ EXAMPLES::
988
+
989
+ sage: from sage.tests.benchmark import SquareInts
990
+ sage: B = SquareInts()
991
+ sage: isinstance(B.maple()[1], float) # optional - maple
992
+ True
993
+ """
994
+ n = maple('%s^%s' % (self.base, self.__ndigits))
995
+ t = walltime()
996
+ n**2
997
+ return False, walltime(t)
998
+
999
+ def libgap(self):
1000
+ """
1001
+ Time the computation in libGAP.
1002
+
1003
+ EXAMPLES::
1004
+
1005
+ sage: from sage.tests.benchmark import SquareInts
1006
+ sage: B = SquareInts()
1007
+ sage: isinstance(B.libgap()[1], float)
1008
+ True
1009
+ """
1010
+ n = libgap(self.base)**libgap(self.__ndigits)
1011
+ t = walltime()
1012
+ n**2
1013
+ return False, walltime(t)
1014
+
1015
+ def mathematica(self):
1016
+ """
1017
+ Time the computation in Mathematica.
1018
+
1019
+ EXAMPLES::
1020
+
1021
+ sage: from sage.tests.benchmark import SquareInts
1022
+ sage: B = SquareInts()
1023
+ sage: isinstance(B.mathematica()[1], float) # optional - mathematica
1024
+ True
1025
+ """
1026
+ n = mathematica('%s^%s' % (self.base, self.__ndigits))
1027
+ t = walltime()
1028
+ n**2
1029
+ return False, walltime(t)
1030
+
1031
+
1032
+ class MatrixSquare(Benchmark):
1033
+ def __init__(self, n, R):
1034
+ self.__n = n
1035
+ self.__R = R
1036
+ self.repr_str = 'Square a matrix of degree %s over %s' % (self.__n, self.__R)
1037
+
1038
+ def sage(self):
1039
+ """
1040
+ Time the computation in Sage.
1041
+
1042
+ EXAMPLES::
1043
+
1044
+ sage: from sage.tests.benchmark import MatrixSquare
1045
+ sage: B = MatrixSquare(3, QQ)
1046
+ sage: isinstance(B.sage(), float)
1047
+ True
1048
+ """
1049
+ R = self.__R
1050
+ n = self.__n
1051
+ f = MatrixSpace(R, n)(list(range(n * n)))
1052
+ t = cputime()
1053
+ f**2
1054
+ return cputime(t)
1055
+
1056
+ def magma(self):
1057
+ """
1058
+ Time the computation in Magma.
1059
+
1060
+ EXAMPLES::
1061
+
1062
+ sage: from sage.tests.benchmark import MatrixSquare
1063
+ sage: B = MatrixSquare(3, QQ)
1064
+ sage: isinstance(B.magma(), float) # optional - magma
1065
+ True
1066
+ """
1067
+ R = magma(self.__R)
1068
+ f = magma('MatrixAlgebra(%s, %s)![0..%s^2-1]' % (
1069
+ R.name(), self.__n, self.__n))
1070
+ t = magma.cputime()
1071
+ f * f
1072
+ return magma.cputime(t)
1073
+
1074
+ def gp(self):
1075
+ """
1076
+ Time the computation in GP.
1077
+
1078
+ EXAMPLES::
1079
+
1080
+ sage: from sage.tests.benchmark import MatrixSquare
1081
+ sage: B = MatrixSquare(3, QQ)
1082
+ sage: isinstance(B.gp(), float)
1083
+ True
1084
+ """
1085
+ n = self.__n
1086
+ m = gp('matrix(%s,%s,m,n,%s*(m-1)+(n-1))' % (n, n, n))
1087
+ gp('gettime')
1088
+ m * m
1089
+ return float(gp.eval('gettime/1000.0'))
1090
+
1091
+ def libgap(self):
1092
+ """
1093
+ Time the computation in libGAP.
1094
+
1095
+ EXAMPLES::
1096
+
1097
+ sage: from sage.tests.benchmark import MatrixSquare
1098
+ sage: B = MatrixSquare(3, QQ)
1099
+ sage: isinstance(B.libgap()[1], float)
1100
+ True
1101
+ """
1102
+ R = self.__R
1103
+ n = self.__n
1104
+ f = MatrixSpace(R, n)(list(range(n * n)))
1105
+ m = libgap(f)
1106
+ t = walltime()
1107
+ m * m
1108
+ return False, walltime(t)
1109
+
1110
+
1111
+ class Factorial(Benchmark):
1112
+ def __init__(self, n):
1113
+ self.__n = n
1114
+ self.repr_str = "Compute the factorial of %s" % self.__n
1115
+
1116
+ def sage(self):
1117
+ """
1118
+ Time the computation in Sage.
1119
+
1120
+ EXAMPLES::
1121
+
1122
+ sage: from sage.tests.benchmark import Factorial
1123
+ sage: B = Factorial(10)
1124
+ sage: isinstance(B.sage(), float)
1125
+ True
1126
+ """
1127
+ t = cputime()
1128
+ factorial(self.__n)
1129
+ return cputime(t)
1130
+
1131
+ def magma(self):
1132
+ """
1133
+ Time the computation in Magma.
1134
+
1135
+ EXAMPLES::
1136
+
1137
+ sage: from sage.tests.benchmark import Factorial
1138
+ sage: B = Factorial(10)
1139
+ sage: isinstance(B.magma(), float) # optional - magma
1140
+ True
1141
+ """
1142
+ t = magma.cputime()
1143
+ magma('&*[1..%s]' % self.__n) # &* is way better than Factorial!!
1144
+ return magma.cputime(t)
1145
+
1146
+ def maple(self):
1147
+ """
1148
+ Time the computation in Maple.
1149
+
1150
+ EXAMPLES::
1151
+
1152
+ sage: from sage.tests.benchmark import Factorial
1153
+ sage: B = Factorial(10)
1154
+ sage: isinstance(B.maple()[1], float) # optional - maple
1155
+ True
1156
+ """
1157
+ n = maple(self.__n)
1158
+ t = walltime()
1159
+ n.factorial()
1160
+ return False, walltime(t)
1161
+
1162
+ def gp(self):
1163
+ """
1164
+ Time the computation in GP.
1165
+
1166
+ EXAMPLES::
1167
+
1168
+ sage: from sage.tests.benchmark import Factorial
1169
+ sage: B = Factorial(10)
1170
+ sage: isinstance(B.gp(), float)
1171
+ True
1172
+ """
1173
+ gp.eval('gettime')
1174
+ gp('%s!' % self.__n)
1175
+ return float(gp.eval('gettime/1000.0'))
1176
+
1177
+
1178
+ class Fibonacci(Benchmark):
1179
+ def __init__(self, n):
1180
+ self.__n = n
1181
+ self.repr_str = "Compute the %s-th Fibonacci number" % self.__n
1182
+
1183
+ def sage(self):
1184
+ """
1185
+ Time the computation in Sage.
1186
+
1187
+ EXAMPLES::
1188
+
1189
+ sage: from sage.tests.benchmark import Fibonacci
1190
+ sage: B = Fibonacci(10)
1191
+ sage: isinstance(B.sage(), float)
1192
+ True
1193
+ """
1194
+ t = cputime()
1195
+ fibonacci(self.__n)
1196
+ return cputime(t)
1197
+
1198
+ def magma(self):
1199
+ """
1200
+ Time the computation in Magma.
1201
+
1202
+ EXAMPLES::
1203
+
1204
+ sage: from sage.tests.benchmark import Fibonacci
1205
+ sage: B = Fibonacci(10)
1206
+ sage: isinstance(B.magma(), float) # optional - magma
1207
+ True
1208
+ """
1209
+ t = magma.cputime()
1210
+ magma('Fibonacci(%s)' % self.__n)
1211
+ return magma.cputime(t)
1212
+
1213
+ def libgap(self):
1214
+ """
1215
+ Time the computation in libGAP.
1216
+
1217
+ EXAMPLES::
1218
+
1219
+ sage: from sage.tests.benchmark import Fibonacci
1220
+ sage: B = Fibonacci(10)
1221
+ sage: isinstance(B.libgap()[1], float)
1222
+ True
1223
+ """
1224
+ n = libgap(self.__n)
1225
+ t = walltime()
1226
+ n.Fibonacci()
1227
+ return False, walltime(t)
1228
+
1229
+ def mathematica(self):
1230
+ """
1231
+ Time the computation in Mathematica.
1232
+
1233
+ EXAMPLES::
1234
+
1235
+ sage: from sage.tests.benchmark import Fibonacci
1236
+ sage: B = Fibonacci(10)
1237
+ sage: isinstance(B.mathematica()[1], float) # optional - mathematica
1238
+ True
1239
+ """
1240
+ n = mathematica(self.__n)
1241
+ t = walltime()
1242
+ n.Fibonacci()
1243
+ return False, walltime(t)
1244
+
1245
+ def gp(self):
1246
+ """
1247
+ Time the computation in GP.
1248
+
1249
+ EXAMPLES::
1250
+
1251
+ sage: from sage.tests.benchmark import Fibonacci
1252
+ sage: B = Fibonacci(10)
1253
+ sage: isinstance(B.gp(), float)
1254
+ True
1255
+ """
1256
+ gp.eval('gettime')
1257
+ gp('fibonacci(%s)' % self.__n)
1258
+ return float(gp.eval('gettime/1000.0'))
1259
+
1260
+
1261
+ class SEA(Benchmark):
1262
+ def __init__(self, p):
1263
+ self.__p = p
1264
+ self.repr_str = "Do SEA on an elliptic curve over GF(%s)" % self.__p
1265
+
1266
+ def sage(self):
1267
+ """
1268
+ Time the computation in Sage.
1269
+
1270
+ EXAMPLES::
1271
+
1272
+ sage: from sage.tests.benchmark import SEA
1273
+ sage: B = SEA(5)
1274
+ sage: isinstance(B.sage()[1], float)
1275
+ True
1276
+ """
1277
+ E = EllipticCurve([1, 2, 3, 4, 5])
1278
+ t = walltime()
1279
+ # Note that from pari 2.4.3, the SEA algorithm is used by the
1280
+ # pari library, but only for large primes, so for a better
1281
+ # test a prime > 2^30 should be used and not 5. In fact
1282
+ # next_prime(2^100) works fine (<<1s).
1283
+ E.change_ring(GF(self.__p)).cardinality_pari()
1284
+ return False, walltime(t)
1285
+
1286
+ def magma(self):
1287
+ """
1288
+ Time the computation in Magma.
1289
+
1290
+ EXAMPLES::
1291
+
1292
+ sage: from sage.tests.benchmark import SEA
1293
+ sage: B = SEA(5)
1294
+ sage: isinstance(B.magma(), float) # optional - magma
1295
+ True
1296
+ """
1297
+ magma(0)
1298
+ t = magma.cputime()
1299
+ magma('#EllipticCurve([GF(%s)|1,2,3,4,5])' % (self.__p))
1300
+ return magma.cputime(t)
1301
+
1302
+
1303
+ class MatrixKernel(Benchmark):
1304
+ def __init__(self, n, R):
1305
+ self.__n = n
1306
+ self.__R = R
1307
+ self.repr_str = 'Kernel of a matrix of degree %s over %s' % (self.__n, self.__R)
1308
+
1309
+ def sage(self):
1310
+ """
1311
+ Time the computation in Sage.
1312
+
1313
+ EXAMPLES::
1314
+
1315
+ sage: from sage.tests.benchmark import MatrixKernel
1316
+ sage: B = MatrixKernel(3, QQ)
1317
+ sage: isinstance(B.sage(), float)
1318
+ True
1319
+ """
1320
+ R = self.__R
1321
+ n = self.__n
1322
+ f = MatrixSpace(R, n, 2 * n)(list(range(n * (2 * n))))
1323
+ t = cputime()
1324
+ f.kernel()
1325
+ return cputime(t)
1326
+
1327
+ def magma(self):
1328
+ """
1329
+ Time the computation in Magma.
1330
+
1331
+ EXAMPLES::
1332
+
1333
+ sage: from sage.tests.benchmark import MatrixKernel
1334
+ sage: B = MatrixKernel(3, QQ)
1335
+ sage: isinstance(B.magma(), float) # optional - magma
1336
+ True
1337
+ """
1338
+ R = magma(self.__R)
1339
+ f = magma('RMatrixSpace(%s, %s, %s)![0..(%s*2*%s)-1]' % (
1340
+ R.name(), self.__n, 2 * self.__n, self.__n, self.__n))
1341
+ t = magma.cputime()
1342
+ f.Kernel()
1343
+ return magma.cputime(t)
1344
+
1345
+ def gp(self):
1346
+ """
1347
+ Time the computation in GP.
1348
+
1349
+ EXAMPLES::
1350
+
1351
+ sage: from sage.tests.benchmark import MatrixKernel
1352
+ sage: B = MatrixKernel(3, QQ)
1353
+ sage: isinstance(B.gp(), float)
1354
+ True
1355
+ """
1356
+ n = self.__n
1357
+ m = gp('matrix(%s,%s,m,n,%s*(m-1)+(n-1))' % (n, 2 * n, n))
1358
+ gp('gettime')
1359
+ m.matker()
1360
+ return float(gp.eval('gettime/1000.0'))
1361
+
1362
+
1363
+ class ComplexMultiply(Benchmark):
1364
+ def __init__(self, bits_prec, times):
1365
+ self.__bits_prec = bits_prec
1366
+ self.__times = times
1367
+ self.repr_str = "List of multiplies of two complex numbers with %s bits of precision %s times" % (self.__bits_prec, self.__times)
1368
+
1369
+ def sage(self):
1370
+ """
1371
+ Time the computation in Sage.
1372
+
1373
+ EXAMPLES::
1374
+
1375
+ sage: from sage.tests.benchmark import ComplexMultiply
1376
+ sage: B = ComplexMultiply(28, 2)
1377
+ sage: isinstance(B.sage(), float)
1378
+ True
1379
+ """
1380
+ CC = ComplexField(self.__bits_prec)
1381
+ s = CC(2).sqrt() + (CC.gen() * 2).sqrt()
1382
+ t = cputime()
1383
+ [s * s for _ in range(self.__times)]
1384
+ return cputime(t)
1385
+
1386
+ def magma(self):
1387
+ """
1388
+ Time the computation in Magma.
1389
+
1390
+ EXAMPLES::
1391
+
1392
+ sage: from sage.tests.benchmark import ComplexMultiply
1393
+ sage: B = ComplexMultiply(28, 2)
1394
+ sage: isinstance(B.magma(), float) # optional - magma
1395
+ True
1396
+
1397
+ .. NOTE::
1398
+
1399
+ decimal digits (despite magma docs that say bits!!)
1400
+ """
1401
+ n = int(self.__bits_prec / log(10, 2)) + 1
1402
+ CC = magma.ComplexField(n)
1403
+ s = CC(2).Sqrt() + CC.gen(1).Sqrt()
1404
+ t = magma.cputime()
1405
+ magma.eval('s := %s;' % s.name())
1406
+ magma('[s*s : i in [1..%s]]' % self.__times)
1407
+ return magma.cputime(t)
1408
+
1409
+ def gp(self):
1410
+ """
1411
+ Time the computation in GP.
1412
+
1413
+ EXAMPLES::
1414
+
1415
+ sage: from sage.tests.benchmark import ComplexMultiply
1416
+ sage: B = ComplexMultiply(28, 2)
1417
+ sage: isinstance(B.gp(), float)
1418
+ True
1419
+ """
1420
+ n = int(self.__bits_prec / log(10, 2)) + 1
1421
+ gp.set_real_precision(n)
1422
+ gp.eval('s = sqrt(2) + sqrt(2*I);')
1423
+ gp.eval('gettime;')
1424
+ gp('vector(%s,i,s*s)' % self.__times)
1425
+ return float(gp.eval('gettime/1000.0'))
1426
+
1427
+
1428
+ class ModularSymbols1(Benchmark):
1429
+ def __init__(self, N, k=2):
1430
+ self.__N = N
1431
+ self.__k = k
1432
+ self.repr_str = 'Presentation for modular symbols on Gamma_0(%s) of weight %s' % (self.__N, self.__k)
1433
+
1434
+ def sage(self):
1435
+ """
1436
+ Time the computation in Sage.
1437
+
1438
+ EXAMPLES::
1439
+
1440
+ sage: from sage.tests.benchmark import ModularSymbols1
1441
+ sage: B = ModularSymbols1(11)
1442
+ sage: isinstance(B.sage(), float)
1443
+ True
1444
+ """
1445
+ t = cputime()
1446
+ ModularSymbols(self.__N, self.__k)
1447
+ return cputime(t)
1448
+
1449
+ def magma(self):
1450
+ """
1451
+ Time the computation in Magma.
1452
+
1453
+ EXAMPLES::
1454
+
1455
+ sage: from sage.tests.benchmark import ModularSymbols1
1456
+ sage: B = ModularSymbols1(11)
1457
+ sage: isinstance(B.magma(), float) # optional - magma
1458
+ True
1459
+ """
1460
+ magma = Magma() # new instance since otherwise modsyms are cached, and cache can't be cleared
1461
+ t = magma.cputime()
1462
+ magma('ModularSymbols(%s, %s)' % (self.__N, self.__k))
1463
+ return magma.cputime(t)
1464
+
1465
+
1466
+ class ModularSymbolsDecomp1(Benchmark):
1467
+ def __init__(self, N, k=2, sign=1, bnd=10):
1468
+ self.N = N
1469
+ self.k = k
1470
+ self.sign = sign
1471
+ self.bnd = bnd
1472
+ self.repr_str = 'Decomposition of modular symbols on Gamma_0(%s) of weight %s and sign %s' % (self.N, self.k, self.sign)
1473
+
1474
+ def sage(self):
1475
+ """
1476
+ Time the computation in Sage.
1477
+
1478
+ EXAMPLES::
1479
+
1480
+ sage: from sage.tests.benchmark import ModularSymbolsDecomp1
1481
+ sage: B = ModularSymbolsDecomp1(11)
1482
+ sage: isinstance(B.sage(), float)
1483
+ True
1484
+ """
1485
+ t = cputime()
1486
+ M = ModularSymbols(self.N, self.k, sign=self.sign, use_cache=False)
1487
+ M.decomposition(self.bnd)
1488
+ return cputime(t)
1489
+
1490
+ def magma(self):
1491
+ """
1492
+ Time the computation in Magma.
1493
+
1494
+ EXAMPLES::
1495
+
1496
+ sage: from sage.tests.benchmark import ModularSymbolsDecomp1
1497
+ sage: B = ModularSymbolsDecomp1(11)
1498
+ sage: isinstance(B.magma(), float) # optional - magma
1499
+ True
1500
+ """
1501
+ m = Magma() # new instance since otherwise modsyms are cached, and cache can't be cleared
1502
+ t = m.cputime()
1503
+ m.eval('Decomposition(ModularSymbols(%s, %s, %s),%s);' % (
1504
+ self.N, self.k, self.sign, self.bnd))
1505
+ return m.cputime(t)
1506
+
1507
+
1508
+ class EllipticCurveTraces(Benchmark):
1509
+ def __init__(self, B):
1510
+ self.B = B
1511
+ self.repr_str = "Compute all a_p for the elliptic curve [1,2,3,4,5], for p < %s" % self.B
1512
+
1513
+ def sage(self):
1514
+ """
1515
+ Time the computation in Sage.
1516
+
1517
+ EXAMPLES::
1518
+
1519
+ sage: from sage.tests.benchmark import EllipticCurveTraces
1520
+ sage: B = EllipticCurveTraces(11)
1521
+ sage: isinstance(B.sage(), float)
1522
+ Traceback (most recent call last):
1523
+ ...
1524
+ TypeError: ...anlist() got an unexpected keyword argument 'pari_ints'
1525
+ """
1526
+ E = EllipticCurve([1, 2, 3, 4, 5])
1527
+ t = cputime()
1528
+ E.anlist(self.B, pari_ints=True)
1529
+ return cputime(t)
1530
+
1531
+ def magma(self):
1532
+ """
1533
+ Time the computation in Magma.
1534
+
1535
+ EXAMPLES::
1536
+
1537
+ sage: from sage.tests.benchmark import EllipticCurveTraces
1538
+ sage: B = EllipticCurveTraces(11)
1539
+ sage: isinstance(B.magma(), float) # optional - magma
1540
+ True
1541
+ """
1542
+ E = magma.EllipticCurve([1, 2, 3, 4, 5])
1543
+ t = magma.cputime()
1544
+ E.TracesOfFrobenius(self.B)
1545
+ return magma.cputime(t)
1546
+
1547
+
1548
+ class EllipticCurvePointMul(Benchmark):
1549
+ def __init__(self, n):
1550
+ self.n = n
1551
+ self.repr_str = "Compute %s*(0,0) on the elliptic curve [0, 0, 1, -1, 0] over QQ" % self.n
1552
+
1553
+ def sage(self):
1554
+ """
1555
+ Time the computation in Sage.
1556
+
1557
+ EXAMPLES::
1558
+
1559
+ sage: from sage.tests.benchmark import EllipticCurvePointMul
1560
+ sage: B = EllipticCurvePointMul(11)
1561
+ sage: isinstance(B.sage(), float)
1562
+ True
1563
+ """
1564
+ E = EllipticCurve([0, 0, 1, -1, 0])
1565
+ P = E([0, 0])
1566
+ t = cputime()
1567
+ self.n * P
1568
+ return cputime(t)
1569
+
1570
+ def magma(self):
1571
+ """
1572
+ Time the computation in Magma.
1573
+
1574
+ EXAMPLES::
1575
+
1576
+ sage: from sage.tests.benchmark import EllipticCurvePointMul
1577
+ sage: B = EllipticCurvePointMul(11)
1578
+ sage: isinstance(B.magma(), float) # optional - magma
1579
+ True
1580
+ """
1581
+ E = magma.EllipticCurve('[0, 0, 1, -1, 0]')
1582
+ P = E('[0,0]')
1583
+ t = magma.cputime()
1584
+ magma(self.n) * P
1585
+ return magma.cputime(t)
1586
+
1587
+ def gp(self):
1588
+ """
1589
+ Time the computation in GP.
1590
+
1591
+ EXAMPLES::
1592
+
1593
+ sage: from sage.tests.benchmark import EllipticCurvePointMul
1594
+ sage: B = EllipticCurvePointMul(11)
1595
+ sage: isinstance(B.gp(), float)
1596
+ True
1597
+ """
1598
+ E = gp.ellinit('[0, 0, 1, -1, 0]')
1599
+ gp.eval('gettime')
1600
+ P = gp([0, 0])
1601
+ E.ellmul(P, self.n)
1602
+ return float(gp.eval('gettime/1000.0'))
1603
+
1604
+ def pari(self):
1605
+ """
1606
+ Time the computation in Pari.
1607
+
1608
+ EXAMPLES::
1609
+
1610
+ sage: from sage.tests.benchmark import EllipticCurvePointMul
1611
+ sage: B = EllipticCurvePointMul(11)
1612
+ sage: isinstance(B.pari(), float)
1613
+ True
1614
+ """
1615
+ E = pari('ellinit([0, 0, 1, -1, 0])')
1616
+ pari('gettime')
1617
+ P = pari([0, 0])
1618
+ E.ellmul(P, self.n)
1619
+ return float(pari('gettime/1000.0'))
1620
+
1621
+
1622
+ class EllipticCurveMW(Benchmark):
1623
+ def __init__(self, ainvs):
1624
+ self.ainvs = ainvs
1625
+ self.repr_str = "Compute generators for the Mordell-Weil group of the elliptic curve %s over QQ" % self.ainvs
1626
+
1627
+ def sage(self):
1628
+ """
1629
+ Time the computation in Sage.
1630
+
1631
+ EXAMPLES::
1632
+
1633
+ sage: from sage.tests.benchmark import EllipticCurveMW
1634
+ sage: B = EllipticCurveMW([1,2,3,4,5])
1635
+ sage: isinstance(B.sage()[1], float)
1636
+ True
1637
+ """
1638
+ E = EllipticCurve(self.ainvs)
1639
+ t = walltime()
1640
+ E.gens()
1641
+ return False, walltime(t)
1642
+
1643
+ def magma(self):
1644
+ """
1645
+ Time the computation in Magma.
1646
+
1647
+ EXAMPLES::
1648
+
1649
+ sage: from sage.tests.benchmark import EllipticCurveMW
1650
+ sage: B = EllipticCurveMW([1,2,3,4,5])
1651
+ sage: isinstance(B.magma(), float) # optional - magma
1652
+ True
1653
+ """
1654
+ E = magma.EllipticCurve(str(self.ainvs))
1655
+ t = magma.cputime()
1656
+ E.Generators()
1657
+ return magma.cputime(t)
1658
+
1659
+
1660
+ class FiniteExtFieldMult(Benchmark):
1661
+ def __init__(self, field, times):
1662
+ self.__times = times
1663
+ self.field = field
1664
+ self.e = field.gen()**(field.cardinality() / 3)
1665
+ self.f = field.gen()**(2 * field.cardinality() / 3)
1666
+ self.repr_str = "Multiply a^(#K/3) with a^(2*#K/3) where a == K.gen()"
1667
+
1668
+ def sage(self):
1669
+ """
1670
+ Time the computation in Sage.
1671
+
1672
+ EXAMPLES::
1673
+
1674
+ sage: from sage.tests.benchmark import FiniteExtFieldMult
1675
+ sage: B = FiniteExtFieldMult(GF(9, 'x'), 2)
1676
+ sage: isinstance(B.sage(), float)
1677
+ True
1678
+ """
1679
+ e = self.e
1680
+ f = self.f
1681
+ t = cputime()
1682
+ [e * f for _ in range(self.__times)]
1683
+ return cputime(t)
1684
+
1685
+ def pari(self):
1686
+ """
1687
+ Time the computation in Pari.
1688
+
1689
+ EXAMPLES::
1690
+
1691
+ sage: from sage.tests.benchmark import FiniteExtFieldMult
1692
+ sage: B = FiniteExtFieldMult(GF(9, 'x'), 2)
1693
+ sage: isinstance(B.pari(), float)
1694
+ True
1695
+ """
1696
+ e = self.e.__pari__()
1697
+ f = self.f.__pari__()
1698
+ t = cputime()
1699
+ [e * f for _ in range(self.__times)]
1700
+ return cputime(t)
1701
+
1702
+ def magma(self):
1703
+ """
1704
+ Time the computation in Magma.
1705
+
1706
+ EXAMPLES::
1707
+
1708
+ sage: from sage.tests.benchmark import FiniteExtFieldMult
1709
+ sage: B = FiniteExtFieldMult(GF(9, 'x'), 2)
1710
+ sage: isinstance(B.magma(), float) # optional - magma
1711
+ True
1712
+ """
1713
+ magma.eval('F<a> := GF(%s)' % (self.field.cardinality()))
1714
+ magma.eval('e := a^Floor(%s/3);' % (self.field.cardinality()))
1715
+ magma.eval('f := a^Floor(2*%s/3);' % (self.field.cardinality()))
1716
+ t = magma.cputime()
1717
+ magma('[e*f : i in [1..%s]]' % self.__times)
1718
+ return magma.cputime(t)
1719
+
1720
+
1721
+ class FiniteExtFieldAdd(Benchmark):
1722
+ def __init__(self, field, times):
1723
+ self.__times = times
1724
+ self.field = field
1725
+ self.e = field.gen()**(field.cardinality() / 3)
1726
+ self.f = field.gen()**(2 * field.cardinality() / 3)
1727
+ self.repr_str = "Add a^(#K/3) to a^(2*#K/3) where a == K.gen()"
1728
+
1729
+ def sage(self):
1730
+ """
1731
+ Time the computation in Sage.
1732
+
1733
+ EXAMPLES::
1734
+
1735
+ sage: from sage.tests.benchmark import FiniteExtFieldAdd
1736
+ sage: B = FiniteExtFieldAdd(GF(9,'x'), 2)
1737
+ sage: isinstance(B.sage(), float)
1738
+ True
1739
+ """
1740
+ e = self.e
1741
+ f = self.f
1742
+ t = cputime()
1743
+ [e + f for _ in range(self.__times)]
1744
+ return cputime(t)
1745
+
1746
+ def pari(self):
1747
+ """
1748
+ Time the computation in Pari.
1749
+
1750
+ EXAMPLES::
1751
+
1752
+ sage: from sage.tests.benchmark import FiniteExtFieldAdd
1753
+ sage: B = FiniteExtFieldAdd(GF(9,'x'), 2)
1754
+ sage: isinstance(B.pari(), float)
1755
+ True
1756
+ """
1757
+ e = self.e.__pari__()
1758
+ f = self.f.__pari__()
1759
+ t = cputime()
1760
+ [e + f for _ in range(self.__times)]
1761
+ return cputime(t)
1762
+
1763
+ def magma(self):
1764
+ """
1765
+ Time the computation in Magma.
1766
+
1767
+ EXAMPLES::
1768
+
1769
+ sage: from sage.tests.benchmark import FiniteExtFieldAdd
1770
+ sage: B = FiniteExtFieldAdd(GF(9,'x'), 2)
1771
+ sage: isinstance(B.magma(), float) # optional - magma
1772
+ True
1773
+ """
1774
+ magma.eval('F<a> := GF(%s)' % (self.field.cardinality()))
1775
+ magma.eval('e := a^Floor(%s/3);' % (self.field.cardinality()))
1776
+ magma.eval('f := a^Floor(2*%s/3);' % (self.field.cardinality()))
1777
+ t = magma.cputime()
1778
+ magma('[e+f : i in [1..%s]]' % self.__times)
1779
+ return magma.cputime(t)
1780
+
1781
+
1782
+ """
1783
+ .. TODO::
1784
+
1785
+ * multiply reals
1786
+ * modular degree
1787
+ * anlist
1788
+ * MW group
1789
+ * symbolic det
1790
+ * poly factor
1791
+ * multivariate poly factor
1792
+ """
1793
+
1794
+
1795
+ def suite1():
1796
+ PolySquare(10000, QQ).run()
1797
+ PolySquare(20000, ZZ).run()
1798
+ PolySquare(50000, GF(5)).run()
1799
+ PolySquare(20000, Integers(8)).run()
1800
+
1801
+ SquareInts(10, 2000000).run()
1802
+
1803
+ MatrixSquare(200, QQ).run()
1804
+ MatrixSquare(50, ZZ).run()
1805
+
1806
+ SquareInts(10, 150000).run()
1807
+
1808
+ Factorial(2 * 10**6).run(systems=['sage', 'magma'])
1809
+ Fibonacci(10**6).run()
1810
+ Fibonacci(2 * 10**7).run(systems=["sage", "magma", "mathematica"])
1811
+
1812
+ MatrixKernel(150, QQ).run()
1813
+
1814
+ ComplexMultiply(100000, 1000)
1815
+ ComplexMultiply(100, 100000)
1816
+ ComplexMultiply(53, 100000)
1817
+
1818
+ PolyFactor(300, ZZ)
1819
+ PolyFactor(300, GF(19))
1820
+ PolyFactor(700, GF(19))
1821
+
1822
+ PolyFactor(500, GF((9, 2), 'a'))
1823
+ PolyFactor(100, GF((10007, 3), 'a'))
1824
+
1825
+ CharPolyTp(54, 4).run()
1826
+ CharPolyTp(389, 2).run()
1827
+ CharPolyTp(389, 2, sign=0, p=3).run()
1828
+ CharPolyTp(1000, 2, sign=1, p=2).run(systems=['sage', 'magma'])
1829
+ CharPolyTp(1, 100, sign=1, p=5).run(systems=['sage', 'magma']) # Sage's multimodular really sucks here! (GP is way better, even)
1830
+ CharPolyTp(512, sign=1, p=3).run(systems=['sage', 'magma', 'gp'])
1831
+ CharPolyTp(512, sign=0, p=3).run(systems=['sage', 'magma', 'gp'])
1832
+ CharPolyTp(1024, sign=1, p=3).run(systems=['sage', 'magma', 'gp'])
1833
+ CharPolyTp(2006, sign=1, p=2).run(systems=['sage', 'magma', 'gp'])
1834
+ CharPolyTp(2006, sign=1, p=2).run(systems=['sage', 'magma']) # gp takes > 1 minute.
1835
+
1836
+
1837
+ def mpoly():
1838
+ # This includes a maxima benchmark. Note that
1839
+ # maxima is *shockingly* slow in comparison to Singular or MAGMA.
1840
+ # It is so slow as to be useless, basically, i.e., factor
1841
+ # of 5000 slower than Singular on this example!
1842
+ MPolynomialPower(nvars=6, exp=10).run()
1843
+
1844
+ main = ['sage', 'magma'] # just the main competitors
1845
+ MPolynomialPower(nvars=2, exp=200, allow_singular=False).run(main)
1846
+ MPolynomialPower(nvars=5, exp=10, allow_singular=False).run(main)
1847
+ MPolynomialPower(nvars=5, exp=30, allow_singular=True).run(main)
1848
+ MPolynomialPower(nvars=2, exp=1000, allow_singular=True).run(main)
1849
+ MPolynomialPower(nvars=10, exp=10, allow_singular=True).run(main)
1850
+ MPolynomialPower(nvars=4, exp=350, base=GF(7), allow_singular=True).run(main)
1851
+ MPolynomialMult(200, allow_singular=False).run(main)
1852
+ MPolynomialMult(400, allow_singular=True).run(main)
1853
+ MPolynomialMult(800, allow_singular=True).run(main)
1854
+ MPolynomialMult2(500, allow_singular=True).run(main)
1855
+
1856
+
1857
+ def mpoly_all(include_maple=False):
1858
+ """
1859
+ Run benchmarks for multipoly arithmetic on all systems (except
1860
+ Maxima, since it is very very slow). You must have mathematica,
1861
+ maple, and magma.
1862
+
1863
+ .. NOTE::
1864
+
1865
+ * maple is depressingly slow on these benchmarks.
1866
+ * Singular (i.e., Sage) does shockingly well.
1867
+ * mathematica is sometimes amazing.
1868
+ * macaulay2 is also quite bad (though not as bad as maple).
1869
+
1870
+ EXAMPLES::
1871
+
1872
+ sage: from sage.tests.benchmark import mpoly_all
1873
+ sage: mpoly_all() # not tested
1874
+ <BLANKLINE>
1875
+ ...
1876
+ ...System min avg max trials cpu or wall
1877
+ ...
1878
+ * sage...
1879
+ """
1880
+ systems = ['sage', 'magma', 'mathematica', 'macaulay2']
1881
+ if include_maple:
1882
+ systems.append('maple')
1883
+ MPolynomialMult(200).run(systems=systems)
1884
+ MPolynomialMult(400).run(systems=systems)
1885
+ MPolynomialMult2(256).run(systems=systems)
1886
+ MPolynomialMult2(512).run(systems=systems)
1887
+ MPolynomialPower(nvars=4, exp=50).run(systems=systems) # mathematica wins
1888
+ MPolynomialPower(nvars=10, exp=10).run(systems=systems)
1889
+
1890
+
1891
+ def modsym_present():
1892
+ ModularSymbols1(2006, 2)
1893
+ ModularSymbols1(1, 50)
1894
+ ModularSymbols1(1, 100)
1895
+ ModularSymbols1(1, 150)
1896
+ ModularSymbols1(30, 8)
1897
+ ModularSymbols1(225, 4)
1898
+ ModularSymbols1(2, 50)
1899
+ ModularSymbols1(2, 100)
1900
+
1901
+
1902
+ def modsym_decomp():
1903
+ ModularSymbolsDecomp1(1, 24).run()
1904
+ ModularSymbolsDecomp1(125, 2).run()
1905
+ ModularSymbolsDecomp1(389, 2).run()
1906
+ ModularSymbolsDecomp1(1, 100).run()
1907
+ ModularSymbolsDecomp1(54, 4).run()
1908
+
1909
+
1910
+ def elliptic_curve():
1911
+ EllipticCurveTraces(100000).run()
1912
+ EllipticCurveTraces(500000).run()
1913
+ Divpoly(59).run()
1914
+ EllipticCurvePointMul(1000).run()
1915
+ EllipticCurvePointMul(2000).run()
1916
+ EllipticCurvePointMul(2500).run() # sage is clearly using the wrong algorithm -- maybe need a balanced rep!?
1917
+
1918
+ # NOTE -- Sage can also do these using Simon's program, which is
1919
+ # *way* *way* faster than MAGMA...
1920
+ EllipticCurveMW([5, 6, 7, 8, 9]).run()
1921
+ EllipticCurveMW([50, 6, 7, 8, 9]).run()
1922
+ EllipticCurveMW([1, -1, 0, -79, 289]).run(trials=1) # rank 4
1923
+ EllipticCurveMW([0, 0, 1, -79, 342]).run(trials=1) # rank 5 (Sage wins)