Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/interfaces/lie.py
4045 views
1
r"""
2
Interface to LiE
3
4
LiE is a software package under development at CWI since
5
January 1988. Its purpose is to enable mathematicians and
6
physicists to obtain on-line information as well as to
7
interactively perform computations of a Lie group theoretic
8
nature. It focuses on the representation theory of complex
9
semisimple (reductive) Lie groups and algebras, and on the
10
structure of their Weyl groups and root systems.
11
12
Type \code{lie.[tab]} for a list of all the functions available
13
from your LiE install. Type \code{lie.[tab]?} for LiE's
14
help about a given function. Type \code{lie(...)} to create
15
a new LiE object, and \code{lie.eval(...)} to run a string
16
using LiE (and get the result back as a string).
17
18
To access the LiE interpreter directly, run lie_console().
19
20
21
EXAMPLES:
22
sage: a4 = lie('A4') # optional - lie
23
sage: lie.diagram('A4') # optional - lie
24
O---O---O---O
25
1 2 3 4
26
A4
27
28
sage: lie.diagram(a4) # optional - lie
29
O---O---O---O
30
1 2 3 4
31
A4
32
33
sage: a4.diagram() # optional - lie
34
O---O---O---O
35
1 2 3 4
36
A4
37
38
sage: a4.Cartan() # optional - lie
39
[[ 2,-1, 0, 0]
40
,[-1, 2,-1, 0]
41
,[ 0,-1, 2,-1]
42
,[ 0, 0,-1, 2]
43
]
44
sage: lie.LR_tensor([3,1],[2,2]) # optional - lie
45
1X[5,3]
46
47
48
\subsection{Tutorial}
49
50
The following examples are taken from Section 2.1 of the LiE manual.
51
52
You can perform basic arithmetic operations in LiE.
53
54
sage: lie.eval('19+68') # optional - lie
55
'87'
56
sage: a = lie('1111111111*1111111111') # optional - lie
57
sage: a # optional - lie
58
1234567900987654321
59
sage: a/1111111111 # optional - lie
60
1111111111
61
sage: a = lie('345') # optional - lie
62
sage: a^2+3*a-5 # optional - lie
63
120055
64
sage: _ / 7*a # optional - lie
65
5916750
66
67
Vectors in LiE are created using square brackets. Notice that
68
the indexing in LiE is 1-based, unlike Python/Sage which is
69
0-based.
70
71
sage: v = lie('[3,2,6873,-38]') # optional - lie
72
sage: v # optional - lie
73
[3,2,6873,-38]
74
sage: v[3] # optional - lie
75
6873
76
sage: v+v # optional - lie
77
[6,4,13746,-76]
78
sage: v*v # optional - lie
79
47239586
80
sage: v+234786 # optional - lie
81
[3,2,6873,-38,234786]
82
sage: v-3 # optional - lie
83
[3,2,-38]
84
sage: v^v # optional - lie
85
[3,2,6873,-38,3,2,6873,-38]
86
87
You can also work with matrices in LiE.
88
89
sage: m = lie('[[1,0,3,3],[12,4,-4,7],[-1,9,8,0],[3,-5,-2,9]]') # optional - lie
90
sage: m # optional - lie
91
[[ 1, 0, 3,3]
92
,[12, 4,-4,7]
93
,[-1, 9, 8,0]
94
,[ 3,-5,-2,9]
95
]
96
sage: print lie.eval('*'+m._name) # optional - lie
97
[[1,12,-1, 3]
98
,[0, 4, 9,-5]
99
,[3,-4, 8,-2]
100
,[3, 7, 0, 9]
101
]
102
103
sage: m^3 # optional - lie
104
[[ 220, 87, 81, 375]
105
,[-168,-1089, 13,1013]
106
,[1550, 357,-55,1593]
107
,[-854, -652, 98,-170]
108
]
109
sage: v*m # optional - lie
110
[-6960,62055,55061,-319]
111
sage: m*v # optional - lie
112
[20508,-27714,54999,-14089]
113
sage: v*m*v # optional - lie
114
378549605
115
sage: m+v # optional - lie
116
[[ 1, 0, 3, 3]
117
,[12, 4, -4, 7]
118
,[-1, 9, 8, 0]
119
,[ 3,-5, -2, 9]
120
,[ 3, 2,6873,-38]
121
]
122
123
sage: m-2 # optional - lie
124
[[ 1, 0, 3,3]
125
,[-1, 9, 8,0]
126
,[ 3,-5,-2,9]
127
]
128
129
130
LiE handles multivariate (Laurent) polynomials.
131
132
sage: lie('X[1,2]') # optional - lie
133
1X[1,2]
134
sage: -3*_ # optional - lie
135
-3X[1,2]
136
sage: _ + lie('4X[-1,4]') # optional - lie
137
4X[-1,4] - 3X[ 1,2]
138
sage: _^2 # optional - lie
139
16X[-2,8] - 24X[ 0,6] + 9X[ 2,4]
140
sage: lie('(4X[-1,4]-3X[1,2])*(X[2,0]-X[0,-4])') # optional - lie
141
-4X[-1, 0] + 3X[ 1,-2] + 4X[ 1, 4] - 3X[ 3, 2]
142
sage: _ - _ # optional - lie
143
0X[0,0]
144
145
146
You can call LiE's built-in functions using lie.functionname .
147
148
sage: lie.partitions(6) # optional - lie
149
[[6,0,0,0,0,0]
150
,[5,1,0,0,0,0]
151
,[4,2,0,0,0,0]
152
,[4,1,1,0,0,0]
153
,[3,3,0,0,0,0]
154
,[3,2,1,0,0,0]
155
,[3,1,1,1,0,0]
156
,[2,2,2,0,0,0]
157
,[2,2,1,1,0,0]
158
,[2,1,1,1,1,0]
159
,[1,1,1,1,1,1]
160
]
161
sage: lie.diagram('E8') # optional - lie
162
O 2
163
|
164
|
165
O---O---O---O---O---O---O
166
1 3 4 5 6 7 8
167
E8
168
169
170
You can define your own functions in LiE using lie.eval . Once you've defined
171
a function (say f), you can call it using lie.f ; however, user-defined functions
172
do not show up when using tab-completion.
173
174
sage: lie.eval('f(int x) = 2*x') # optional - lie
175
''
176
sage: lie.f(984) # optional - lie
177
1968
178
sage: lie.eval('f(int n) = a=3*n-7; if a < 0 then a = -a fi; 7^a+a^3-4*a-57') # optional - lie
179
''
180
sage: lie.f(2) # optional - lie
181
-53
182
sage: lie.f(5) # optional - lie
183
5765224
184
185
186
187
LiE's help can be accessed through lie.help('functionname') where
188
functionname is the function you want to receive help for.
189
190
sage: print lie.help('diagram') # optional - lie
191
diagram(g). Prints the Dynkin diagram of g, also indicating
192
the type of each simple component printed, and labeling the nodes as
193
done by Bourbaki (for the second and further simple components the
194
labels are given an offset so as to make them disjoint from earlier
195
labels). The labeling of the vertices of the Dynkin diagram prescribes
196
the order of the coordinates of root- and weight vectors used in LiE.
197
198
This can also be accessed with lie.functionname? .
199
200
201
202
With the exception of groups, all LiE data types can be converted into
203
native Sage data types by calling the .sage() method.
204
205
Integers:
206
207
sage: a = lie('1234') # optional - lie
208
sage: b = a.sage(); b # optional - lie
209
1234
210
sage: type(b) # optional - lie
211
<type 'sage.rings.integer.Integer'>
212
213
Vectors:
214
215
sage: a = lie('[1,2,3]') # optional - lie
216
sage: b = a.sage(); b # optional - lie
217
[1, 2, 3]
218
sage: type(b) # optional - lie
219
<type 'list'>
220
221
Matrices:
222
223
sage: a = lie('[[1,2],[3,4]]') # optional - lie
224
sage: b = a.sage(); b # optional - lie
225
[1 2]
226
[3 4]
227
sage: type(b) # optional - lie
228
<type 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'>
229
230
231
Polynomials:
232
233
sage: a = lie('X[1,2] - 2*X[2,1]') # optional - lie
234
sage: b = a.sage(); b # optional - lie
235
-2*x0^2*x1 + x0*x1^2
236
sage: type(b) # optional - lie
237
<type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular'>
238
239
Text:
240
241
sage: a = lie('"text"') # optional - lie
242
sage: b = a.sage(); b # optional - lie
243
'text'
244
sage: type(b) # optional - lie
245
<type 'str'>
246
247
248
LiE can be programmed using the Sage interface as well. Section 5.1.5
249
of the manual gives an example of a function written in LiE's language
250
which evaluates a polynomial at a point. Below is a (roughly) direct
251
translation of that program into Python / Sage.
252
253
sage: def eval_pol(p, pt): # optional - lie
254
... s = 0
255
... for i in range(1,p.length().sage()+1):
256
... m = 1
257
... for j in range(1,pt.size().sage()+1):
258
... m *= pt[j]^p.expon(i)[j]
259
... s += p.coef(i)*m
260
... return s
261
sage: a = lie('X[1,2]') # optional - lie
262
sage: b1 = lie('[1,2]') # optional - lie
263
sage: b2 = lie('[2,3]') # optional - lie
264
sage: eval_pol(a, b1) # optional - lie
265
4
266
sage: eval_pol(a, b2) # optional - lie
267
18
268
269
270
271
AUTHORS:
272
-- Mike Hansen 2007-08-27
273
-- William Stein (template)
274
"""
275
276
##########################################################################
277
#
278
# Copyright (C) 2007 Mike Hansen <[email protected]>
279
# Copyright (C) 2006 William Stein <[email protected]>
280
#
281
# Distributed under the terms of the GNU General Public License (GPL)
282
#
283
# http://www.gnu.org/licenses/
284
#
285
##########################################################################
286
287
from expect import Expect, ExpectElement, ExpectFunction, FunctionElement, AsciiArtString
288
from sage.misc.misc import verbose, DOT_SAGE, SAGE_LOCAL
289
290
291
COMMANDS_CACHE = '%s/lie_commandlist_cache.sobj'%DOT_SAGE
292
HELP_CACHE = '%s/lie_helpdict_cache.sobj'%DOT_SAGE
293
294
class LiE(Expect):
295
r"""
296
Interface to the LiE interpreter.
297
298
Type \code{lie.[tab]} for a list of all the functions available
299
from your LiE install. Type \code{lie.[tab]?} for LiE's
300
help about a given function. Type \code{lie(...)} to create
301
a new LiE object, and \code{lie.eval(...)} to run a string
302
using LiE (and get the result back as a string).
303
304
"""
305
def __init__(self,
306
maxread=100000, script_subdirectory=None,
307
logfile=None,
308
server=None):
309
"""
310
EXAMPLES:
311
sage: lie == loads(dumps(lie))
312
True
313
"""
314
Expect.__init__(self,
315
316
# The capitalized version of this is used for printing.
317
name = 'LiE',
318
319
# This is regexp of the input prompt. If you can change
320
# it to be very obfuscated that would be better. Even
321
# better is to use sequence numbers.
322
prompt = '> ',
323
324
# This is the command that starts up your program
325
command = "bash "+ SAGE_LOCAL + "/bin/lie",
326
327
maxread = maxread,
328
server=server,
329
script_subdirectory = script_subdirectory,
330
331
# If this is true, then whenever the user presses Control-C to
332
# interrupt a calculation, the whole interface is restarted.
333
restart_on_ctrlc = False,
334
335
# If true, print out a message when starting
336
# up the command when you first send a command
337
# to this interface.
338
verbose_start = False,
339
340
logfile=logfile,
341
342
# If an input is longer than this number of characters, then
343
# try to switch to outputting to a file.
344
eval_using_file_cutoff=1024)
345
346
self._seq = 0
347
348
self._trait_names_dict = None
349
self._trait_names_list = None
350
self._help_dict = None
351
352
def _read_info_files(self, use_disk_cache=True):
353
"""
354
EXAMPLES:
355
sage: from sage.interfaces.lie import LiE
356
sage: lie = LiE()
357
sage: lie._trait_names_list is None
358
True
359
sage: lie._read_info_files(use_disk_cache=False) #optional - lie
360
sage: lie._trait_names_list # optional - lie
361
['history',
362
'version',
363
...
364
'sort']
365
"""
366
import sage.misc.persist
367
if use_disk_cache:
368
try:
369
trait_dict = sage.misc.persist.load(COMMANDS_CACHE)
370
help_dict = sage.misc.persist.load(HELP_CACHE)
371
v = []
372
for key in trait_dict:
373
v += trait_dict[key]
374
self._trait_names_list = v
375
self._trait_names_dict = trait_dict
376
self._help_dict = help_dict
377
return
378
except IOError:
379
pass
380
381
382
#Go through INFO.3 and get the necessary information
383
filenames = ['INFO.3', 'INFO.0']
384
commands = {}
385
commands['vid'] = []
386
help = {}
387
388
389
for f in filenames:
390
filename = SAGE_LOCAL + "/lib/lie/" + f
391
info = open(filename)
392
prev_command = ""
393
help_text = ""
394
for line in info:
395
#If the line doesn't start with an "@", then
396
#it is part of the help text for the previous
397
#command
398
if len(line) == 0 or line[0] != "@":
399
if prev_command != "":
400
help_text += line
401
continue
402
403
404
#Do not add not completions that do not start with an
405
#alphabetical character or that contain 'silence'
406
if len(line) > 1 and (not line[1].isalpha() or line.find('silence') != -1):
407
help[prev_command] = help.get(prev_command, "") + help_text
408
help_text = ""
409
prev_command = ""
410
continue
411
412
413
#At this point we should be at the start of a new
414
#command definition
415
416
417
#Get the type of the first argument of the command
418
i = line.find('(')
419
if line[i+1] == ")":
420
t = 'vid'
421
else:
422
t = line[i+1:i+4]
423
424
#Save the help text for the command
425
help[prev_command] = help.get(prev_command, "") + help_text
426
help_text = ""
427
prev_command = line[1:i]
428
429
#Add the commad
430
if t in commands:
431
commands[t].append(line[1:i])
432
else:
433
commands[t] = [ line[1:i] ]
434
435
#Take care of the last help text which doesn't get processed
436
#since there's no following @ symbol
437
help[prev_command] = help.get(prev_command, "") + help_text
438
439
info.close()
440
441
442
#Build the list of all possible command completions
443
l = []
444
for key in commands:
445
l += commands[key]
446
447
#Save the data
448
self._trait_names_dict = commands
449
self._trait_names_list = l
450
self._help_dict = help
451
452
#Write them to file
453
if use_disk_cache:
454
sage.misc.persist.save(commands, COMMANDS_CACHE)
455
sage.misc.persist.save(help, HELP_CACHE)
456
457
def _repr_(self):
458
"""
459
EXAMPLES:
460
sage: lie
461
LiE Interpreter
462
"""
463
return 'LiE Interpreter'
464
465
def __reduce__(self):
466
"""
467
EXAMPLES:
468
sage: lie.__reduce__()
469
(<function reduce_load_lie at 0x...>, ())
470
471
"""
472
return reduce_load_lie, tuple([])
473
474
def _function_class(self):
475
"""
476
EXAMPLES:
477
sage: lie._function_class()
478
<class 'sage.interfaces.lie.LiEFunction'>
479
"""
480
return LiEFunction
481
482
def _quit_string(self):
483
"""
484
EXAMPLES:
485
sage: lie._quit_string()
486
'quit'
487
"""
488
return 'quit'
489
490
def _read_in_file_command(self, filename):
491
"""
492
EXAMPLES:
493
sage: lie._read_in_file_command('testfile')
494
Traceback (most recent call last):
495
...
496
NotImplementedError
497
"""
498
raise NotImplementedError
499
500
501
def trait_names(self, type=None, verbose=False, use_disk_cache=True):
502
"""
503
EXAMPLES:
504
sage: lie.trait_names() # optional - lie
505
['Cartan_type',
506
'cent_roots',
507
...
508
'n_comp']
509
510
"""
511
if self._trait_names_dict is None:
512
self._read_info_files()
513
if type:
514
return self._trait_names_dict[type]
515
else:
516
return self._trait_names_list
517
518
def _an_element_impl(self):
519
"""
520
EXAMPLES:
521
sage: lie._an_element_impl() # optional - lie
522
0
523
"""
524
return self(0)
525
526
def read(self, filename):
527
"""
528
EXAMPLES:
529
sage: filename = tmp_filename()
530
sage: f = open(filename, 'w')
531
sage: f.write('x = 2\n')
532
sage: f.close()
533
sage: lie.read(filename) # optional - lie
534
sage: lie.get('x') # optional - lie
535
'2'
536
sage: import os
537
sage: os.unlink(filename)
538
"""
539
self.eval('read %s'%filename)
540
541
def console(self):
542
"""
543
Spawn a new LiE command-line session.
544
545
EXAMPLES:
546
sage: lie.console() # not tested
547
LiE version 2.2.2 created on Sep 26 2007 at 18:13:19
548
Authors: Arjeh M. Cohen, Marc van Leeuwen, Bert Lisser.
549
Free source code distribution
550
...
551
552
"""
553
lie_console()
554
555
def version(self):
556
"""
557
EXAMPLES:
558
sage: lie.version() # optional - lie
559
'2.1'
560
"""
561
return lie_version()
562
563
def _object_class(self):
564
"""
565
EXAMPLES:
566
sage: lie._object_class()
567
<class 'sage.interfaces.lie.LiEElement'>
568
569
"""
570
return LiEElement
571
572
def _true_symbol(self):
573
"""
574
EXAMPLES:
575
sage: lie._true_symbol()
576
'1'
577
"""
578
return '1'
579
580
def _false_symbol(self):
581
"""
582
EXAMPLES:
583
sage: lie._false_symbol()
584
'0'
585
"""
586
return '0'
587
588
def _equality_symbol(self):
589
"""
590
EXAMPLES:
591
sage: lie._equality_symbol()
592
'=='
593
"""
594
return '=='
595
596
def help(self, command):
597
"""
598
Returns a string of the LiE help for command.
599
600
EXAMPLES:
601
sage: lie.help('diagram') # optional - lie
602
'diagram(g)...'
603
"""
604
# return help on a given command.
605
if self._help_dict is None:
606
self._read_info_files()
607
try:
608
return self._help_dict[command]
609
except KeyError:
610
return "Could not find help for " + command
611
612
def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if_needed=False):
613
"""
614
EXAMPLES:
615
sage: lie._eval_line('2+2') # optional - lie
616
' 4'
617
sage: lie._eval_line('diagram(2)') # optional - lie
618
Traceback (most recent call last):
619
...
620
RuntimeError: An error occurred running a LiE command:
621
Argument types do not match in call. Types are: diagram(bin).
622
Valid argument types are for instance: diagram(grp).
623
624
"""
625
out = Expect._eval_line(self, line, allow_use_file=allow_use_file, wait_for_prompt=wait_for_prompt)
626
#Check to see if an error has occurred
627
err = max( out.find("\n(in"), out.find('not defined'), out.find('Argument types') )
628
if err != -1:
629
raise RuntimeError, "An error occurred running a LiE command:\n%s"%(out.replace('\r\n','\n'))
630
return out
631
632
633
def eval(self, code, strip=True, **kwds):
634
"""
635
EXAMPLES:
636
sage: lie.eval('2+2') # optional - lie
637
'4'
638
"""
639
s = Expect.eval(self,code, strip=True, **kwds)
640
#return s.strip()
641
if len(s) > 0 and s.find("\n") != -1:
642
return s
643
else:
644
return s.strip()
645
646
def set(self, var, value):
647
"""
648
Set the variable var to the given value.
649
650
EXAMPLES:
651
sage: lie.set('x', '2') # optional - lie
652
sage: lie.get('x') # optional - lie
653
'2'
654
"""
655
cmd = '%s=%s'%(var,value)
656
out = self.eval(cmd)
657
i = min( out.find('not defined'), out.find('\(in'), out.find('Argument types') )
658
if i != -1:
659
raise RuntimeError, out
660
661
def get(self, var):
662
"""
663
Get the value of the variable var.
664
665
EXAMPLES:
666
sage: lie.set('x', '2') # optional - lie
667
sage: lie.get('x') # optional - lie
668
'2'
669
670
"""
671
s = self.eval('%s'%var)
672
return s
673
674
def get_using_file(self, var):
675
"""
676
EXAMPLES:
677
sage: lie.get_using_file('x')
678
Traceback (most recent call last):
679
...
680
NotImplementedError
681
"""
682
raise NotImplementedError
683
684
def function_call(self, function, args=None, kwds=None):
685
"""
686
EXAMPLES:
687
sage: lie.function_call("diagram", args=['A4']) # optional - lie
688
O---O---O---O
689
1 2 3 4
690
A4
691
"""
692
#If function just prints something on the screen rather than
693
#returning an object, then we return an AsciiArtString rather
694
#than a LiEElement
695
if function in ['diagram', 'setdefault', 'print_tab', 'type', 'factor', 'void', 'gcol']:
696
args, kwds = self._convert_args_kwds(args, kwds)
697
cmd = "%s(%s)"%(function, ",".join([s.name() for s in args]))
698
return AsciiArtString(self.eval(cmd))
699
700
return Expect.function_call(self, function, args, kwds)
701
702
def _function_element_class(self):
703
"""
704
EXAMPLES:
705
sage: lie._function_element_class()
706
<class 'sage.interfaces.lie.LiEFunctionElement'>
707
"""
708
return LiEFunctionElement
709
710
class LiEElement(ExpectElement):
711
def trait_names(self):
712
"""
713
Returns the possible tab completions for self.
714
715
EXAMPLES:
716
sage: a4 = lie('A4') # optional - lie
717
sage: a4.trait_names() # optional - lie
718
['center',
719
'diagram',
720
...
721
'n_comp']
722
723
"""
724
return self.parent().trait_names(type=self.type())
725
726
def type(self):
727
"""
728
EXAMPLES:
729
sage: m = lie('[[1,0,3,3],[12,4,-4,7],[-1,9,8,0],[3,-5,-2,9]]') # optional - lie
730
sage: m.type() # optional - lie
731
'mat'
732
"""
733
t = self.parent().eval('type(%s)'%self._name)
734
i = t.find(':')
735
return t[i+1:].strip()
736
737
def _matrix_(self, R=None):
738
"""
739
EXAMPLES:
740
sage: m = lie('[[1,0,3,3],[12,4,-4,7],[-1,9,8,0],[3,-5,-2,9]]') # optional - lie
741
sage: matrix(m) # optional - lie
742
[ 1 0 3 3]
743
[12 4 -4 7]
744
[-1 9 8 0]
745
[ 3 -5 -2 9]
746
sage: matrix(RDF, m) # optional - lie
747
[ 1.0 0.0 3.0 3.0]
748
[12.0 4.0 -4.0 7.0]
749
[-1.0 9.0 8.0 0.0]
750
[ 3.0 -5.0 -2.0 9.0]
751
"""
752
P = self._check_valid()
753
if self.type() == 'mat':
754
m = self.sage()
755
if R is not None:
756
m = m.change_ring(R)
757
return m
758
else:
759
raise ValueError, "not a matrix"
760
761
762
def _sage_(self):
763
"""
764
EXAMPLES:
765
sage: m = lie('[[1,0,3,3],[12,4,-4,7],[-1,9,8,0],[3,-5,-2,9]]') # optional - lie
766
sage: m.sage() # optional - lie
767
[ 1 0 3 3]
768
[12 4 -4 7]
769
[-1 9 8 0]
770
[ 3 -5 -2 9]
771
772
"""
773
t = self.type()
774
if t == 'grp':
775
raise ValueError, "cannot convert Lie groups to native Sage objects"
776
elif t == 'mat':
777
import sage.matrix.constructor
778
return sage.matrix.constructor.matrix( eval( str(self).replace('\n','').strip()) )
779
elif t == 'pol':
780
import sage.misc.misc
781
from sage.rings.all import PolynomialRing, QQ
782
783
#Figure out the number of variables
784
s = str(self)
785
open_bracket = s.find('[')
786
close_bracket = s.find(']')
787
nvars = len(s[open_bracket:close_bracket].split(','))
788
789
#create the polynomial ring
790
R = PolynomialRing(QQ, nvars, 'x')
791
x = R.gens()
792
pol = R(0)
793
794
#Split up the polynomials into terms
795
terms = []
796
for termgrp in s.split(' - '):
797
#The first entry in termgrp has
798
#a negative coefficient
799
termgrp = "-"+termgrp.strip()
800
terms += termgrp.split('+')
801
#Make sure we don't accidentally add a negative
802
#sign to the first monomial
803
if s[0] != "-":
804
terms[0] = terms[0][1:]
805
806
#go through all the terms in s
807
for term in terms:
808
xpos = term.find('X')
809
coef = eval(term[:xpos].strip())
810
exps = eval(term[xpos+1:].strip())
811
monomial = sage.misc.misc.prod(map(lambda i: x[i]**exps[i] , range(nvars)))
812
pol += coef * monomial
813
814
return pol
815
elif t == 'tex':
816
return repr(self)
817
elif t == 'vid':
818
return None
819
else:
820
return ExpectElement._sage_(self)
821
822
823
class LiEFunctionElement(FunctionElement):
824
def _sage_doc_(self):
825
"""
826
EXAMPLES:
827
sage: a4 = lie('A4') # optional - lie
828
sage: a4.diagram._sage_doc_() # optional - lie
829
'diagram(g)...'
830
"""
831
M = self._obj.parent()
832
return M.help(self._name)
833
834
835
class LiEFunction(ExpectFunction):
836
def _sage_doc_(self):
837
"""
838
Returns the help for self.
839
840
EXAMPLES:
841
sage: lie.diagram._sage_doc_() # optional - lie
842
'diagram(g)...'
843
"""
844
M = self._parent
845
return M.help(self._name)
846
847
848
849
def is_LiEElement(x):
850
"""
851
EXAMPLES:
852
sage: from sage.interfaces.lie import is_LiEElement
853
sage: l = lie(2) # optional - lie
854
sage: is_LiEElement(l) # optional - lie
855
True
856
sage: is_LiEElement(2)
857
False
858
"""
859
return isinstance(x, LiEElement)
860
861
# An instance
862
lie = LiE()
863
864
def reduce_load_lie():
865
"""
866
EXAMPLES:
867
sage: from sage.interfaces.lie import reduce_load_lie
868
sage: reduce_load_lie()
869
LiE Interpreter
870
"""
871
return lie
872
873
import os
874
def lie_console():
875
"""
876
Spawn a new LiE command-line session.
877
878
EXAMPLES:
879
sage: from sage.interfaces.lie import lie_console
880
sage: lie_console() # not tested
881
LiE version 2.2.2 created on Sep 26 2007 at 18:13:19
882
Authors: Arjeh M. Cohen, Marc van Leeuwen, Bert Lisser.
883
Free source code distribution
884
...
885
886
"""
887
os.system('bash `which lie`')
888
889
890
def lie_version():
891
"""
892
EXAMPLES:
893
sage: from sage.interfaces.lie import lie_version
894
sage: lie_version() # optional - lie
895
'2.1'
896
"""
897
f = open(SAGE_LOCAL + 'lib/lie/INFO.0')
898
lines = f.readlines()
899
f.close()
900
i = lines.index('@version()\n')
901
return lines[i+1].split()[1]
902
903
904