passagemath-standard-no-symbolics 10.6.31rc3__cp314-cp314-macosx_13_0_arm64.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.

Potentially problematic release.


This version of passagemath-standard-no-symbolics might be problematic. Click here for more details.

Files changed (82) hide show
  1. passagemath_standard_no_symbolics-10.6.31rc3.data/scripts/sage-grep +5 -0
  2. passagemath_standard_no_symbolics-10.6.31rc3.data/scripts/sage-grepdoc +5 -0
  3. passagemath_standard_no_symbolics-10.6.31rc3.data/scripts/sage-list-packages +103 -0
  4. passagemath_standard_no_symbolics-10.6.31rc3.dist-info/METADATA +151 -0
  5. passagemath_standard_no_symbolics-10.6.31rc3.dist-info/RECORD +82 -0
  6. passagemath_standard_no_symbolics-10.6.31rc3.dist-info/WHEEL +6 -0
  7. passagemath_standard_no_symbolics-10.6.31rc3.dist-info/top_level.txt +1 -0
  8. sage/all.py +207 -0
  9. sage/all_cmdline.py +36 -0
  10. sage/cli/__init__.py +61 -0
  11. sage/cli/__main__.py +5 -0
  12. sage/cli/eval_cmd.py +45 -0
  13. sage/cli/eval_cmd_test.py +25 -0
  14. sage/cli/interactive_shell_cmd.py +28 -0
  15. sage/cli/notebook_cmd.py +51 -0
  16. sage/cli/notebook_cmd_test.py +39 -0
  17. sage/cli/options.py +26 -0
  18. sage/cli/run_file_cmd.py +50 -0
  19. sage/cli/version_cmd.py +26 -0
  20. sage/databases/all.py +83 -0
  21. sage/databases/cubic_hecke_db.py +1527 -0
  22. sage/dynamics/all.py +31 -0
  23. sage/dynamics/surface_dynamics_deprecation.py +32 -0
  24. sage/ext_data/kenzo/CP2.txt +45 -0
  25. sage/ext_data/kenzo/CP3.txt +349 -0
  26. sage/ext_data/kenzo/CP4.txt +4774 -0
  27. sage/ext_data/kenzo/README.txt +49 -0
  28. sage/ext_data/kenzo/S4.txt +20 -0
  29. sage/ext_data/mwrank/PRIMES +1 -0
  30. sage/ext_data/nbconvert/postprocess.py +48 -0
  31. sage/ext_data/nbconvert/rst_sage.tpl +99 -0
  32. sage/ext_data/nodoctest +0 -0
  33. sage/ext_data/notebook-ipython/kernel.json.in +11 -0
  34. sage/ext_data/notebook-ipython/logo-64x64.png +0 -0
  35. sage/ext_data/notebook-ipython/logo.svg +352 -0
  36. sage/ext_data/valgrind/pyalloc.supp +58 -0
  37. sage/ext_data/valgrind/sage-additional.supp +417 -0
  38. sage/ext_data/valgrind/sage.supp +43 -0
  39. sage/ext_data/valgrind/valgrind-python.supp +480 -0
  40. sage/geometry/all.py +12 -0
  41. sage/groups/matrix_gps/pickling_overrides.py +110 -0
  42. sage/homology/tests.py +66 -0
  43. sage/interacts/algebra.py +20 -0
  44. sage/interacts/all.py +25 -0
  45. sage/interacts/calculus.py +24 -0
  46. sage/interacts/fractals.py +18 -0
  47. sage/interacts/geometry.py +19 -0
  48. sage/interacts/library.py +1950 -0
  49. sage/interacts/library_cython.cpython-314-darwin.so +0 -0
  50. sage/interacts/statistics.py +19 -0
  51. sage/interfaces/axiom.py +1002 -0
  52. sage/interfaces/kash.py +834 -0
  53. sage/interfaces/lie.py +950 -0
  54. sage/interfaces/matlab.py +413 -0
  55. sage/interfaces/mupad.py +686 -0
  56. sage/interfaces/octave.py +858 -0
  57. sage/interfaces/phc.py +943 -0
  58. sage/interfaces/psage.py +189 -0
  59. sage/interfaces/qsieve.py +4 -0
  60. sage/interfaces/r.py +2096 -0
  61. sage/interfaces/read_data.py +46 -0
  62. sage/interfaces/scilab.py +576 -0
  63. sage/interfaces/tests.py +81 -0
  64. sage/libs/all.py +11 -0
  65. sage/libs/cremona/__init__.py +0 -0
  66. sage/libs/mwrank/__init__.py +0 -0
  67. sage/logic/all.py +3 -0
  68. sage/logic/booleval.py +160 -0
  69. sage/logic/boolformula.py +1490 -0
  70. sage/logic/logic.py +856 -0
  71. sage/logic/logicparser.py +696 -0
  72. sage/logic/logictable.py +272 -0
  73. sage/logic/propcalc.py +311 -0
  74. sage/misc/all.py +28 -0
  75. sage/misc/lazy_attribute.pyi +11 -0
  76. sage/rings/all.py +48 -0
  77. sage/rings/commutative_algebra.py +38 -0
  78. sage/rings/finite_rings/all.py +21 -0
  79. sage/rings/numbers_abc.py +58 -0
  80. sage/rings/polynomial/all.py +22 -0
  81. sage/rings/polynomial/convolution.py +421 -0
  82. sage/symbolic/all__sagemath_standard_no_symbolics.py +0 -0
@@ -0,0 +1,1002 @@
1
+ r"""
2
+ Interface to Axiom
3
+
4
+ .. TODO::
5
+
6
+ - Evaluation using a file is not done. Any input line with more than a
7
+ few thousand characters would hang the system, so currently it
8
+ automatically raises an exception.
9
+
10
+ - All completions of a given command.
11
+
12
+ - Interactive help.
13
+
14
+ Axiom is a free GPL-compatible (modified BSD license) general
15
+ purpose computer algebra system whose development started in 1973
16
+ at IBM. It contains symbolic manipulation algorithms, as well as
17
+ implementations of special functions, including elliptic functions
18
+ and generalized hypergeometric functions. Moreover, Axiom has
19
+ implementations of many functions relating to the invariant theory
20
+ of the symmetric group `S_n.` For many links to Axiom
21
+ documentation see http://wiki.axiom-developer.org.
22
+
23
+ AUTHORS:
24
+
25
+ - Bill Page (2006-10): Created this (based on Maxima interface)
26
+
27
+
28
+ .. NOTE::
29
+
30
+ Bill Page put a huge amount of effort into the Sage Axiom
31
+ interface over several days during the Sage Days 2 coding
32
+ sprint. This is contribution is greatly appreciated.
33
+
34
+ - William Stein (2006-10): misc touchup.
35
+
36
+ - Bill Page (2007-08): Minor modifications to support axiom4sage-0.3
37
+
38
+ .. NOTE::
39
+
40
+ The axiom4sage-0.3.spkg is based on an experimental version of the
41
+ FriCAS fork of the Axiom project by Waldek Hebisch that uses
42
+ pre-compiled cached Lisp code to build Axiom very quickly with
43
+ clisp.
44
+
45
+ If the string "error" (case insensitive) occurs in the output of
46
+ anything from axiom, a :exc:`RuntimeError` exception is raised.
47
+
48
+ EXAMPLES: We evaluate a very simple expression in axiom.
49
+
50
+ ::
51
+
52
+ sage: axiom('3 * 5') #optional - axiom
53
+ 15
54
+ sage: a = axiom(3) * axiom(5); a #optional - axiom
55
+ 15
56
+
57
+ The type of a is AxiomElement, i.e., an element of the axiom
58
+ interpreter.
59
+
60
+ ::
61
+
62
+ sage: type(a) #optional - axiom
63
+ <class 'sage.interfaces.axiom.AxiomElement'>
64
+ sage: parent(a) #optional - axiom
65
+ Axiom
66
+
67
+ The underlying Axiom type of a is also available, via the type
68
+ method::
69
+
70
+ sage: a.type() #optional - axiom
71
+ PositiveInteger
72
+
73
+ We factor `x^5 - y^5` in Axiom in several different ways.
74
+ The first way yields a Axiom object.
75
+
76
+ ::
77
+
78
+ sage: F = axiom.factor('x^5 - y^5'); F #optional - axiom
79
+ 4 3 2 2 3 4
80
+ - (y - x)(y + x y + x y + x y + x )
81
+ sage: type(F) #optional - axiom
82
+ <class 'sage.interfaces.axiom.AxiomElement'>
83
+ sage: F.type() #optional - axiom
84
+ Factored Polynomial Integer
85
+
86
+ Note that Axiom objects are normally displayed using "ASCII art".
87
+
88
+ ::
89
+
90
+ sage: a = axiom(2/3); a #optional - axiom
91
+ 2
92
+ -
93
+ 3
94
+ sage: a = axiom('x^2 + 3/7'); a #optional - axiom
95
+ 2 3
96
+ x + -
97
+ 7
98
+
99
+ The ``axiom.eval`` command evaluates an expression in
100
+ axiom and returns the result as a string. This is exact as if we
101
+ typed in the given line of code to axiom; the return value is what
102
+ Axiom would print out.
103
+
104
+ ::
105
+
106
+ sage: print(axiom.eval('factor(x^5 - y^5)')) # optional - axiom
107
+ 4 3 2 2 3 4
108
+ - (y - x)(y + x y + x y + x y + x )
109
+ Type: Factored Polynomial Integer
110
+
111
+ We can create the polynomial `f` as a Axiom polynomial,
112
+ then call the factor method on it. Notice that the notation
113
+ ``f.factor()`` is consistent with how the rest of Sage
114
+ works.
115
+
116
+ ::
117
+
118
+ sage: f = axiom('x^5 - y^5') #optional - axiom
119
+ sage: f^2 #optional - axiom
120
+ 10 5 5 10
121
+ y - 2x y + x
122
+ sage: f.factor() #optional - axiom
123
+ 4 3 2 2 3 4
124
+ - (y - x)(y + x y + x y + x y + x )
125
+
126
+ Control-C interruption works well with the axiom interface, because
127
+ of the excellent implementation of axiom. For example, try the
128
+ following sum but with a much bigger range, and hit control-C.
129
+
130
+ ::
131
+
132
+ sage: f = axiom('(x^5 - y^5)^10000') # not tested
133
+ Interrupting Axiom...
134
+ ...
135
+ <class 'exceptions.TypeError'>: Ctrl-c pressed while running Axiom
136
+
137
+ ::
138
+
139
+ sage: axiom('1/100 + 1/101') #optional - axiom
140
+ 201
141
+ -----
142
+ 10100
143
+ sage: a = axiom('(1 + sqrt(2))^5'); a #optional - axiom
144
+ +-+
145
+ 29\|2 + 41
146
+
147
+ TESTS:
148
+
149
+ We check to make sure the subst method works with keyword
150
+ arguments.
151
+
152
+ ::
153
+
154
+ sage: a = axiom(x+2); a #optional - axiom
155
+ x + 2
156
+ sage: a.subst(x=3) #optional - axiom
157
+ 5
158
+
159
+ We verify that Axiom floating point numbers can be converted to
160
+ Python floats.
161
+
162
+ ::
163
+
164
+ sage: float(axiom(2)) #optional - axiom
165
+ 2.0
166
+ """
167
+
168
+ ###########################################################################
169
+ # Copyright (C) 2008 Mike Hansen <mhansen@gmail.com>
170
+ # 2007 Bill Page
171
+ # 2006 William Stein <wstein@gmail.com>
172
+ #
173
+ # Distributed under the terms of the GNU General Public License (GPL)
174
+ # The full text of the GPL is available at:
175
+ #
176
+ # https://www.gnu.org/licenses/
177
+ ###########################################################################
178
+
179
+ import os
180
+ import re
181
+
182
+ import sage.interfaces.abc
183
+
184
+ from .expect import Expect, ExpectElement, FunctionElement, ExpectFunction
185
+ from sage.env import DOT_SAGE
186
+ from pexpect import EOF
187
+ from sage.misc.multireplace import multiple_replace
188
+ from sage.interfaces.tab_completion import ExtraTabCompletion
189
+ from sage.misc.instancedoc import instancedoc
190
+ from sage.structure.richcmp import rich_to_bool
191
+
192
+
193
+ # The Axiom commands ")what thing det" ")show Matrix" and ")display
194
+ # op det" commands, gives a list of all identifiers that begin in
195
+ # a certain way. This could maybe be useful somehow... (?) Also
196
+ # axiom has a lot a lot of ways for getting documentation from the
197
+ # system -- this could also be useful.
198
+
199
+ class PanAxiom(ExtraTabCompletion, Expect):
200
+ """
201
+ Interface to a PanAxiom interpreter.
202
+ """
203
+ def __init__(self, name='axiom', command='axiom -nox -noclef',
204
+ script_subdirectory=None, logfile=None,
205
+ server=None, server_tmpdir=None,
206
+ init_code=[')lisp (si::readline-off)']):
207
+ """
208
+ Create an instance of the Axiom interpreter.
209
+
210
+ TESTS::
211
+
212
+ sage: axiom == loads(dumps(axiom))
213
+ True
214
+ """
215
+ eval_using_file_cutoff = 200
216
+ self.__eval_using_file_cutoff = eval_using_file_cutoff
217
+ self._COMMANDS_CACHE = '%s/%s_commandlist_cache.sobj' % (DOT_SAGE, name)
218
+ Expect.__init__(self,
219
+ name=name,
220
+ prompt=r'\([0-9]+\) -> ',
221
+ command=command,
222
+ script_subdirectory=script_subdirectory,
223
+ server=server,
224
+ server_tmpdir=server_tmpdir,
225
+ restart_on_ctrlc=False,
226
+ verbose_start=False,
227
+ init_code=init_code,
228
+ logfile=logfile,
229
+ eval_using_file_cutoff=eval_using_file_cutoff)
230
+ self._prompt_wait = self._prompt
231
+
232
+ def _start(self):
233
+ """
234
+ Start the Axiom interpreter.
235
+
236
+ EXAMPLES::
237
+
238
+ sage: a = Axiom()
239
+ sage: a.is_running()
240
+ False
241
+ sage: a._start() #optional - axiom
242
+ sage: a.is_running() #optional - axiom
243
+ True
244
+ sage: a.quit() #optional - axiom
245
+ """
246
+ Expect._start(self)
247
+ self._eval_line(')set functions compile on', reformat=False)
248
+ self._eval_line(')set output length 245', reformat=False)
249
+ self._eval_line(')set message autoload off', reformat=False)
250
+
251
+ def _read_in_file_command(self, filename):
252
+ r"""
253
+ EXAMPLES::
254
+
255
+ sage: axiom._read_in_file_command('test.input')
256
+ ')read test.input \n'
257
+ sage: axiom._read_in_file_command('test')
258
+ Traceback (most recent call last):
259
+ ...
260
+ ValueError: the filename must end with .input
261
+
262
+ ::
263
+
264
+ sage: filename = tmp_filename(ext='.input')
265
+ sage: f = open(filename, 'w')
266
+ sage: _ = f.write('xx := 22;\n')
267
+ sage: f.close()
268
+ sage: axiom.read(filename) # optional - axiom
269
+ sage: axiom.get('xx') # optional - axiom
270
+ '22'
271
+ """
272
+ if not filename.endswith('.input'):
273
+ raise ValueError("the filename must end with .input")
274
+
275
+ # For some reason this trivial comp
276
+ # keeps certain random freezes from occurring. Do not remove this.
277
+ # The space before the \n is also important.
278
+ return ')read %s \n' % filename
279
+
280
+ def _quit_string(self):
281
+ """
282
+ Return the string used to quit Axiom.
283
+
284
+ EXAMPLES::
285
+
286
+ sage: axiom._quit_string()
287
+ ')lisp (quit)'
288
+ sage: a = Axiom()
289
+ sage: a.is_running()
290
+ False
291
+ sage: a._start() #optional - axiom
292
+ sage: a.is_running() #optional - axiom
293
+ True
294
+ sage: a.quit() #optional - axiom
295
+ sage: a.is_running() #optional - axiom
296
+ False
297
+ """
298
+ return ')lisp (quit)'
299
+
300
+ def _commands(self):
301
+ """
302
+ Return a list of commands available. This is done by parsing the
303
+ result of the first section of the output of ')what things'.
304
+
305
+ EXAMPLES::
306
+
307
+ sage: # optional - axiom
308
+ sage: cmds = axiom._commands()
309
+ sage: len(cmds) > 100
310
+ True
311
+ sage: '<' in cmds
312
+ True
313
+ sage: 'factor' in cmds
314
+ True
315
+ """
316
+ s = self.eval(")what things")
317
+ start = '\r\n\r\n#'
318
+ i = s.find(start)
319
+ end = "To get more information about"
320
+ j = s.find(end)
321
+ return s[i + len(start):j].split()
322
+
323
+ def _tab_completion(self, verbose=True, use_disk_cache=True):
324
+ """
325
+ Return a list of all the commands defined in Axiom and optionally
326
+ (per default) store them to disk.
327
+
328
+ EXAMPLES::
329
+
330
+ sage: # optional - axiom
331
+ sage: c = axiom._tab_completion(use_disk_cache=False, verbose=False)
332
+ sage: len(c) > 100
333
+ True
334
+ sage: 'factor' in c
335
+ True
336
+ sage: '**' in c
337
+ False
338
+ sage: 'upperCase?' in c
339
+ False
340
+ sage: 'upperCase_q' in c
341
+ True
342
+ sage: 'upperCase_e' in c
343
+ True
344
+ """
345
+ try:
346
+ return self.__tab_completion
347
+ except AttributeError:
348
+ import sage.misc.persist
349
+ if use_disk_cache:
350
+ try:
351
+ self.__tab_completion = sage.misc.persist.load(self._COMMANDS_CACHE)
352
+ return self.__tab_completion
353
+ except OSError:
354
+ pass
355
+ if verbose:
356
+ print("\nBuilding %s command completion list (this takes" % self)
357
+ print("a few seconds only the first time you do it).")
358
+ print("To force rebuild later, delete %s." % self._COMMANDS_CACHE)
359
+ v = self._commands()
360
+
361
+ # Process we now need process the commands to strip out things which
362
+ # are not valid Python identifiers.
363
+ valid = re.compile('[^a-zA-Z0-9_]+')
364
+ names = [x for x in v if valid.search(x) is None]
365
+
366
+ # Change everything that ends with ? to _q and
367
+ # everything that ends with ! to _e
368
+ names += [x[:-1] + "_q" for x in v if x.endswith("?")]
369
+ names += [x[:-1] + "_e" for x in v if x.endswith("!")]
370
+
371
+ self.__tab_completion = names
372
+ if len(v) > 200:
373
+ # Axiom is actually installed.
374
+ sage.misc.persist.save(v, self._COMMANDS_CACHE)
375
+ return names
376
+
377
+ def set(self, var, value):
378
+ """
379
+ Set the variable var to the given value.
380
+
381
+ EXAMPLES::
382
+
383
+ sage: axiom.set('xx', '2') #optional - axiom
384
+ sage: axiom.get('xx') #optional - axiom
385
+ '2'
386
+ """
387
+ cmd = '%s := %s' % (var, value)
388
+ out = self._eval_line(cmd, reformat=False)
389
+
390
+ if out.find("error") != -1:
391
+ raise TypeError("Error executing code in Axiom\nCODE:\n\t%s\nAxiom ERROR:\n\t%s" % (cmd, out))
392
+
393
+ def get(self, var):
394
+ r"""
395
+ Get the string value of the Axiom variable var.
396
+
397
+ EXAMPLES::
398
+
399
+ sage: # optional - axiom
400
+ sage: axiom.set('xx', '2')
401
+ sage: axiom.get('xx')
402
+ '2'
403
+ sage: a = axiom('(1 + sqrt(2))^5')
404
+ sage: axiom.get(a.name())
405
+ ' +-+\r\r\n 29\\|2 + 41'
406
+ """
407
+ s = self._eval_line(str(var))
408
+ i = s.rfind('Type:')
409
+ s = s[:i].rstrip().lstrip("\n")
410
+ if '\n' not in s:
411
+ s = s.strip()
412
+ return s
413
+
414
+ def _eval_line(self, line, reformat=True, allow_use_file=False,
415
+ wait_for_prompt=True, restart_if_needed=False):
416
+ """
417
+ EXAMPLES::
418
+
419
+ sage: print(axiom._eval_line('2+2')) # optional - axiom
420
+ 4
421
+ Type: PositiveInteger
422
+ """
423
+ from sage.misc.verbose import verbose
424
+ if not wait_for_prompt:
425
+ return Expect._eval_line(self, line)
426
+ line = line.rstrip().rstrip(';')
427
+ if line == '':
428
+ return ''
429
+ if len(line) > 3000:
430
+ raise NotImplementedError("evaluation of long input lines (>3000 characters) in Axiom not yet implemented.")
431
+ if self._expect is None:
432
+ self._start()
433
+ if allow_use_file and self.__eval_using_file_cutoff and \
434
+ len(line) > self.__eval_using_file_cutoff:
435
+ return self._eval_line_using_file(line)
436
+ try:
437
+ E = self._expect
438
+ # debug
439
+ # self._synchronize(cmd='1+%s\n')
440
+ verbose("in = '%s'" % line, level=3)
441
+ E.sendline(line)
442
+ self._expect.expect(self._prompt)
443
+ out = self._expect.before
444
+ # debug
445
+ verbose("out = '%s'" % out, level=3)
446
+ except EOF:
447
+ if self._quit_string() in line:
448
+ return ''
449
+ except KeyboardInterrupt:
450
+ self._keyboard_interrupt()
451
+
452
+ if '>> Error detected within library code:' in out or \
453
+ 'Cannot find a definition or applicable library operation named' in out:
454
+ raise RuntimeError(out)
455
+
456
+ if not reformat:
457
+ return out
458
+ if 'error' in out:
459
+ return out
460
+ # out = out.lstrip()
461
+ i = out.find('\n')
462
+ out = out[i+1:]
463
+ outs = out.split("\n")
464
+ i = 0
465
+ for line in outs:
466
+ line = line.rstrip()
467
+ if line[:4] == ' (':
468
+ i = line.find('(')
469
+ i += line[i:].find(')') + 1
470
+ if line[i:] == "":
471
+ i = 0
472
+ outs = outs[1:]
473
+ break
474
+ return "\n".join(line[i:] for line in outs[1:])
475
+
476
+ # define relational operators
477
+ def _equality_symbol(self):
478
+ """equality symbol
479
+
480
+ EXAMPLES::
481
+
482
+ sage: a = axiom(x==6); a #optional axiom
483
+ x= 6
484
+ """
485
+ return "="
486
+
487
+
488
+ class Axiom(PanAxiom):
489
+ def __reduce__(self):
490
+ """
491
+ EXAMPLES::
492
+
493
+ sage: Axiom().__reduce__()
494
+ (<function reduce_load_Axiom at 0x...>, ())
495
+ sage: f, args = _
496
+ sage: f(*args)
497
+ Axiom
498
+ """
499
+ return reduce_load_Axiom, tuple([])
500
+
501
+ def _function_class(self):
502
+ """
503
+ Return the AxiomExpectFunction class.
504
+
505
+ EXAMPLES::
506
+
507
+ sage: axiom._function_class()
508
+ <class 'sage.interfaces.axiom.PanAxiomExpectFunction'>
509
+ sage: type(axiom.gcd)
510
+ <class 'sage.interfaces.axiom.PanAxiomExpectFunction'>
511
+ """
512
+ return AxiomExpectFunction
513
+
514
+ def _object_class(self):
515
+ """
516
+ EXAMPLES::
517
+
518
+ sage: axiom._object_class()
519
+ <class 'sage.interfaces.axiom.PanAxiomElement'>
520
+ sage: type(axiom(2)) #optional - axiom
521
+ <class 'sage.interfaces.axiom.PanAxiomElement'>
522
+ """
523
+ return AxiomElement
524
+
525
+ def _function_element_class(self):
526
+ """
527
+ Return the Axiom function element class.
528
+
529
+ EXAMPLES::
530
+
531
+ sage: axiom._function_element_class()
532
+ <class 'sage.interfaces.axiom.PanAxiomFunctionElement'>
533
+ sage: type(axiom(2).gcd) #optional - axiom
534
+ <class 'sage.interfaces.axiom.PanAxiomFunctionElement'>
535
+ """
536
+ return AxiomFunctionElement
537
+
538
+ def console(self):
539
+ """
540
+ Spawn a new Axiom command-line session.
541
+
542
+ EXAMPLES::
543
+
544
+ sage: axiom.console() #not tested
545
+ AXIOM Computer Algebra System
546
+ Version: Axiom (January 2009)
547
+ Timestamp: Sunday January 25, 2009 at 07:08:54
548
+ -----------------------------------------------------------------------------
549
+ Issue )copyright to view copyright notices.
550
+ Issue )summary for a summary of useful system commands.
551
+ Issue )quit to leave AXIOM and return to shell.
552
+ -----------------------------------------------------------------------------
553
+ """
554
+ axiom_console()
555
+
556
+
557
+ @instancedoc
558
+ class PanAxiomElement(ExpectElement, sage.interfaces.abc.AxiomElement):
559
+ def __call__(self, x):
560
+ """
561
+ EXAMPLES::
562
+
563
+ sage: f = axiom(x+2) #optional - axiom
564
+ sage: f(2) #optional - axiom
565
+ 4
566
+ """
567
+ self._check_valid()
568
+ P = self.parent()
569
+ return P('%s(%s)' % (self.name(), x))
570
+
571
+ def _richcmp_(self, other, op):
572
+ """
573
+ EXAMPLES::
574
+
575
+ sage: # optional - axiom
576
+ sage: two = axiom(2)
577
+ sage: two == 2
578
+ True
579
+ sage: two == 3
580
+ False
581
+ sage: two < 3
582
+ True
583
+ sage: two > 1
584
+ True
585
+
586
+ sage: # optional - axiom
587
+ sage: a = axiom(1); b = axiom(2)
588
+ sage: a == b
589
+ False
590
+ sage: a < b
591
+ True
592
+ sage: a > b
593
+ False
594
+ sage: b < a
595
+ False
596
+ sage: b > a
597
+ True
598
+
599
+ We can also compare more complicated object such as functions::
600
+
601
+ sage: f = axiom('sin(x)'); g = axiom('cos(x)') #optional - axiom
602
+ sage: f == g #optional - axiom
603
+ False
604
+ """
605
+ P = self.parent()
606
+ if 'true' in P.eval("(%s = %s) :: Boolean" % (self.name(), other.name())):
607
+ return rich_to_bool(op, 0)
608
+ elif 'true' in P.eval("(%s < %s) :: Boolean" % (self.name(), other.name())):
609
+ return rich_to_bool(op, -1)
610
+ elif 'true' in P.eval("(%s > %s) :: Boolean" % (self.name(), other.name())):
611
+ return rich_to_bool(op, 1)
612
+
613
+ return NotImplemented
614
+
615
+ def type(self):
616
+ """
617
+ Return the type of an AxiomElement.
618
+
619
+ EXAMPLES::
620
+
621
+ sage: axiom(x+2).type() #optional - axiom
622
+ Polynomial Integer
623
+ """
624
+ P = self._check_valid()
625
+ s = P._eval_line(self.name())
626
+ i = s.rfind('Type:')
627
+ return P(s[i+5:].strip())
628
+
629
+ def __len__(self):
630
+ """
631
+ Return the length of a list.
632
+
633
+ EXAMPLES::
634
+
635
+ sage: v = axiom('[x^i for i in 0..5]') # optional - axiom
636
+ sage: len(v) # optional - axiom
637
+ 6
638
+ """
639
+ P = self._check_valid()
640
+ s = P.eval('# %s ' % self.name())
641
+ i = s.rfind('Type')
642
+ return int(s[:i - 1])
643
+
644
+ def __getitem__(self, n):
645
+ r"""
646
+ Return the `n`-th element of this list.
647
+
648
+ .. NOTE::
649
+
650
+ Lists are 1-based.
651
+
652
+ EXAMPLES::
653
+
654
+ sage: # optional - axiom
655
+ sage: v = axiom('[i*x^i for i in 0..5]'); v
656
+ 2 3 4 5
657
+ [0,x,2x ,3x ,4x ,5x ]
658
+ sage: v[4]
659
+ 3
660
+ 3x
661
+ sage: v[1]
662
+ 0
663
+ sage: v[10]
664
+ Traceback (most recent call last):
665
+ ...
666
+ IndexError: index out of range
667
+ """
668
+ n = int(n)
669
+ if n <= 0 or n > len(self):
670
+ raise IndexError("index out of range")
671
+ P = self._check_valid()
672
+ if not isinstance(n, tuple):
673
+ return P.new('%s(%s)' % (self._name, n))
674
+ else:
675
+ return P.new('%s(%s)' % (self._name, str(n)[1:-1]))
676
+
677
+ def comma(self, *args):
678
+ """
679
+ Return an Axiom tuple from ``self`` and ``args``.
680
+
681
+ EXAMPLES::
682
+
683
+ sage: # optional - axiom
684
+ sage: two = axiom(2)
685
+ sage: two.comma(3)
686
+ [2,3]
687
+ sage: two.comma(3,4)
688
+ [2,3,4]
689
+ sage: _.type()
690
+ Tuple PositiveInteger
691
+ """
692
+ P = self._check_valid()
693
+ args = list(args)
694
+ for i, arg in enumerate(args):
695
+ if not isinstance(arg, AxiomElement) or arg.parent() is not P:
696
+ args[i] = P(arg)
697
+ cmd = "(" + ",".join(x.name() for x in [self] + args) + ")"
698
+ return P(cmd)
699
+
700
+ def _latex_(self):
701
+ r"""
702
+ EXAMPLES::
703
+
704
+ sage: a = axiom(1/2) #optional - axiom
705
+ sage: latex(a) #optional - axiom
706
+ \frac{1}{2}
707
+ """
708
+ self._check_valid()
709
+ P = self.parent()
710
+ s = P._eval_line('outputAsTex(%s)' % self.name(), reformat=False)
711
+ if '$$' not in s:
712
+ raise RuntimeError("Error texing axiom object.")
713
+ i = s.find('$$')
714
+ j = s.rfind('$$')
715
+ s = s[i + 2:j]
716
+ s = multiple_replace({'\r': '', '\n': ' ',
717
+ ' \\sp ': '^',
718
+ '\\arcsin ': '\\sin^{-1} ',
719
+ '\\arccos ': '\\cos^{-1} ',
720
+ '\\arctan ': '\\tan^{-1} '},
721
+ re.sub(r'\\leqno\(.*?\)', '', s)) # no eq number!
722
+ return s
723
+
724
+ def as_type(self, type):
725
+ """
726
+ Return ``self`` as type.
727
+
728
+ EXAMPLES::
729
+
730
+ sage: a = axiom(1.2); a #optional - axiom
731
+ 1.2
732
+ sage: a.as_type(axiom.DoubleFloat) #optional - axiom
733
+ 1.2
734
+ sage: _.type() #optional - axiom
735
+ DoubleFloat
736
+ """
737
+ P = self._check_valid()
738
+ type = P(type)
739
+ return P.new("%s :: %s" % (self.name(), type.name()))
740
+
741
+ def unparsed_input_form(self):
742
+ """
743
+ Get the linear string representation of this object, if possible
744
+ (often it isn't).
745
+
746
+ EXAMPLES::
747
+
748
+ sage: a = axiom(x^2+1); a #optional - axiom
749
+ 2
750
+ x + 1
751
+ sage: a.unparsed_input_form() #optional - axiom
752
+ 'x*x+1'
753
+ """
754
+ P = self._check_valid()
755
+ s = P.eval('unparse(%s::InputForm)' % self._name)
756
+ if 'translation error' in s or 'Cannot convert' in s:
757
+ raise NotImplementedError
758
+ s = multiple_replace({'\r\n': '', # fix stupid Fortran-ish
759
+ 'DSIN(': 'sin(',
760
+ 'DCOS(': 'cos(',
761
+ 'DTAN(': 'tan(',
762
+ 'DSINH(': 'sinh('}, s)
763
+ r = re.search(r'"(.*)"', s)
764
+ return r.groups(0)[0] if r else s
765
+
766
+ def _sage_(self):
767
+ """
768
+ Convert ``self`` to a Sage object.
769
+
770
+ EXAMPLES::
771
+
772
+ sage: a = axiom(1/2); a #optional - axiom
773
+ 1
774
+ -
775
+ 2
776
+ sage: a.sage() #optional - axiom
777
+ 1/2
778
+ sage: _.parent() #optional - axiom
779
+ Rational Field
780
+
781
+ sage: gp(axiom(1/2)) #optional - axiom
782
+ 1/2
783
+
784
+ DoubleFloat's in Axiom are converted to be in RDF in Sage.
785
+
786
+ ::
787
+
788
+ sage: axiom(2.0).as_type('DoubleFloat').sage() #optional - axiom
789
+ 2.0
790
+ sage: _.parent() #optional - axiom
791
+ Real Double Field
792
+
793
+
794
+ sage: axiom(2.1234)._sage_() #optional - axiom
795
+ 2.12340000000000
796
+ sage: _.parent() #optional - axiom
797
+ Real Field with 53 bits of precision
798
+ sage: a = RealField(100)(pi) # needs sage.symbolic
799
+ sage: axiom(a)._sage_() # optional - axiom # needs sage.symbolic
800
+ 3.1415926535897932384626433833
801
+ sage: _.parent() # optional - axiom # needs sage.symbolic
802
+ Real Field with 100 bits of precision
803
+ sage: axiom(a)._sage_() == a # optional - axiom # needs sage.symbolic
804
+ True
805
+ sage: axiom(2.0)._sage_() #optional - axiom
806
+ 2.00000000000000
807
+ sage: _.parent() #optional - axiom
808
+ Real Field with 53 bits of precision
809
+
810
+
811
+ We can also convert Axiom's polynomials to Sage polynomials.
812
+ sage: # optional - axiom, needs sage.symbolic
813
+ sage: a = axiom(x^2 + 1)
814
+ sage: a.type()
815
+ Polynomial Integer
816
+ sage: a.sage()
817
+ x^2 + 1
818
+ sage: _.parent()
819
+ Univariate Polynomial Ring in x over Integer Ring
820
+ sage: axiom('x^2 + y^2 + 1/2').sage()
821
+ y^2 + x^2 + 1/2
822
+ sage: _.parent()
823
+ Multivariate Polynomial Ring in y, x over Rational Field
824
+ """
825
+ P = self._check_valid()
826
+ type = str(self.type())
827
+
828
+ if type in ["Type", "Domain"]:
829
+ return self._sage_domain()
830
+
831
+ if type == "Float":
832
+ from sage.rings.real_mpfr import RealField
833
+ from sage.rings.integer_ring import ZZ
834
+ prec = max(self.mantissa().length()._sage_(), 53)
835
+ R = RealField(prec)
836
+ x, e, b = self.unparsed_input_form().lstrip('float(').rstrip(')').split(',')
837
+ return R(ZZ(x) * ZZ(b)**ZZ(e))
838
+ elif type == "DoubleFloat":
839
+ from sage.rings.real_double import RDF
840
+ return RDF(repr(self))
841
+ elif type in ["PositiveInteger", "Integer"]:
842
+ from sage.rings.integer_ring import ZZ
843
+ return ZZ(repr(self))
844
+ elif type.startswith('Polynomial'):
845
+ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
846
+ base_ring = P(type.removeprefix('Polynomial '))._sage_domain()
847
+ vars = str(self.variables())[1:-1]
848
+ R = PolynomialRing(base_ring, vars)
849
+ return R(self.unparsed_input_form())
850
+ elif type.startswith('Fraction'):
851
+ return self.numer().sage() / self.denom().sage()
852
+
853
+ # If all else fails, try using the unparsed input form
854
+ try:
855
+ import sage.misc.sage_eval
856
+ vars = sage.symbolic.ring.var(str(self.variables())[1:-1])
857
+ if isinstance(vars, tuple):
858
+ return sage.misc.sage_eval.sage_eval(self.unparsed_input_form(),
859
+ locals={str(x): x for x in vars})
860
+ else:
861
+ return sage.misc.sage_eval.sage_eval(self.unparsed_input_form(),
862
+ locals={str(vars): vars})
863
+ except Exception:
864
+ raise NotImplementedError
865
+
866
+ def _sage_domain(self):
867
+ """
868
+ A helper function for converting Axiom domains to the corresponding
869
+ Sage object.
870
+
871
+ EXAMPLES::
872
+
873
+ sage: axiom('Integer').sage() #optional - axiom
874
+ Integer Ring
875
+
876
+ sage: axiom('Fraction Integer').sage() #optional - axiom
877
+ Rational Field
878
+
879
+ sage: axiom('DoubleFloat').sage() #optional - axiom
880
+ Real Double Field
881
+ """
882
+ P = self._check_valid()
883
+ name = str(self)
884
+ if name == 'Integer':
885
+ from sage.rings.integer_ring import ZZ
886
+ return ZZ
887
+ elif name == 'DoubleFloat':
888
+ from sage.rings.real_double import RDF
889
+ return RDF
890
+ elif name.startswith('Fraction '):
891
+ return P(name.lstrip('Fraction '))._sage_domain().fraction_field()
892
+
893
+ raise NotImplementedError
894
+
895
+
896
+ AxiomElement = PanAxiomElement
897
+
898
+
899
+ @instancedoc
900
+ class PanAxiomFunctionElement(FunctionElement):
901
+ def __init__(self, object, name):
902
+ """
903
+ TESTS::
904
+
905
+ sage: # optional - axiom
906
+ sage: a = axiom('"Hello"')
907
+ sage: a.upperCase_q
908
+ upperCase?
909
+ sage: a.upperCase_e
910
+ upperCase!
911
+ sage: a.upperCase_e()
912
+ "HELLO"
913
+ """
914
+ if name.endswith("_q"):
915
+ name = name[:-2] + "?"
916
+ elif name.endswith("_e"):
917
+ name = name[:-2] + "!"
918
+ FunctionElement.__init__(self, object, name)
919
+
920
+
921
+ AxiomFunctionElement = PanAxiomFunctionElement
922
+
923
+
924
+ @instancedoc
925
+ class PanAxiomExpectFunction(ExpectFunction):
926
+ def __init__(self, parent, name):
927
+ """
928
+ TESTS::
929
+
930
+ sage: axiom.upperCase_q
931
+ upperCase?
932
+ sage: axiom.upperCase_e
933
+ upperCase!
934
+ """
935
+ if name.endswith("_q"):
936
+ name = name[:-2] + "?"
937
+ elif name.endswith("_e"):
938
+ name = name[:-2] + "!"
939
+ ExpectFunction.__init__(self, parent, name)
940
+
941
+
942
+ AxiomExpectFunction = PanAxiomExpectFunction
943
+
944
+
945
+ def is_AxiomElement(x):
946
+ """
947
+ Return ``True`` if ``x`` is of type :class:`AxiomElement`.
948
+
949
+ EXAMPLES::
950
+
951
+ sage: from sage.interfaces.axiom import is_AxiomElement
952
+ sage: is_AxiomElement(2)
953
+ doctest:...: DeprecationWarning: the function is_AxiomElement is deprecated; use isinstance(x, sage.interfaces.abc.AxiomElement) instead
954
+ See https://github.com/sagemath/sage/issues/34804 for details.
955
+ False
956
+ sage: is_AxiomElement(axiom(2)) # optional - axiom
957
+ True
958
+ """
959
+ from sage.misc.superseded import deprecation
960
+ deprecation(34804, "the function is_AxiomElement is deprecated; use isinstance(x, sage.interfaces.abc.AxiomElement) instead")
961
+
962
+ return isinstance(x, AxiomElement)
963
+
964
+
965
+ # Instances
966
+ axiom = Axiom(name='axiom')
967
+
968
+
969
+ def reduce_load_Axiom():
970
+ """
971
+ Return the Axiom interface object defined in
972
+ sage.interfaces.axiom.
973
+
974
+ EXAMPLES::
975
+
976
+ sage: from sage.interfaces.axiom import reduce_load_Axiom
977
+ sage: reduce_load_Axiom()
978
+ Axiom
979
+ """
980
+ return axiom
981
+
982
+
983
+ def axiom_console():
984
+ """
985
+ Spawn a new Axiom command-line session.
986
+
987
+ EXAMPLES::
988
+
989
+ sage: axiom_console() #not tested
990
+ AXIOM Computer Algebra System
991
+ Version: Axiom (January 2009)
992
+ Timestamp: Sunday January 25, 2009 at 07:08:54
993
+ -----------------------------------------------------------------------------
994
+ Issue )copyright to view copyright notices.
995
+ Issue )summary for a summary of useful system commands.
996
+ Issue )quit to leave AXIOM and return to shell.
997
+ -----------------------------------------------------------------------------
998
+ """
999
+ from sage.repl.rich_output.display_manager import get_display_manager
1000
+ if not get_display_manager().is_in_terminal():
1001
+ raise RuntimeError('Can use the console only in the terminal. Try %%axiom magics instead.')
1002
+ os.system('axiom -nox')