passagemath-standard-no-symbolics 10.6.45__cp313-cp313-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.
Files changed (83) hide show
  1. passagemath_standard_no_symbolics/__init__.py +1 -0
  2. passagemath_standard_no_symbolics-10.6.45.data/scripts/sage-grep +5 -0
  3. passagemath_standard_no_symbolics-10.6.45.data/scripts/sage-grepdoc +5 -0
  4. passagemath_standard_no_symbolics-10.6.45.data/scripts/sage-list-packages +103 -0
  5. passagemath_standard_no_symbolics-10.6.45.dist-info/METADATA +150 -0
  6. passagemath_standard_no_symbolics-10.6.45.dist-info/RECORD +83 -0
  7. passagemath_standard_no_symbolics-10.6.45.dist-info/WHEEL +6 -0
  8. passagemath_standard_no_symbolics-10.6.45.dist-info/top_level.txt +2 -0
  9. sage/all.py +207 -0
  10. sage/all_cmdline.py +36 -0
  11. sage/cli/__init__.py +61 -0
  12. sage/cli/__main__.py +5 -0
  13. sage/cli/eval_cmd.py +45 -0
  14. sage/cli/eval_cmd_test.py +25 -0
  15. sage/cli/interactive_shell_cmd.py +28 -0
  16. sage/cli/notebook_cmd.py +51 -0
  17. sage/cli/notebook_cmd_test.py +39 -0
  18. sage/cli/options.py +26 -0
  19. sage/cli/run_file_cmd.py +50 -0
  20. sage/cli/version_cmd.py +26 -0
  21. sage/databases/all.py +83 -0
  22. sage/databases/cubic_hecke_db.py +1527 -0
  23. sage/dynamics/all.py +31 -0
  24. sage/dynamics/surface_dynamics_deprecation.py +32 -0
  25. sage/ext_data/kenzo/CP2.txt +45 -0
  26. sage/ext_data/kenzo/CP3.txt +349 -0
  27. sage/ext_data/kenzo/CP4.txt +4774 -0
  28. sage/ext_data/kenzo/README.txt +49 -0
  29. sage/ext_data/kenzo/S4.txt +20 -0
  30. sage/ext_data/mwrank/PRIMES +1 -0
  31. sage/ext_data/nbconvert/postprocess.py +48 -0
  32. sage/ext_data/nbconvert/rst_sage.tpl +99 -0
  33. sage/ext_data/nodoctest +0 -0
  34. sage/ext_data/notebook-ipython/kernel.json.in +11 -0
  35. sage/ext_data/notebook-ipython/logo-64x64.png +0 -0
  36. sage/ext_data/notebook-ipython/logo.svg +352 -0
  37. sage/ext_data/valgrind/pyalloc.supp +58 -0
  38. sage/ext_data/valgrind/sage-additional.supp +417 -0
  39. sage/ext_data/valgrind/sage.supp +43 -0
  40. sage/ext_data/valgrind/valgrind-python.supp +480 -0
  41. sage/geometry/all.py +12 -0
  42. sage/groups/matrix_gps/pickling_overrides.py +110 -0
  43. sage/homology/tests.py +66 -0
  44. sage/interacts/algebra.py +20 -0
  45. sage/interacts/all.py +25 -0
  46. sage/interacts/calculus.py +24 -0
  47. sage/interacts/fractals.py +18 -0
  48. sage/interacts/geometry.py +19 -0
  49. sage/interacts/library.py +1950 -0
  50. sage/interacts/library_cython.cpython-313-darwin.so +0 -0
  51. sage/interacts/statistics.py +19 -0
  52. sage/interfaces/axiom.py +1002 -0
  53. sage/interfaces/kash.py +834 -0
  54. sage/interfaces/lie.py +950 -0
  55. sage/interfaces/matlab.py +413 -0
  56. sage/interfaces/mupad.py +686 -0
  57. sage/interfaces/octave.py +858 -0
  58. sage/interfaces/phc.py +943 -0
  59. sage/interfaces/psage.py +189 -0
  60. sage/interfaces/qsieve.py +4 -0
  61. sage/interfaces/r.py +2096 -0
  62. sage/interfaces/read_data.py +46 -0
  63. sage/interfaces/scilab.py +576 -0
  64. sage/interfaces/tests.py +81 -0
  65. sage/libs/all.py +11 -0
  66. sage/libs/cremona/__init__.py +0 -0
  67. sage/libs/mwrank/__init__.py +0 -0
  68. sage/logic/all.py +3 -0
  69. sage/logic/booleval.py +160 -0
  70. sage/logic/boolformula.py +1490 -0
  71. sage/logic/logic.py +856 -0
  72. sage/logic/logicparser.py +696 -0
  73. sage/logic/logictable.py +272 -0
  74. sage/logic/propcalc.py +311 -0
  75. sage/misc/all.py +28 -0
  76. sage/misc/lazy_attribute.pyi +11 -0
  77. sage/rings/all.py +48 -0
  78. sage/rings/commutative_algebra.py +38 -0
  79. sage/rings/finite_rings/all.py +21 -0
  80. sage/rings/numbers_abc.py +58 -0
  81. sage/rings/polynomial/all.py +22 -0
  82. sage/rings/polynomial/convolution.py +421 -0
  83. sage/symbolic/all__sagemath_standard_no_symbolics.py +0 -0
@@ -0,0 +1,834 @@
1
+ r"""
2
+ Interface to KASH
3
+
4
+ Sage provides an interface to the KASH computer algebra system,
5
+ which is a *free* (as in beer!) but *closed source* program for
6
+ algebraic number theory that shares much common code with Magma. To
7
+ use KASH, you must first install it. Visit its web page:
8
+ http://page.math.tu-berlin.de/~kant/kash.html
9
+
10
+ .. TODO::
11
+
12
+ Update the following sentence.
13
+
14
+ It is not enough to just have KASH installed on your computer.
15
+
16
+ The KASH interface offers three pieces of functionality:
17
+
18
+
19
+ #. ``kash_console()`` - A function that dumps you into
20
+ an interactive command-line KASH session. Alternatively,
21
+
22
+ type ``!kash`` from the Sage prompt.
23
+
24
+ #. ``kash(expr)`` - Creation of a Sage object that
25
+ wraps a KASH object. This provides a Pythonic interface to KASH.
26
+ For example, if ``f=kash.new(10)``, then
27
+ ``f.Factors()`` returns the prime factorization of
28
+ `10` computed using KASH.
29
+
30
+ #. ``kash.function_name(args ...)`` - Call the
31
+ indicated KASH function with the given arguments are return the
32
+ result as a KASH object.
33
+
34
+ #. ``kash.eval(expr)`` - Evaluation of arbitrary KASH
35
+ expressions, with the result returned as a string.
36
+
37
+
38
+ Issues
39
+ ------
40
+
41
+ For some reason hitting :kbd:`Control` + :kbd:`C` to interrupt a calculation
42
+ does not work correctly. (TODO)
43
+
44
+ Tutorial
45
+ --------
46
+
47
+ The examples in this tutorial require that kash be installed.
48
+
49
+ Basics
50
+ ~~~~~~
51
+
52
+ Basic arithmetic is straightforward. First, we obtain the result as
53
+ a string.
54
+
55
+ ::
56
+
57
+ sage: kash.eval('(9 - 7) * (5 + 6)') # optional -- kash
58
+ '22'
59
+
60
+ Next we obtain the result as a new KASH object.
61
+
62
+ ::
63
+
64
+ sage: a = kash('(9 - 7) * (5 + 6)'); a # optional -- kash
65
+ 22
66
+ sage: a.parent() # optional -- kash
67
+ Kash
68
+
69
+ We can do arithmetic and call functions on KASH objects::
70
+
71
+ sage: a*a # optional -- kash
72
+ 484
73
+ sage: a.Factorial() # optional -- kash
74
+ 1124000727777607680000
75
+
76
+ Integrated Help
77
+ ~~~~~~~~~~~~~~~
78
+
79
+ Use the ``kash.help(name)`` command to get help about a
80
+ given command. This returns a list of help for each of the
81
+ definitions of ``name``. Use ``print
82
+ kash.help(name)`` to nicely print out all signatures.
83
+
84
+ Arithmetic
85
+ ~~~~~~~~~~
86
+
87
+ Using the ``kash.new`` command we create Kash objects
88
+ on which one can do arithmetic.
89
+
90
+ ::
91
+
92
+ sage: # optional - kash
93
+ sage: a = kash(12345)
94
+ sage: b = kash(25)
95
+ sage: a/b
96
+ 2469/5
97
+ sage: a**b
98
+ 1937659030411463935651167391656422626577614411586152317674869233464019922771432158872187137603759765625
99
+
100
+ Variable assignment
101
+ ~~~~~~~~~~~~~~~~~~~
102
+
103
+ Variable assignment using ``kash`` is takes place in
104
+ Sage.
105
+
106
+ ::
107
+
108
+ sage: a = kash('32233') # optional -- kash
109
+ sage: a # optional -- kash
110
+ 32233
111
+
112
+ In particular, ``a`` is not defined as part of the KASH
113
+ session itself.
114
+
115
+ ::
116
+
117
+ sage: kash.eval('a') # optional -- kash
118
+ "Error, the variable 'a' must have a value"
119
+
120
+ Use ``a.name()`` to get the name of the KASH variable::
121
+
122
+ sage: a.name() # somewhat random; optional - kash
123
+ 'sage0'
124
+ sage: kash(a.name()) # optional -- kash
125
+ 32233
126
+
127
+ Integers and Rationals
128
+ ~~~~~~~~~~~~~~~~~~~~~~
129
+
130
+ We illustrate arithmetic with integers and rationals in KASH.
131
+
132
+ ::
133
+
134
+ sage: # optional - kash
135
+ sage: F = kash.Factorization(4352)
136
+ sage: F[1]
137
+ <2, 8>
138
+ sage: F[2]
139
+ <17, 1>
140
+ sage: F
141
+ [ <2, 8>, <17, 1> ], extended by:
142
+ ext1 := 1,
143
+ ext2 := Unassign
144
+
145
+ .. NOTE::
146
+
147
+ For some very large numbers KASH's integer factorization seems much
148
+ faster than PARI's (which is the default in Sage).
149
+
150
+ ::
151
+
152
+ sage: # optional - kash
153
+ sage: kash.GCD(15,25)
154
+ 5
155
+ sage: kash.LCM(15,25)
156
+ 75
157
+ sage: kash.Div(25,15)
158
+ 1
159
+ sage: kash(17) % kash(5)
160
+ 2
161
+ sage: kash.IsPrime(10007)
162
+ TRUE
163
+ sage: kash.IsPrime(2005)
164
+ FALSE
165
+
166
+ sage: kash.NextPrime(10007) # optional -- kash
167
+ 10009
168
+
169
+ Real and Complex Numbers
170
+ ~~~~~~~~~~~~~~~~~~~~~~~~
171
+
172
+ ::
173
+
174
+ sage: # optional - kash
175
+ sage: kash.Precision()
176
+ 30
177
+ sage: kash('R')
178
+ Real field of precision 30
179
+ sage: kash.Precision(40)
180
+ 40
181
+ sage: kash('R')
182
+ Real field of precision 40
183
+ sage: z = kash('1 + 2*I')
184
+ sage: z
185
+ 1.000000000000000000000000000000000000000 + 2.000000000000000000000000000000000000000*I
186
+ sage: z*z
187
+ -3.000000000000000000000000000000000000000 + 4.000000000000000000000000000000000000000*I
188
+
189
+ sage: kash.Cos('1.24') # optional -- kash
190
+ 0.3247962844387762365776934156973803996992
191
+ sage: kash('1.24').Cos() # optional -- kash
192
+ 0.3247962844387762365776934156973803996992
193
+
194
+ sage: kash.Exp('1.24') # optional -- kash
195
+ 3.455613464762675598057615494121998175400
196
+
197
+ sage: kash.Precision(30) # optional -- kash
198
+ 30
199
+ sage: kash.Log('3+4*I') # optional -- kash
200
+ 1.60943791243410037460075933323 + 0.927295218001612232428512462922*I
201
+ sage: kash.Log('I') # optional -- kash
202
+ 1.57079632679489661923132169164*I
203
+
204
+ sage: kash.Sqrt(4) # optional -- kash
205
+ 2.00000000000000000000000000000
206
+ sage: kash.Sqrt(2) # optional -- kash
207
+ 1.41421356237309504880168872421
208
+
209
+ sage: kash.Floor('9/5') # optional -- kash
210
+ 1
211
+ sage: kash.Floor('3/5') # optional -- kash
212
+ 0
213
+
214
+ sage: x_c = kash('3+I') # optional -- kash
215
+ sage: x_c.Argument() # optional -- kash
216
+ 0.321750554396642193401404614359
217
+ sage: x_c.Imaginary() # optional -- kash
218
+ 1.00000000000000000000000000000
219
+
220
+ Lists
221
+ ~~~~~
222
+
223
+ Note that list appends are completely different in KASH than in
224
+ Python. Use underscore after the function name for the mutation
225
+ version.
226
+
227
+ ::
228
+
229
+ sage: # optional - kash
230
+ sage: v = kash([1,2,3]); v
231
+ [ 1, 2, 3 ]
232
+ sage: v[1]
233
+ 1
234
+ sage: v[3]
235
+ 3
236
+ sage: v.Append([5])
237
+ [ 1, 2, 3, 5 ]
238
+ sage: v
239
+ [ 1, 2, 3 ]
240
+ sage: v.Append_([5, 6])
241
+ SUCCESS
242
+ sage: v
243
+ [ 1, 2, 3, 5, 6 ]
244
+ sage: v.Add(5)
245
+ [ 1, 2, 3, 5, 6, 5 ]
246
+ sage: v
247
+ [ 1, 2, 3, 5, 6 ]
248
+ sage: v.Add_(5)
249
+ SUCCESS
250
+ sage: v
251
+ [ 1, 2, 3, 5, 6, 5 ]
252
+
253
+ The ``Apply`` command applies a function to each
254
+ element of a list::
255
+
256
+ sage: # optional - kash
257
+ sage: L = kash([1,2,3,4])
258
+ sage: L.Apply('i -> 3*i')
259
+ [ 3, 6, 9, 12 ]
260
+ sage: L
261
+ [ 1, 2, 3, 4 ]
262
+ sage: L.Apply('IsEven')
263
+ [ FALSE, TRUE, FALSE, TRUE ]
264
+ sage: L
265
+ [ 1, 2, 3, 4 ]
266
+
267
+ Ranges
268
+ ~~~~~~
269
+
270
+ the following are examples of ranges.
271
+
272
+ ::
273
+
274
+ sage: # optional - kash
275
+ sage: L = kash('[1..10]')
276
+ sage: L
277
+ [ 1 .. 10 ]
278
+ sage: L = kash('[2,4..100]')
279
+ sage: L
280
+ [ 2, 4 .. 100 ]
281
+
282
+ Sequences
283
+ ~~~~~~~~~
284
+
285
+ Tuples
286
+ ~~~~~~
287
+
288
+ Polynomials
289
+ ~~~~~~~~~~~
290
+
291
+ ::
292
+
293
+ sage: # optional - kash
294
+ sage: f = kash('X^3 + X + 1')
295
+ sage: f + f
296
+ 2*X^3 + 2*X + 2
297
+ sage: f * f
298
+ X^6 + 2*X^4 + 2*X^3 + X^2 + 2*X + 1
299
+ sage: f.Evaluate(10)
300
+ 1011
301
+ sage: Qx = kash.PolynomialAlgebra('Q')
302
+ sage: Qx.gen(1)**5 + kash('7/3')
303
+ sage1.1^5 + 7/3
304
+
305
+ Number Fields
306
+ ~~~~~~~~~~~~~
307
+
308
+ We create an equation order.
309
+
310
+ ::
311
+
312
+ sage: f = kash('X^5 + 4*X^4 - 56*X^2 -16*X + 192') # optional -- kash
313
+ sage: OK = f.EquationOrder() # optional -- kash
314
+ sage: OK # optional -- kash
315
+ Equation Order with defining polynomial X^5 + 4*X^4 - 56*X^2 - 16*X + 192 over Z
316
+
317
+ ::
318
+
319
+ sage: # optional - kash
320
+ sage: f = kash('X^5 + 4*X^4 - 56*X^2 -16*X + 192')
321
+ sage: O = f.EquationOrder()
322
+ sage: a = O.gen(2)
323
+ sage: a
324
+ [0, 1, 0, 0, 0]
325
+ sage: O.Basis()
326
+ [
327
+ _NG.1,
328
+ _NG.2,
329
+ _NG.3,
330
+ _NG.4,
331
+ _NG.5
332
+ ]
333
+ sage: O.Discriminant()
334
+ 1364202618880
335
+ sage: O.MaximalOrder()
336
+ Maximal Order of sage2
337
+
338
+ sage: O = kash.MaximalOrder('X^3 - 77') # optional -- kash
339
+ sage: I = O.Ideal(5,[2, 1, 0]) # optional -- kash
340
+ sage: I # name sage14 below random; optional -- kash
341
+ Ideal of sage14
342
+ Two element generators:
343
+ [5, 0, 0]
344
+ [2, 1, 0]
345
+
346
+ sage: F = I.Factorisation() # optional -- kash
347
+ sage: F # name sage14 random; optional -- kash
348
+ [
349
+ <Prime Ideal of sage14
350
+ Two element generators:
351
+ [5, 0, 0]
352
+ [2, 1, 0], 1>
353
+ ]
354
+
355
+ Determining whether an ideal is principal.
356
+
357
+ ::
358
+
359
+ sage: I.IsPrincipal() # optional -- kash
360
+ FALSE, extended by:
361
+ ext1 := Unassign
362
+
363
+ Computation of class groups and unit groups::
364
+
365
+ sage: # optional - kash
366
+ sage: f = kash('X^5 + 4*X^4 - 56*X^2 -16*X + 192')
367
+ sage: O = kash.EquationOrder(f)
368
+ sage: OK = O.MaximalOrder()
369
+ sage: OK.ClassGroup()
370
+ Abelian Group isomorphic to Z/6
371
+ Defined on 1 generator
372
+ Relations:
373
+ 6*sage32.1 = 0, extended by:
374
+ ext1 := Mapping from: grp^abl: sage32 to ids/ord^num: _AA
375
+
376
+ ::
377
+
378
+ sage: U = OK.UnitGroup() # optional -- kash
379
+ sage: U # name sage34 below random; optional -- kash
380
+ Abelian Group isomorphic to Z/2 + Z + Z
381
+ Defined on 3 generators
382
+ Relations:
383
+ 2*sage34.1 = 0, extended by:
384
+ ext1 := Mapping from: grp^abl: sage34 to ord^num: sage30
385
+
386
+ sage: kash.Apply('x->%s.ext1(x)'%U.name(), U.Generators().List()) # optional -- kash
387
+ [ [1, -1, 0, 0, 0], [1, 1, 0, 0, 0], [-1, 0, 0, 0, 0] ]
388
+
389
+ Function Fields
390
+ ~~~~~~~~~~~~~~~
391
+
392
+ ::
393
+
394
+ sage: # optional - kash
395
+ sage: k = kash.FiniteField(25)
396
+ sage: kT = k.RationalFunctionField()
397
+ sage: kTy = kT.PolynomialAlgebra()
398
+ sage: T = kT.gen(1)
399
+ sage: y = kTy.gen(1)
400
+ sage: f = y**3 + T**4 + 1
401
+
402
+ Long Input
403
+ ----------
404
+
405
+ The KASH interface reads in even very long input (using files) in a
406
+ robust manner, as long as you are creating a new object.
407
+
408
+ .. NOTE::
409
+
410
+ Using ``kash.eval`` for long input is much less robust, and is not
411
+ recommended.
412
+
413
+ ::
414
+
415
+ sage: a = kash(range(10000)) # optional -- kash
416
+
417
+ Note that KASH seems to not support string or integer literals with
418
+ more than 1024 digits, which is why the above example uses a list
419
+ unlike for the other interfaces.
420
+ """
421
+
422
+
423
+ # ****************************************************************************
424
+ # Copyright (C) 2005 William Stein <wstein@gmail.com>
425
+ #
426
+ # Distributed under the terms of the GNU General Public License (GPL)
427
+ #
428
+ # This code is distributed in the hope that it will be useful,
429
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
430
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
431
+ # General Public License for more details.
432
+ #
433
+ # The full text of the GPL is available at:
434
+ #
435
+ # https://www.gnu.org/licenses/
436
+ # ****************************************************************************
437
+
438
+ from .expect import Expect, ExpectElement
439
+ from sage.misc.instancedoc import instancedoc
440
+ import os
441
+
442
+ from sage.misc.sage_eval import sage_eval
443
+
444
+
445
+ class Kash(Expect):
446
+ r"""
447
+ Interface to the Kash interpreter.
448
+
449
+ AUTHORS:
450
+
451
+ - William Stein and David Joyner
452
+ """
453
+ def __init__(self,
454
+ max_workspace_size=None,
455
+ maxread=None,
456
+ script_subdirectory=None,
457
+ restart_on_ctrlc=True,
458
+ logfile=None,
459
+ server=None,
460
+ server_tmpdir=None):
461
+ """
462
+ INPUT:
463
+
464
+ - ``max_workspace_size`` -- (default: ``None``)
465
+ set maximal workspace memory usage to <mem>
466
+ <mem> stands for byte-wise allocation
467
+ <mem>k stands for kilobyte-wise allocation
468
+ <mem>m stands for megabyte-wise allocation
469
+ """
470
+ cmd = "kash3 -b -c -d "
471
+ if max_workspace_size is not None:
472
+ cmd += " -a %s" % int(max_workspace_size)
473
+ Expect.__init__(self,
474
+ name='kash',
475
+ prompt='kash% ',
476
+ command=cmd,
477
+ server=server,
478
+ server_tmpdir=server_tmpdir,
479
+ script_subdirectory=script_subdirectory,
480
+ restart_on_ctrlc=True,
481
+ verbose_start=False,
482
+ logfile=logfile,
483
+ eval_using_file_cutoff=100,
484
+ init_code=['X:=ZX.1;']
485
+ )
486
+ # The above init_code programs around a bug reported by Jack Schmidt
487
+
488
+ self.__seq = 0
489
+
490
+ def clear(self, var):
491
+ """
492
+ Clear the variable named ``var``.
493
+
494
+ Kash variables have a record structure, so if sage1 is a
495
+ polynomial ring, sage1.1 will be its indeterminate. This
496
+ prevents us from easily reusing variables, since sage1.1
497
+ might still have references even if sage1 does not.
498
+
499
+ For now, we don't implement variable clearing to avoid these
500
+ problems, and instead implement this method with a noop.
501
+ """
502
+ pass
503
+
504
+ def _read_in_file_command(self, filename):
505
+ return 'Read("%s");' % filename
506
+
507
+ def _eval_line_using_file(self, line):
508
+ F = open(self._local_tmpfile(), 'w')
509
+ F.write(line)
510
+ F.close()
511
+ tmp_to_use = self._local_tmpfile()
512
+ if self.is_remote():
513
+ self._send_tmpfile_to_server()
514
+ tmp_to_use = self._remote_tmpfile()
515
+ return self._eval_line(self._read_in_file_command(tmp_to_use),
516
+ allow_use_file=False)
517
+
518
+ # Change the default for KASH, since eval using a file doesn't
519
+ # work except for setting variables.
520
+ def _eval_line(self, line, allow_use_file=False, wait_for_prompt=True, restart_if_needed=False):
521
+ return Expect._eval_line(self, line, allow_use_file=allow_use_file,
522
+ wait_for_prompt=wait_for_prompt)
523
+
524
+ def __reduce__(self):
525
+ return reduce_load_Kash, tuple([])
526
+
527
+ def _quit_string(self):
528
+ return 'quit;'
529
+
530
+ def _start(self):
531
+ Expect._start(self)
532
+ # Turn off the annoying timer.
533
+ self.eval('Time(false);')
534
+
535
+ def _object_class(self):
536
+ return KashElement
537
+
538
+ def eval(self, x, newlines=False, strip=True, **kwds):
539
+ r"""
540
+ Send the code in the string s to the Kash interpreter and return
541
+ the output as a string.
542
+
543
+ INPUT:
544
+
545
+ - ``s`` -- string containing Kash code
546
+
547
+ - ``newlines`` -- boolean (default: ``True``); if ``False``,
548
+ remove all backslash-newlines inserted by the Kash output formatter
549
+
550
+ - ``strip`` -- ignored
551
+ """
552
+ x = str(x)
553
+ x = x.rstrip()
554
+ if len(x) == 0 or x[len(x) - 1] != ';':
555
+ x += ';'
556
+ s = Expect.eval(self, x, **kwds)
557
+ i = s.find('\r\n')
558
+ if i != -1:
559
+ s = s[i + 2:]
560
+ if newlines:
561
+ return s
562
+ else:
563
+ return s.replace("\\\n", "")
564
+
565
+ def help(self, name=None):
566
+ """
567
+ Return help on KASH commands.
568
+
569
+ This returns help on all commands with a given name. If name
570
+ is ``None``, return the location of the installed Kash HTML
571
+ documentation.
572
+
573
+ EXAMPLES::
574
+
575
+ sage: X = kash.help('IntegerRing') # random; optional -- kash
576
+ 1439: IntegerRing() -> <ord^rat>
577
+ 1440: IntegerRing(<elt-ord^rat> m) -> <res^rat>
578
+ 1441: IntegerRing(<seq()> Q) -> <res^rat>
579
+ 1442: IntegerRing(<fld^rat> K) -> <ord^rat>
580
+ 1443: IntegerRing(<fld^fra> K) -> <ord^num>
581
+ 1444: IntegerRing(<rng> K) -> <rng>
582
+ 1445: IntegerRing(<fld^pad> L) -> <ord^pad>
583
+
584
+ There is one entry in X for each item found in the documentation
585
+ for this function: If you type ``print(X[0])`` you will
586
+ get help on about the first one, printed nicely to the screen.
587
+
588
+ AUTHORS:
589
+
590
+ - Sebastion Pauli (2006-02-04): during Sage coding sprint
591
+ """
592
+ if name is None:
593
+ print('\nTo use KASH help enter kash.help(s). ')
594
+ print('The syntax of the string s is given below.\n')
595
+ print(self.eval('?'))
596
+ return
597
+ name = str(name)
598
+ if name[0] == '?':
599
+ print(self.eval(name))
600
+ else:
601
+ print(self.eval('?%s' % name))
602
+
603
+ def _doc(self, V):
604
+ if V.lstrip()[:11] == 'No matches.':
605
+ return KashDocumentation([])
606
+ V = V.split('\n')[1:-1]
607
+ X = []
608
+ for C in V:
609
+ i = C.find('m')
610
+ j = C.find(':')
611
+ try:
612
+ n = int(C[i + 1:j])
613
+ except ValueError:
614
+ full = C
615
+ else:
616
+ full = self.eval('?%s' % n)
617
+ X.append(full)
618
+ return KashDocumentation(X)
619
+
620
+ def help_search(self, name):
621
+ return self._doc(self.eval('?*%s' % name))
622
+
623
+ def set(self, var, value):
624
+ """
625
+ Set the variable var to the given value.
626
+ """
627
+ cmd = '%s:=%s;;' % (var, value)
628
+ out = self._eval_line(cmd, allow_use_file=True)
629
+ if out.lower().find('error') != -1:
630
+ raise TypeError("Error executing code in Kash\nCODE:\n\t%s\nKash ERROR:\n\t%s" % (cmd, out))
631
+
632
+ def get(self, var):
633
+ """
634
+ Get the value of the variable var.
635
+ """
636
+ return self.eval('%s;' % var, newlines=False)
637
+
638
+ # def clear(self, var):
639
+ # """
640
+ # Clear the variable named var.
641
+ # """
642
+ # self.eval('Unbind(%s)'%var)
643
+
644
+ def _contains(self, v1, v2):
645
+ return self.eval('%s in %s' % (v1, v2)) == "TRUE"
646
+
647
+ def _assign_symbol(self):
648
+ return ":="
649
+
650
+ def _equality_symbol(self):
651
+ return "="
652
+
653
+ def _true_symbol(self):
654
+ return "TRUE"
655
+
656
+ def _false_symbol(self):
657
+ return "FALSE"
658
+
659
+ def function_call(self, function, args=None, kwds=None):
660
+ """
661
+ EXAMPLES::
662
+
663
+ sage: kash.function_call('ComplexToPolar', [1+I], {'Results' : 1}) # optional -- kash
664
+ 1.41421356237309504880168872421
665
+ """
666
+ args, kwds = self._convert_args_kwds(args, kwds)
667
+ self._check_valid_function_name(function)
668
+ s = self._function_call_string(function,
669
+ [s.name() for s in args],
670
+ ['%s:=%s' % (key, value.name())
671
+ for key, value in kwds.items()])
672
+ return self.new(s)
673
+
674
+ def _function_call_string(self, function, args, kwds):
675
+ """
676
+ Return the string used to make function calls.
677
+
678
+ EXAMPLES::
679
+
680
+ sage: Kash()._function_call_string('Expand', ['x', 'y'], ['Prec:=10'])
681
+ 'Expand(x,y,rec(Prec:=10))'
682
+ """
683
+ if not kwds:
684
+ return "%s(%s)" % (function, ",".join(args))
685
+ return "%s(%s,rec(%s))" % (function, ",".join(args), ",".join(kwds))
686
+
687
+ def console(self):
688
+ kash_console()
689
+
690
+ def version(self):
691
+ return kash_version()
692
+
693
+
694
+ @instancedoc
695
+ class KashElement(ExpectElement):
696
+ def __mod__(self, other):
697
+ self._check_valid()
698
+ if not isinstance(other, KashElement):
699
+ other = self.parent()(other)
700
+ other._check_valid()
701
+ return self.parent()('%s mod %s' % (self._name, other._name))
702
+
703
+ def __len__(self):
704
+ self._check_valid()
705
+ return int(self.parent().eval('Length(%s)' % self.name()))
706
+
707
+ def __bool__(self):
708
+ """
709
+ Return ``True`` if this Kash element is not 0 or FALSE.
710
+
711
+ EXAMPLES::
712
+
713
+ sage: bool(kash('FALSE')) # optional -- kash
714
+ False
715
+ sage: bool(kash('TRUE')) # optional -- kash
716
+ True
717
+
718
+ sage: bool(kash(0)) # optional -- kash
719
+ False
720
+ sage: bool(kash(1)) # optional -- kash
721
+ True
722
+ """
723
+
724
+ # Kash has separate integer and boolean types, and FALSE does not
725
+ # compare equal to 0 (i.e, FALSE = 0 is FALSE)
726
+
727
+ # Python 3.x uses __bool__ for type conversion to 'bool', so we
728
+ # have to test against FALSE, and sage.structure.element.Element's
729
+ # default implementation of is_zero() is to return 'not self', so
730
+ # our boolean conversion also has to test against 0.
731
+
732
+ P = self.parent()
733
+ return (P.eval('%s = FALSE' % self.name()) == 'FALSE' and
734
+ P.eval('%s = 0' % self.name()) == 'FALSE')
735
+
736
+ def _sage_(self, locals={}, *args):
737
+ """
738
+ Convert this object to Sage.
739
+
740
+ A translation dictionary `locals` can be provided to map Kash
741
+ names and objects to Sage objects.
742
+
743
+ EXAMPLES::
744
+
745
+ sage: kash('1234').sage() # optional -- kash
746
+ 1234
747
+
748
+ sage: kash('X^2+X').sage({'X': x}) # optional -- kash
749
+ x^2 + x
750
+
751
+ sage: kQ = kash.RationalField() # optional -- kash
752
+ sage: kR = kQ.PolynomialAlgebra() # optional -- kash
753
+
754
+ sage: R.<x> = QQ[] # optional -- kash
755
+ sage: ka = (x^2+x).subs({x : kR.1}) # random; optional -- kash
756
+ sage541.1^2 + sage541.1
757
+ sage: ka.sage({kR.1: x}) # optional -- kash
758
+ x^2 + x
759
+
760
+ sage: R.<x,y> = QQ[] # optional -- kash
761
+ sage: ka = (x^2+x).subs({x : kR.1}) # random; optional -- kash
762
+ sage541.1^2 + sage541.1
763
+ sage: ka.sage({kR.1: x}) # optional -- kash
764
+ x^2 + x
765
+ """
766
+
767
+ string = self._sage_repr()
768
+
769
+ i = 1
770
+ parsedict = {}
771
+ for key, val in locals.items():
772
+ name = 'sage' + str(i)
773
+ string = string.replace(str(key), name)
774
+ parsedict[name] = val
775
+ i = i + 1
776
+
777
+ try:
778
+ return sage_eval(string, locals=parsedict)
779
+ except Exception:
780
+ raise NotImplementedError("Unable to parse output: %s" % string)
781
+
782
+
783
+ class KashDocumentation(list):
784
+ def __repr__(self):
785
+ if len(self) == 0:
786
+ return "No matches."
787
+ return '\n'.join(self)
788
+
789
+
790
+ def is_KashElement(x):
791
+ """
792
+ Return ``True`` if ``x`` is of type :class:`KashElement`.
793
+
794
+ EXAMPLES::
795
+
796
+ sage: from sage.interfaces.kash import is_KashElement
797
+ sage: is_KashElement(2)
798
+ doctest:...: DeprecationWarning: the function is_KashElement is deprecated; use isinstance(x, sage.interfaces.abc.KashElement) instead
799
+ See https://github.com/sagemath/sage/issues/34804 for details.
800
+ False
801
+ sage: is_KashElement(kash(2)) # optional - kash
802
+ True
803
+ """
804
+ from sage.misc.superseded import deprecation
805
+ deprecation(34804, "the function is_KashElement is deprecated; use isinstance(x, sage.interfaces.abc.KashElement) instead")
806
+
807
+ return isinstance(x, KashElement)
808
+
809
+ ######
810
+
811
+ ######
812
+
813
+
814
+ kash = Kash()
815
+
816
+
817
+ def reduce_load_Kash():
818
+ return kash
819
+
820
+
821
+ def kash_console():
822
+ from sage.repl.rich_output.display_manager import get_display_manager
823
+ if not get_display_manager().is_in_terminal():
824
+ raise RuntimeError('Can use the console only in the terminal. Try %%kash magics instead.')
825
+ os.system("kash3 ")
826
+
827
+
828
+ def kash_version():
829
+ return kash.eval('VERSION')
830
+
831
+
832
+ def __doctest_cleanup():
833
+ import sage.interfaces.quit
834
+ sage.interfaces.quit.expect_quitall()