Ticket #5111: trac_5111.patch
File trac_5111.patch, 54.8 KB (added by , 13 years ago) |
---|
-
sage/interfaces/all.py
# HG changeset patch # User Mike Hansen <mhansen@gmail.com> # Date 1235065126 28800 # Node ID f3c6593ad0c6ac3514cec6337df689b6046a6786 # Parent e787cad2d557063eadfd31c0063ee578bbf238db Fixed #5111 and #4036 diff -r e787cad2d557 -r f3c6593ad0c6 sage/interfaces/all.py
a b 2 2 3 3 from frobby import frobby 4 4 from axiom import Axiom, axiom, axiom_console 5 from fricas import FriCAS, fricas, fricas_console 5 6 6 7 from expect import is_ExpectElement 7 8 from gap import gap, gap_reset_workspace, gap_console, gap_version, is_GapElement, Gap -
sage/interfaces/axiom.py
diff -r e787cad2d557 -r f3c6593ad0c6 sage/interfaces/axiom.py
a b 17 17 implementations of special functions, including elliptic functions 18 18 and generalized hypergeometric functions. Moreover, Axiom has 19 19 implementations of many functions relating to the invariant theory 20 of the symmetric group `S_n `.For many links to Axiom20 of the symmetric group `S_n.` For many links to Axiom 21 21 documentation see http://wiki.axiom-developer.org. 22 22 23 23 AUTHORS: … … 49 49 50 50 :: 51 51 52 sage: axiom('3 * 5') # optional52 sage: axiom('3 * 5') #optional - axiom 53 53 15 54 sage: a = axiom(3) * axiom(5); a # optional54 sage: a = axiom(3) * axiom(5); a #optional - axiom 55 55 15 56 56 57 57 The type of a is AxiomElement, i.e., an element of the axiom … … 59 59 60 60 :: 61 61 62 sage: type(a) # optional62 sage: type(a) #optional - axiom 63 63 <class 'sage.interfaces.axiom.AxiomElement'> 64 sage: parent(a) # optional64 sage: parent(a) #optional - axiom 65 65 Axiom 66 66 67 67 The underlying Axiom type of a is also available, via the type 68 68 method:: 69 69 70 sage: a.type() # optional70 sage: a.type() #optional - axiom 71 71 PositiveInteger 72 72 73 73 We factor `x^5 - y^5` in Axiom in several different ways. … … 75 75 76 76 :: 77 77 78 sage: F = axiom.factor('x^5 - y^5'); F # optional78 sage: F = axiom.factor('x^5 - y^5'); F #optional - axiom 79 79 4 3 2 2 3 4 80 80 - (y - x)(y + x y + x y + x y + x ) 81 sage: type(F) # optional81 sage: type(F) #optional - axiom 82 82 <class 'sage.interfaces.axiom.AxiomElement'> 83 sage: F.type() # optional83 sage: F.type() #optional - axiom 84 84 Factored Polynomial Integer 85 85 86 86 Note that Axiom objects are normally displayed using "ASCII art". 87 87 88 88 :: 89 89 90 sage: a = axiom(2/3); a # optional90 sage: a = axiom(2/3); a #optional - axiom 91 91 2 92 92 - 93 93 3 94 sage: a = axiom('x^2 + 3/7'); a # optional94 sage: a = axiom('x^2 + 3/7'); a #optional - axiom 95 95 2 3 96 96 x + - 97 97 7 … … 103 103 104 104 :: 105 105 106 sage: print axiom.eval('factor(x^5 - y^5)') # optional106 sage: print axiom.eval('factor(x^5 - y^5)') #optional - axiom 107 107 4 3 2 2 3 4 108 108 - (y - x)(y + x y + x y + x y + x ) 109 110 109 Type: Factored Polynomial Integer 111 110 112 111 We can create the polynomial `f` as a Axiom polynomial, … … 116 115 117 116 :: 118 117 119 sage: f = axiom('x^5 - y^5') # optional120 sage: f^2 # optional118 sage: f = axiom('x^5 - y^5') #optional - axiom 119 sage: f^2 #optional - axiom 121 120 10 5 5 10 122 121 y - 2x y + x 123 sage: f.factor() # optional122 sage: f.factor() #optional - axiom 124 123 4 3 2 2 3 4 125 124 - (y - x)(y + x y + x y + x y + x ) 126 125 … … 137 136 138 137 :: 139 138 140 sage: axiom('1/100 + 1/101') # optional139 sage: axiom('1/100 + 1/101') #optional - axiom 141 140 201 142 141 ----- 143 142 10100 144 sage: a = axiom('(1 + sqrt(2))^5'); a # optional143 sage: a = axiom('(1 + sqrt(2))^5'); a #optional - axiom 145 144 +-+ 146 145 29\|2 + 41 147 146 … … 150 149 151 150 :: 152 151 153 sage: a = axiom(x+2); a #optional 152 sage: a = axiom(x+2); a #optional - axiom 154 153 x + 2 155 sage: a.subst(x=3) #optional 154 sage: a.subst(x=3) #optional - axiom 156 155 5 157 156 158 157 We verify that Axiom floating point numbers can be converted to … … 160 159 161 160 :: 162 161 163 sage: float(axiom(2)) #optional 162 sage: float(axiom(2)) #optional - axiom 164 163 2.0 165 164 """ 166 165 … … 178 177 import os, re 179 178 180 179 from expect import Expect, ExpectElement, FunctionElement, ExpectFunction 180 from sage.misc.misc import verbose, DOT_SAGE, SAGE_ROOT 181 181 from pexpect import EOF 182 183 from sage.misc.misc import verbose, DOT_SAGE, SAGE_ROOT184 185 182 from sage.misc.multireplace import multiple_replace 186 183 187 cnt = 0188 seq = 0189 190 COMMANDS_CACHE = '%s/axiom_commandlist_cache.sobj'%DOT_SAGE191 192 184 # The Axiom commands ")what thing det" ")show Matrix" and ")display 193 185 # op det" commands, gives a list of all identifiers that begin in 194 186 # a certain way. This could maybe be useful somehow... (?) Also 195 187 # axiom has a lot a lot of ways for getting documentation from the 196 188 # system -- this could also be useful. 197 189 198 class Axiom(Expect):190 class PanAxiom(Expect): 199 191 """ 200 Interface to theAxiom interpreter.192 Interface to a PanAxiom interpreter. 201 193 """ 202 def __init__(self, script_subdirectory=None, logfile=None, server=None, server_tmpdir=None): 194 def __init__(self, name='axiom', command='axiom -nox -noclef', 195 script_subdirectory=None, logfile=None, 196 server=None, server_tmpdir=None): 203 197 """ 204 198 Create an instance of the Axiom interpreter. 205 199 … … 210 204 """ 211 205 eval_using_file_cutoff = 200 212 206 self.__eval_using_file_cutoff = eval_using_file_cutoff 207 self._COMMANDS_CACHE = '%s/%s_commandlist_cache.sobj'%(DOT_SAGE, name) 213 208 Expect.__init__(self, 214 name = 'axiom',209 name = name, 215 210 prompt = '\([0-9]+\) -> ', 216 command = "axiom -nox -noclef",211 command = command, 217 212 maxread = 10, 218 213 script_subdirectory = script_subdirectory, 219 214 server=server, … … 223 218 #init_code = [')lisp (si::readline-off)'], 224 219 logfile = logfile, 225 220 eval_using_file_cutoff=eval_using_file_cutoff) 226 227 def _function_class(self): 228 """ 229 Return the AxiomExpectFunction class. 230 231 EXAMPLES:: 232 233 sage: axiom._function_class() 234 <class 'sage.interfaces.axiom.AxiomExpectFunction'> 235 sage: type(axiom.gcd) 236 <class 'sage.interfaces.axiom.AxiomExpectFunction'> 237 """ 238 return AxiomExpectFunction 239 240 def _object_class(self): 241 """ 242 EXAMPLES:: 243 244 sage: axiom._object_class() 245 <class 'sage.interfaces.axiom.AxiomElement'> 246 sage: type(axiom(2)) #optional -- requires Axiom 247 <class 'sage.interfaces.axiom.AxiomElement'> 248 """ 249 return AxiomElement 250 251 def _function_element_class(self): 252 """ 253 Returns the Axiom function element class. 254 255 EXAMPLES:: 256 257 sage: axiom._function_element_class() 258 <class 'sage.interfaces.axiom.AxiomFunctionElement'> 259 sage: type(axiom(2).gcd) #optional -- requires Axiom 260 <class 'sage.interfaces.axiom.AxiomFunctionElement'> 261 """ 262 return AxiomFunctionElement 221 self._prompt_wait = self._prompt 263 222 264 223 def _start(self): 265 224 """ … … 270 229 sage: a = Axiom() 271 230 sage: a.is_running() 272 231 False 273 sage: a._start() #optional - - requiresaxiom274 sage: a.is_running() #optional 232 sage: a._start() #optional - axiom 233 sage: a.is_running() #optional - axiom 275 234 True 276 sage: a.quit() #optional 235 sage: a.quit() #optional - axiom 277 236 """ 278 237 Expect._start(self) 279 238 out = self._eval_line(')set functions compile on', reformat=False) … … 309 268 # The space before the \n is also important. 310 269 return ')read %s \n'%filename 311 270 312 def __reduce__(self):313 """314 EXAMPLES::315 316 sage: axiom.__reduce__()317 (<function reduce_load_Axiom at 0x...>, ())318 sage: f, args = _319 sage: f(*args)320 Axiom321 """322 return reduce_load_Axiom, tuple([])323 271 324 272 def _quit_string(self): 325 273 """ … … 329 277 330 278 sage: axiom._quit_string() 331 279 ')lisp (quit)' 332 333 ::334 335 280 sage: a = Axiom() 336 281 sage: a.is_running() 337 282 False 338 sage: a._start() #optional - - requiresaxiom339 sage: a.is_running() #optional 283 sage: a._start() #optional - axiom 284 sage: a.is_running() #optional - axiom 340 285 True 341 sage: a.quit() #optional 342 sage: a.is_running() #optional 286 sage: a.quit() #optional - axiom 287 sage: a.is_running() #optional - axiom 343 288 False 344 289 """ 345 290 return ')lisp (quit)' 346 291 292 def _commands(self): 293 """ 294 Returns a list of commands available. This is done by parsing the 295 result of the first section of the output of ')what things'. 296 297 EXAMPLES:: 298 299 sage: cmds = axiom._commands() #optional - axiom 300 sage: len(cmds) > 100 #optional - axiom 301 True 302 sage: '<' in cmds #optional - axiom 303 True 304 sage: 'factor' in cmds #optional - axiom 305 True 306 """ 307 s = self.eval(")what things") 308 start = '\r\n\r\n#' 309 i = s.find(start) 310 end = "To get more information about" 311 j = s.find(end) 312 s = s[i+len(start):j].split() 313 return s 314 315 316 def trait_names(self, verbose=True, use_disk_cache=True): 317 """ 318 Returns a list of all the commands defined in Axiom and optionally 319 (per default) store them to disk. 320 321 EXAMPLES:: 322 323 sage: c = axiom.trait_names(use_disk_cache=False, verbose=False) #optional - axiom 324 sage: len(c) > 100 #optional - axiom 325 True 326 sage: 'factor' in c #optional - axiom 327 True 328 sage: '**' in c #optional - axiom 329 False 330 sage: 'upperCase?' in c #optional - axiom 331 False 332 sage: 'upperCase_q' in c #optional - axiom 333 True 334 sage: 'upperCase_e' in c #optional - axiom 335 True 336 """ 337 try: 338 return self.__trait_names 339 except AttributeError: 340 import sage.misc.persist 341 if use_disk_cache: 342 try: 343 self.__trait_names = sage.misc.persist.load(self._COMMANDS_CACHE) 344 return self.__trait_names 345 except IOError: 346 pass 347 if verbose: 348 print "\nBuilding %s command completion list (this takes"%(self) 349 print "a few seconds only the first time you do it)." 350 print "To force rebuild later, delete %s."%self._COMMANDS_CACHE 351 v = self._commands() 352 353 #Process we now need process the commands to strip out things which 354 #are not valid Python identifiers. 355 import re 356 valid = re.compile('[^a-zA-Z0-9_]+') 357 names = [x for x in v if valid.search(x) is None] 358 359 #Change everything that ends with ? to _q and 360 #everything that ends with ! to _e 361 names += [x[:-1]+"_q" for x in v if x.endswith("?")] 362 names += [x[:-1]+"_e" for x in v if x.endswith("!")] 363 364 self.__trait_names = names 365 if len(v) > 200: 366 # Axiom is actually installed. 367 sage.misc.persist.save(v, self._COMMANDS_CACHE) 368 return names 369 370 def set(self, var, value): 371 """ 372 Set the variable var to the given value. 373 374 EXAMPLES:: 375 376 sage: axiom.set('xx', '2') #optional - axiom 377 sage: axiom.get('xx') #optional - axiom 378 '2' 379 380 sage: fricas.set('xx', '2') #optional - fricas 381 sage: fricas.get('xx') #optional - fricas 382 '2' 383 384 """ 385 cmd = '%s := %s'%(var, value) 386 out = self._eval_line(cmd, reformat=False) 387 388 if out.find("error") != -1: 389 raise TypeError, "Error executing code in Axiom\nCODE:\n\t%s\nAxiom ERROR:\n\t%s"%(cmd, out) 390 391 392 def get(self, var): 393 r""" 394 Get the string value of the Axiom variable var. 395 396 EXAMPLES:: 397 398 sage: axiom.set('xx', '2') #optional - axiom 399 sage: axiom.get('xx') #optional - axiom 400 '2' 401 sage: a = axiom('(1 + sqrt(2))^5') #optional - axiom 402 sage: axiom.get(a.name()) #optional - axiom 403 ' +-+\r\r\n 29\\|2 + 41' 404 """ 405 s = self._eval_line(str(var)) 406 i = s.rfind('Type:') 407 s = s[:i].rstrip().lstrip("\n") 408 if '\n' not in s: 409 s = s.strip() 410 return s 411 347 412 def _eval_line(self, line, reformat=True, allow_use_file=False, 348 413 wait_for_prompt=True): 349 414 """ 350 415 EXAMPLES:: 351 416 352 sage: print axiom._eval_line('2+2') #optional - - requires Axiom417 sage: print axiom._eval_line('2+2') #optional - axiom 353 418 4 354 419 Type: PositiveInteger 355 420 """ … … 360 425 return '' 361 426 if len(line) > 3000: 362 427 raise NotImplementedError, "evaluation of long input lines (>3000 characters) in Axiom not yet implemented." 363 global seq364 seq += 1365 428 if self._expect is None: 366 429 self._start() 367 430 if allow_use_file and self.__eval_using_file_cutoff and \ … … 370 433 try: 371 434 E = self._expect 372 435 # debug 436 self._synchronize(cmd='1+%s\n') 373 437 verbose("in = '%s'"%line,level=3) 374 438 E.sendline(line) 375 439 self._expect.expect(self._prompt) … … 409 473 out = "\n".join(line[i+1:] for line in outs[1:]) 410 474 return out 411 475 412 def _commands(self): 476 477 class Axiom(PanAxiom): 478 def __reduce__(self): 413 479 """ 414 Returns a list of commands available. This is done by parsing the 415 result of the first section of the output of ')what things'. 480 EXAMPLES:: 481 482 sage: axiom.__reduce__() 483 (<function reduce_load_Axiom at 0x...>, ()) 484 sage: f, args = _ 485 sage: f(*args) 486 Axiom 487 """ 488 return reduce_load_Axiom, tuple([]) 489 490 def _function_class(self): 491 """ 492 Return the AxiomExpectFunction class. 416 493 417 494 EXAMPLES:: 418 495 419 sage: cmds = axiom._commands() #optional -- requires Axiom 420 sage: len(cmds) > 100 #optional 421 True 422 sage: '<' in cmds #optional 423 True 424 sage: 'factor' in cmds #optional 425 True 496 sage: axiom._function_class() 497 <class 'sage.interfaces.axiom.AxiomExpectFunction'> 498 sage: type(axiom.gcd) 499 <class 'sage.interfaces.axiom.AxiomExpectFunction'> 426 500 """ 427 s = self.eval(")what things") 428 start = '\r\n\r\n#' 429 i = s.find(start) 430 end = "To get more information about" 431 j = s.find(end) 432 s = s[i+len(start):j].split() 433 return s 501 return AxiomExpectFunction 434 502 503 def _object_class(self): 504 """ 505 EXAMPLES:: 506 507 sage: axiom._object_class() 508 <class 'sage.interfaces.axiom.AxiomElement'> 509 sage: type(axiom(2)) #optional - axiom 510 <class 'sage.interfaces.axiom.AxiomElement'> 511 """ 512 return AxiomElement 435 513 436 def trait_names(self, verbose=True, use_disk_cache=True):514 def _function_element_class(self): 437 515 """ 438 Returns a list of all the commands defined in Axiom and optionally 439 (per default) store them to disk. 516 Returns the Axiom function element class. 440 517 441 518 EXAMPLES:: 442 519 443 sage: c = axiom.trait_names(use_disk_cache=False, verbose=False) #optional 444 sage: len(c) > 100 #optional 445 True 446 sage: 'factor' in c #optional 447 True 448 sage: '**' in c #optional 449 False 450 sage: 'upperCase?' in c #optional 451 False 452 sage: 'upperCase_q' in c #optional 453 True 454 sage: 'upperCase_e' in c #optional 455 True 520 sage: axiom._function_element_class() 521 <class 'sage.interfaces.axiom.AxiomFunctionElement'> 522 sage: type(axiom(2).gcd) #optional - axiom 523 <class 'sage.interfaces.axiom.AxiomFunctionElement'> 456 524 """ 457 try: 458 return self.__trait_names 459 except AttributeError: 460 import sage.misc.persist 461 if use_disk_cache: 462 try: 463 self.__trait_names = sage.misc.persist.load(COMMANDS_CACHE) 464 return self.__trait_names 465 except IOError: 466 pass 467 if verbose: 468 print "\nBuilding Axiom command completion list (this takes" 469 print "a few seconds only the first time you do it)." 470 print "To force rebuild later, delete %s."%COMMANDS_CACHE 471 v = self._commands() 525 return AxiomFunctionElement 472 526 473 #Process we now need process the commands to strip out things which474 #are not valid Python identifiers.475 import re476 valid = re.compile('[^a-zA-Z0-9_]+')477 names = [x for x in v if valid.search(x) is None]478 479 #Change everything that ends with ? to _q and480 #everything that ends with ! to _e481 names += [x[:-1]+"_q" for x in v if x.endswith("?")]482 names += [x[:-1]+"_e" for x in v if x.endswith("!")]483 484 self.__trait_names = names485 if len(v) > 200:486 # Axiom is actually installed.487 sage.misc.persist.save(v, COMMANDS_CACHE)488 return names489 490 def set(self, var, value):491 """492 Set the variable var to the given value.493 494 EXAMPLES::495 496 sage: axiom.set('xx', '2') #optional -- requires Axiom497 sage: axiom.get('xx') #optional498 '2'499 """500 cmd = '%s := %s'%(var, value)501 out = self._eval_line(cmd, reformat=False)502 503 if out.find("error") != -1:504 raise TypeError, "Error executing code in Axiom\nCODE:\n\t%s\nAxiom ERROR:\n\t%s"%(cmd, out)505 506 507 def get(self, var):508 r"""509 Get the string value of the Axiom variable var.510 511 EXAMPLES::512 513 sage: axiom.set('xx', '2') #optional -- requires Axiom514 sage: axiom.get('xx') #optional515 '2'516 sage: a = axiom('(1 + sqrt(2))^5') #optional517 sage: axiom.get(a.name()) #optional518 ' +-+\r\n 29\\|2 + 41'519 """520 s = self._eval_line(str(var))521 i = s.rfind('Type:')522 s = s[:i].rstrip().lstrip("\n")523 if '\n' not in s:524 s = s.strip()525 return s526 527 527 def console(self): 528 528 """ 529 Spawn a new Axiom (FriCAS)command-line session.529 Spawn a new Axiom command-line session. 530 530 531 531 EXAMPLES:: 532 532 533 533 sage: axiom.console() #not tested 534 FriCAS (AXIOM fork)Computer Algebra System535 Version: FriCAS 2007-07-19536 Timestamp: Saturday October 20, 2007 at 20:08:37534 AXIOM Computer Algebra System 535 Version: Axiom (January 2009) 536 Timestamp: Sunday January 25, 2009 at 07:08:54 537 537 ----------------------------------------------------------------------------- 538 538 Issue )copyright to view copyright notices. 539 539 Issue )summary for a summary of useful system commands. … … 541 541 ----------------------------------------------------------------------------- 542 542 """ 543 543 axiom_console() 544 545 546 class AxiomElement(ExpectElement): 544 545 class PanAxiomElement(ExpectElement): 547 546 def __call__(self, x): 548 547 """ 549 548 EXAMPLES:: 550 549 551 sage: f = axiom(x+2) #optional - - requires Axiom552 sage: f(2) #optional 550 sage: f = axiom(x+2) #optional - axiom 551 sage: f(2) #optional - axiom 553 552 4 554 553 """ 555 554 self._check_valid() … … 560 559 """ 561 560 EXAMPLES:: 562 561 563 sage: a = axiom(1); b = axiom(2) # optional 564 sage: a == b # optional 562 sage: two = axiom(2) #optional - axiom 563 sage: two == 2 #optional - axiom 564 True 565 sage: two == 3 #optional - axiom 565 566 False 566 sage: a < b # optional567 sage: two < 3 #optional - axiom 567 568 True 568 sage: a > b # optional 569 sage: two > 1 #optional - axiom 570 True 571 572 sage: a = axiom(1); b = axiom(2) #optional - axiom 573 sage: a == b #optional - axiom 569 574 False 570 sage: b < a # optional 575 sage: a < b #optional - axiom 576 True 577 sage: a > b #optional - axiom 571 578 False 572 sage: b > a # optional 579 sage: b < a #optional - axiom 580 False 581 sage: b > a #optional - axiom 573 582 True 574 583 575 584 We can also compare more complicated object such as functions:: 576 585 577 sage: f = axiom('sin(x)'); g = axiom('cos(x)') # optional578 sage: f == g # optional586 sage: f = axiom('sin(x)'); g = axiom('cos(x)') #optional - axiom 587 sage: f == g #optional - axiom 579 588 False 580 """581 589 582 def __cmp__(self, other):583 """584 EXAMPLES::585 586 sage: two = axiom(2) #optional -- requires Axiom587 sage: two == 2 #optional588 True589 sage: two == 3 #optional590 False591 sage: two < 3 #optional592 True593 sage: two > 1 #optional594 True595 590 """ 596 591 P = self.parent() 597 592 if 'true' in P.eval("(%s = %s) :: Boolean"%(self.name(),other.name())): … … 614 609 615 610 EXAMPLES:: 616 611 617 sage: axiom(x+2).type() #optional - - requires Axiom612 sage: axiom(x+2).type() #optional - axiom 618 613 Polynomial Integer 619 614 """ 620 615 P = self._check_valid() … … 628 623 629 624 EXAMPLES:: 630 625 631 sage: v = axiom('[x^i for i in 0..5]') # optional 632 sage: len(v) # optional 626 sage: v = axiom('[x^i for i in 0..5]') # optional - axiom 627 sage: len(v) # optional - axiom 633 628 6 634 629 """ 635 630 P = self._check_valid() … … 647 642 648 643 EXAMPLES:: 649 644 650 sage: v = axiom('[i*x^i for i in 0..5]'); v # optional 645 sage: v = axiom('[i*x^i for i in 0..5]'); v # optional - axiom 651 646 2 3 4 5 652 647 [0,x,2x ,3x ,4x ,5x ] 653 sage: v[4] # optional 648 sage: v[4] # optional - axiom 654 649 3 655 650 3x 656 sage: v[1] # optional 651 sage: v[1] # optional - axiom 657 652 0 658 sage: v[10] # optional 653 sage: v[10] # optional - axiom 659 654 Traceback (most recent call last): 660 655 ... 661 656 IndexError: index out of range … … 675 670 676 671 EXAMPLES:: 677 672 678 sage: two = axiom(2) #optional - - requires Axiom679 sage: two.comma(3) #optional 673 sage: two = axiom(2) #optional - axiom 674 sage: two.comma(3) #optional - axiom 680 675 [2,3] 681 sage: two.comma(3,4) #optional 676 sage: two.comma(3,4) #optional - axiom 682 677 [2,3,4] 683 sage: _.type() #optional 678 sage: _.type() #optional - axiom 684 679 Tuple PositiveInteger 680 681 sage: two = fricas(2) #optional - fricas 682 sage: two.comma(3) #optional - fricas 683 [2,3] 684 sage: two.comma(3,4) #optional - fricas 685 [2,3,4] 686 sage: _.type() #optional - fricas 687 Tuple PositiveInteger 688 685 689 """ 686 690 P = self._check_valid() 687 691 args = list(args) … … 692 696 return P(cmd) 693 697 694 698 def _latex_(self): 695 """699 r""" 696 700 EXAMPLES:: 701 702 sage: a = axiom(1/2) #optional - axiom 703 sage: latex(a) #optional - axiom 704 \frac{1}{2} 697 705 698 sage: a = axiom(1/2) #optional -- requires Axiom699 sage: latex(a) #optional706 sage: a = fricas(1/2) #optional - fricas 707 sage: latex(a) #optional - fricas 700 708 1 \over 2 701 709 """ 702 710 self._check_valid() 703 711 P = self.parent() 704 s = axiom._eval_line('outputAsTex(%s)'%self.name(), reformat=False)712 s = P._eval_line('outputAsTex(%s)'%self.name(), reformat=False) 705 713 if not '$$' in s: 706 714 raise RuntimeError, "Error texing axiom object." 707 715 i = s.find('$$') … … 715 723 re.sub(r'\\leqno\(.*?\)','',s)) # no eq number! 716 724 return s 717 725 726 def as_type(self, type): 727 """ 728 Returns self as type. 729 730 EXAMPLES:: 718 731 719 class AxiomFunctionElement(FunctionElement): 732 sage: a = axiom(1.2); a #optional - axiom 733 1.2 734 sage: a.as_type(axiom.DoubleFloat) #optional - axiom 735 1.2 736 sage: _.type() #optional - axiom 737 DoubleFloat 738 739 :: 740 741 sage: a = fricas(1.2); a #optional - fricas 742 1.2 743 sage: a.as_type(fricas.DoubleFloat) #optional - fricas 744 1.2 745 sage: _.type() #optional - fricas 746 DoubleFloat 747 748 """ 749 P = self._check_valid() 750 type = P(type) 751 return P.new("%s :: %s"%(self.name(), type.name())) 752 753 def unparsed_input_form(self): 754 """ 755 Get the linear string representation of this object, if possible 756 (often it isn't). 757 758 EXAMPLES:: 759 760 sage: a = axiom(x^2+1); a #optional - axiom 761 2 762 x + 1 763 sage: a.unparsed_input_form() #optional - axiom 764 'x*x+1' 765 766 sage: a = fricas(x^2+1) #optional - fricas 767 sage: a.unparsed_input_form() #optional - fricas 768 'x^2+1' 769 """ 770 P = self._check_valid() 771 s = P.eval('unparse(%s::InputForm)'%self._name) 772 if 'translation error' in s or 'Cannot convert' in s: 773 raise NotImplementedError 774 s = multiple_replace({'\r\n':'', # fix stupid Fortran-ish 775 'DSIN(':'sin(', 776 'DCOS(':'cos(', 777 'DTAN(':'tan(', 778 'DSINH(':'sinh('}, s) 779 r = re.search(r'"(.*)"',s) 780 if r: 781 return r.groups(0)[0] 782 else: 783 return s 784 785 786 def _sage_(self): 787 """ 788 Convert self to a Sage object. 789 790 EXAMPLES:: 791 792 sage: a = axiom(1/2); a #optional - axiom 793 1 794 - 795 2 796 sage: a.sage() #optional - axiom 797 1/2 798 sage: _.parent() #optional - axiom 799 Rational Field 800 801 sage: gp(axiom(1/2)) #optional - axiom 802 1/2 803 804 sage: fricas(1/2).sage() #optional - fricas 805 1/2 806 807 DoubleFloat's in Axiom are converted to be in RDF in Sage. 808 809 :: 810 811 sage: axiom(2.0).as_type('DoubleFloat').sage() #optional - axiom 812 2.0 813 sage: _.parent() #optional - axiom 814 Real Double Field 815 816 817 sage: axiom(2.1234)._sage_() #optional - axiom 818 2.12340000000000 819 sage: _.parent() #optional - axiom 820 Real Field with 53 bits of precision 821 sage: a = RealField(100)(pi) 822 sage: axiom(a)._sage_() #optional - axiom 823 3.1415926535897932384626433833 824 sage: _.parent() #optional - axiom 825 Real Field with 100 bits of precision 826 sage: axiom(a)._sage_() == a #optional - axiom 827 True 828 sage: axiom(2.0)._sage_() #optional - axiom 829 2.00000000000000 830 sage: _.parent() #optional - axiom 831 Real Field with 53 bits of precision 832 833 834 We can also convert Axiom's polynomials to Sage polynomials. 835 sage: a = axiom(x^2 + 1) #optional - axiom 836 sage: a.type() #optional - axiom 837 Polynomial Integer 838 sage: a.sage() #optional - axiom 839 x^2 + 1 840 sage: _.parent() #optional - axiom 841 Univariate Polynomial Ring in x over Integer Ring 842 sage: axiom('x^2 + y^2 + 1/2').sage() #optional - axiom 843 y^2 + x^2 + 1/2 844 sage: _.parent() #optional - axiom 845 Multivariate Polynomial Ring in y, x over Rational Field 846 847 848 """ 849 P = self._check_valid() 850 type = str(self.type()) 851 852 if type == "Domain": 853 return self._sage_domain() 854 855 if type == "Float": 856 from sage.rings.all import RealField, ZZ 857 prec = max(self.mantissa().length()._sage_(), 53) 858 R = RealField(prec) 859 x,e,b = self.unparsed_input_form().lstrip('float(').rstrip(')').split(',') 860 return R(ZZ(x)*ZZ(b)**ZZ(e)) 861 elif type == "DoubleFloat": 862 from sage.rings.all import RDF 863 return RDF(repr(self)) 864 elif type.startswith('Polynomial'): 865 from sage.rings.all import PolynomialRing 866 base_ring = P(type.lstrip('Polynomial '))._sage_domain() 867 vars = str(self.variables())[1:-1] 868 R = PolynomialRing(base_ring, vars) 869 return R(self.unparsed_input_form()) 870 871 #If all else fails, try using the unparsed input form 872 try: 873 import sage.misc.sage_eval 874 return sage.misc.sage_eval.sage_eval(self.unparsed_input_form()) 875 except: 876 raise NotImplementedError 877 878 879 def _sage_domain(self): 880 """ 881 A helper function for converting Axiom domains to the corresponding 882 Sage object. 883 884 EXAMPLES:: 885 886 sage: axiom('Integer').sage() #optional - axiom 887 Integer Ring 888 sage: fricas('Integer').sage() #optional - fricas 889 Integer Ring 890 891 sage: axiom('Fraction Integer').sage() #optional - axiom 892 Rational Field 893 sage: fricas('Fraction Integer').sage() #optional - fricas 894 Rational Field 895 896 sage: axiom('DoubleFloat').sage() #optional - axiom 897 Real Double Field 898 sage: fricas('DoubleFloat').sage() #optional - fricas 899 Real Double Field 900 901 """ 902 P = self._check_valid() 903 name = str(self) 904 if name == 'Integer': 905 from sage.rings.all import ZZ 906 return ZZ 907 elif name == 'DoubleFloat': 908 from sage.rings.all import RDF 909 return RDF 910 elif name.startswith('Fraction '): 911 return P(name.lstrip('Fraction '))._sage_domain().fraction_field() 912 913 raise NotImplementedError 914 915 916 917 class AxiomElement(PanAxiomElement): 918 pass 919 920 class PanAxiomFunctionElement(FunctionElement): 720 921 def __init__(self, object, name): 721 922 """ 722 923 TESTS:: 723 924 724 sage: a = axiom('"Hello"') #optional - - requires Axiom725 sage: a.upperCase_q #optional 925 sage: a = axiom('"Hello"') #optional - axiom 926 sage: a.upperCase_q #optional - axiom 726 927 upperCase? 727 sage: a.upperCase_e #optional 928 sage: a.upperCase_e #optional - axiom 728 929 upperCase! 729 sage: a.upperCase_e() #optional 930 sage: a.upperCase_e() #optional - axiom 730 931 "HELLO" 731 932 """ 732 933 if name.endswith("_q"): … … 735 936 name = name[:-2] + "!" 736 937 FunctionElement.__init__(self, object, name) 737 938 939 class AxiomFunctionElement(PanAxiomFunctionElement): 940 pass 738 941 739 class AxiomExpectFunction(ExpectFunction):942 class PanAxiomExpectFunction(ExpectFunction): 740 943 def __init__(self, parent, name): 741 944 """ 742 945 TESTS:: … … 752 955 name = name[:-2] + "!" 753 956 ExpectFunction.__init__(self, parent, name) 754 957 958 class AxiomExpectFunction(PanAxiomExpectFunction): 959 pass 755 960 756 961 def is_AxiomElement(x): 757 962 """ … … 760 965 EXAMPLES:: 761 966 762 967 sage: from sage.interfaces.axiom import is_AxiomElement 763 sage: is_AxiomElement(axiom(2)) #optional - - requires Axiom968 sage: is_AxiomElement(axiom(2)) #optional - axiom 764 969 True 765 970 sage: is_AxiomElement(2) 766 971 False 767 972 """ 768 973 return isinstance(x, AxiomElement) 769 974 770 # An instance771 axiom = Axiom( script_subdirectory=None)975 #Instances 976 axiom = Axiom(name='axiom') 772 977 773 978 def reduce_load_Axiom(): 774 979 """ … … 786 991 import os 787 992 def axiom_console(): 788 993 """ 789 Spawn a new Axiom (FriCAS)command-line session.994 Spawn a new Axiom command-line session. 790 995 791 996 EXAMPLES:: 792 997 793 998 sage: axiom_console() #not tested 794 FriCAS (AXIOM fork)Computer Algebra System795 Version: FriCAS 2007-07-19796 Timestamp: Saturday October 20, 2007 at 20:08:37999 AXIOM Computer Algebra System 1000 Version: Axiom (January 2009) 1001 Timestamp: Sunday January 25, 2009 at 07:08:54 797 1002 ----------------------------------------------------------------------------- 798 1003 Issue )copyright to view copyright notices. 799 1004 Issue )summary for a summary of useful system commands. 800 1005 Issue )quit to leave AXIOM and return to shell. 801 1006 ----------------------------------------------------------------------------- 1007 802 1008 """ 803 1009 os.system('axiom -nox') 804 1010 805 def __doctest_cleanup():806 """807 EXAMPLES::808 809 sage: from sage.interfaces.axiom import __doctest_cleanup810 sage: a = Axiom()811 sage: two = a(2) #optional -- requires Axiom812 sage: a.is_running() #optional813 True814 sage: __doctest_cleanup()815 sage: a.is_running()816 False817 """818 import sage.interfaces.quit819 sage.interfaces.quit.expect_quitall() -
sage/interfaces/expect.py
diff -r e787cad2d557 -r f3c6593ad0c6 sage/interfaces/expect.py
a b 886 886 """ 887 887 print "%s crashed -- automatically restarting."%self 888 888 889 def _synchronize(self ):889 def _synchronize(self, cmd='1+%s;\n'): 890 890 """ 891 891 Synchronize pexpect interface. 892 892 … … 917 917 return 918 918 rnd = randrange(2147483647) 919 919 s = str(rnd+1) 920 cmd = "1+%s;\n"%rnd920 cmd = cmd%rnd 921 921 self._sendstr(cmd) 922 922 try: 923 923 self._expect_expr(timeout=0.5) … … 993 993 work. Morever if foo is a function then 994 994 X.foo(y,z,...) 995 995 calls foo(X, y, z, ...) and returns the corresponding object. 996 997 EXAMPLES:: 998 999 sage: gp(2) 1000 2 1001 sage: gp('2') 1002 2 1003 sage: a = gp(2); gp(a) is a 1004 True 1005 996 1006 """ 997 1007 cls = self._object_class() 998 1008 999 if isinstance(x, cls) and x.parent() is self: 1000 return x 1009 #Handle the case when x is an object 1010 #in some interface. 1011 if isinstance(x, ExpectElement): 1012 if x.parent() is self: 1013 return x 1014 1015 #We convert x into an object in this 1016 #interface by first going through Sage. 1017 try: 1018 return self(x._sage_()) 1019 except (NotImplementedError, TypeError): 1020 pass 1021 1001 1022 if isinstance(x, basestring): 1002 1023 return cls(self, x, name=name) 1003 1024 try: … … 1489 1510 pass 1490 1511 1491 1512 def _sage_(self): 1513 """ 1514 Attempt to return a Sage version of this object. 1515 This is a generic routine that just tries to evaluate 1516 the repr(self). 1517 1518 EXAMPLES:: 1519 1520 sage: gp(1/2)._sage_() 1521 1/2 1522 sage: _.parent() 1523 Rational Field 1524 """ 1492 1525 #TO DO: this could use file transfers when self.is_remote() 1493 return sage.misc.sage_eval.sage_eval(repr(self).replace('\n','')) 1526 try: 1527 return sage.misc.sage_eval.sage_eval(repr(self).replace('\n','')) 1528 except: 1529 raise NotImplementedError 1494 1530 1495 1531 1496 1532 def sage(self): 1497 1533 """ 1498 1534 Attempt to return a Sage version of this object. 1535 1536 EXAMPLES:: 1537 1538 sage: gp(1/2).sage() 1539 1/2 1540 sage: _.parent() 1541 Rational Field 1499 1542 """ 1500 1543 return self._sage_() 1501 1544 -
new file sage/interfaces/fricas.py
diff -r e787cad2d557 -r f3c6593ad0c6 sage/interfaces/fricas.py
- + 1 r""" 2 Interface to FriCAS 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 FriCAS is a free GPL-compatible (modified BSD license) general 15 purpose computer algebra system based on Axiom. The FriCAS 16 website can be found at http://fricas.sourceforge.net/. 17 18 AUTHORS: 19 20 - Mike Hansen (2009-02): Split off the FriCAS interface from 21 the Axiom interface. 22 23 If the string "error" (case insensitive) occurs in the output of 24 anything from FriCAS, a RuntimeError exception is raised. 25 26 EXAMPLES: We evaluate a very simple expression in FriCas. 27 28 :: 29 30 sage: fricas('3 * 5') # optional - fricas 31 15 32 sage: a = fricas(3) * fricas(5); a # optional - fricas 33 15 34 35 The type of a is FriCASElement, i.e., an element of the axiom 36 interpreter. 37 38 :: 39 40 sage: type(a) # optional - fricas 41 <class 'sage.interfaces.fricas.FriCASElement'> 42 sage: a.parent() # optional - fricas 43 FriCAS 44 45 The underlying FriCAS type of a is also available, via the type 46 method:: 47 48 sage: a.type() # optional - fricas 49 PositiveInteger 50 51 We factor `x^5 - y^5` in FriCAS in several different ways. 52 The first way yields a FriCAS object. 53 54 :: 55 56 sage: F = fricas.factor('x^5 - y^5'); F # optional - fricas 57 4 3 2 2 3 4 58 - (y - x)(y + x y + x y + x y + x ) 59 sage: type(F) # optional - fricas 60 <class 'sage.interfaces.fricas.FriCASElement'> 61 sage: F.type() # optional - fricas 62 Factored(Polynomial(Integer)) 63 64 Note that FriCAS objects are normally displayed using "ASCII art". 65 66 :: 67 68 sage: a = fricas(2/3); a # optional - fricas 69 2 70 - 71 3 72 sage: a = fricas('x^2 + 3/7'); a # optional - fricas 73 2 3 74 x + - 75 7 76 77 The ``fricas.eval`` command evaluates an expression in 78 axiom and returns the result as a string. This is exact as if we 79 typed in the given line of code to axiom; the return value is what 80 FriCAS would print out. 81 82 :: 83 84 sage: print fricas.eval('factor(x^5 - y^5)') # optional - fricas 85 4 3 2 2 3 4 86 - (y - x)(y + x y + x y + x y + x ) Type: Factored(Polynomial(Integer)) 87 88 We can create the polynomial `f` as a FriCAS polynomial, 89 then call the factor method on it. Notice that the notation 90 ``f.factor()`` is consistent with how the rest of Sage 91 works. 92 93 :: 94 95 sage: f = fricas('x^5 - y^5') # optional - fricas 96 sage: f^2 # optional - fricas 97 10 5 5 10 98 y - 2x y + x 99 sage: f.factor() # optional - fricas 100 4 3 2 2 3 4 101 - (y - x)(y + x y + x y + x y + x ) 102 103 Control-C interruption works well with the FriCAS interface. For 104 example, try the following sum but with a much bigger range, and hit 105 control-C. 106 107 :: 108 109 sage: f = fricas('(x^5 - y^5)^10000') # not tested - fricas 110 Interrupting FriCAS... 111 ... 112 <type 'exceptions.TypeError'>: Ctrl-c pressed while running FriCAS 113 114 :: 115 116 sage: fricas('1/100 + 1/101') # optional - fricas 117 201 118 ----- 119 10100 120 sage: a = fricas('(1 + sqrt(2))^5'); a # optional - fricas 121 +-+ 122 29\|2 + 41 123 124 TESTS: We check to make sure the subst method works with keyword 125 arguments. 126 127 :: 128 129 sage: a = fricas(x+2); a #optional - fricas 130 x + 2 131 sage: a.subst(x=3) #optional - fricas 132 5 133 134 We verify that FriCAS floating point numbers can be converted to 135 Python floats. 136 137 :: 138 139 sage: float(fricas(2)) #optional - fricas 140 2.0 141 """ 142 143 ########################################################################### 144 # Copyright (C) 2008 Mike Hansen <mhansen@gmail.com> 145 # 2007 Bill Page 146 # 2006 William Stein <wstein@gmail.com> 147 # 148 # Distributed under the terms of the GNU General Public License (GPL) 149 # The full text of the GPL is available at: 150 # 151 # http://www.gnu.org/licenses/ 152 ########################################################################### 153 from axiom import PanAxiom, PanAxiomElement, PanAxiomFunctionElement, PanAxiomExpectFunction 154 from pexpect import EOF 155 from sage.misc.multireplace import multiple_replace 156 from expect import Expect, ExpectElement, FunctionElement, ExpectFunction 157 from sage.misc.misc import verbose, DOT_SAGE, SAGE_ROOT 158 159 160 class FriCAS(PanAxiom): 161 """ 162 The FriCAS interpreter interfaces. 163 164 TESTS:: 165 166 sage: fricas == loads(dumps(fricas)) 167 True 168 """ 169 def __repr__(self): 170 """ 171 EXAMPLES:: 172 173 sage: fricas 174 FriCAS 175 """ 176 return "FriCAS" 177 178 def __reduce__(self): 179 """ 180 EXAMPLES:: 181 182 sage: fricas.__reduce__() 183 (<function reduce_load_fricas at 0x...>, ()) 184 sage: f, args = _ 185 sage: f(*args) 186 FriCAS 187 """ 188 return reduce_load_fricas, tuple([]) 189 190 def _function_class(self): 191 """ 192 Return the FriCASExpectFunction class. 193 194 EXAMPLES:: 195 196 sage: fricas._function_class() 197 <class 'sage.interfaces.fricas.FriCASExpectFunction'> 198 sage: type(fricas.gcd) 199 <class 'sage.interfaces.fricas.FriCASExpectFunction'> 200 """ 201 return FriCASExpectFunction 202 203 def _object_class(self): 204 """ 205 EXAMPLES:: 206 207 sage: fricas._object_class() 208 <class 'sage.interfaces.fricas.FriCASElement'> 209 sage: type(fricas(2)) #optional - fricas 210 <class 'sage.interfaces.fricas.FriCASElement'> 211 """ 212 return FriCASElement 213 214 def _function_element_class(self): 215 """ 216 Returns the FriCAS function element class. 217 218 EXAMPLES:: 219 220 sage: fricas._function_element_class() 221 <class 'sage.interfaces.fricas.FriCASFunctionElement'> 222 sage: type(fricas(2).gcd) #optional - fricas 223 <class 'sage.interfaces.fricas.FriCASFunctionElement'> 224 """ 225 return FriCASFunctionElement 226 227 def console(self): 228 """ 229 Spawn a new FriCAS command-line session. 230 231 EXAMPLES:: 232 233 sage: fricas.console() #not tested 234 FriCAS (AXIOM fork) Computer Algebra System 235 Version: FriCAS 1.0.5 236 Timestamp: Thursday February 19, 2009 at 06:57:33 237 ----------------------------------------------------------------------------- 238 Issue )copyright to view copyright notices. 239 Issue )summary for a summary of useful system commands. 240 Issue )quit to leave AXIOM and return to shell. 241 ----------------------------------------------------------------------------- 242 """ 243 fricas_console() 244 245 class FriCASElement(PanAxiomElement): 246 pass 247 248 class FriCASFunctionElement(PanAxiomFunctionElement): 249 pass 250 251 class FriCASExpectFunction(PanAxiomExpectFunction): 252 pass 253 254 def is_FriCASElement(x): 255 """ 256 Returns True of x is of type FriCASElement. 257 258 EXAMPLES:: 259 260 sage: from sage.interfaces.fricas import is_FriCASElement 261 sage: is_FriCASElement(fricas(2)) #optional - fricas 262 True 263 sage: is_FriCASElement(2) 264 False 265 """ 266 return isinstance(x, FriCASElement) 267 268 fricas = FriCAS(name='fricas', command='fricas -nox -noclef') 269 270 def reduce_load_fricas(): 271 """ 272 Returns the FriCAS interface object defined in 273 sage.interfaces.fricas. 274 275 EXAMPLES:: 276 277 sage: from sage.interfaces.fricas import reduce_load_fricas 278 sage: reduce_load_fricas() 279 FriCAS 280 """ 281 return fricas 282 283 import os 284 285 def fricas_console(): 286 """ 287 Spawn a new FriCAS command-line session. 288 289 EXAMPLES:: 290 291 sage: fricas_console() #not tested 292 FriCAS (AXIOM fork) Computer Algebra System 293 Version: FriCAS 1.0.5 294 Timestamp: Thursday February 19, 2009 at 06:57:33 295 ----------------------------------------------------------------------------- 296 Issue )copyright to view copyright notices. 297 Issue )summary for a summary of useful system commands. 298 Issue )quit to leave AXIOM and return to shell. 299 ----------------------------------------------------------------------------- 300 """ 301 os.system('fricas -nox') 302 303 def __doctest_cleanup(): 304 """ 305 EXAMPLES:: 306 307 sage: from sage.interfaces.fricas import __doctest_cleanup 308 sage: a = FriCAS() 309 sage: two = a(2) #optional - fricas 310 sage: a.is_running() #optional - fricas 311 True 312 sage: __doctest_cleanup() 313 sage: a.is_running() 314 False 315 """ 316 import sage.interfaces.quit 317 sage.interfaces.quit.expect_quitall() -
sage/interfaces/sage0.py
diff -r e787cad2d557 -r f3c6593ad0c6 sage/interfaces/sage0.py
a b 246 246 Sage 247 247 sage: a is sage0(a) 248 248 True 249 250 TESTS:: 251 252 sage: sage0(axiom(x^2+1)) #optional - axiom 253 x^2 + 1 254 249 255 """ 250 if isinstance(x, SageElement) and x.parent() is self: 251 return x 256 if isinstance(x, ExpectElement): 257 if x.parent() is self: 258 return x 259 else: 260 return self(x.sage()) 261 252 262 if isinstance(x, str): 253 263 return SageElement(self, x) 254 264 -
sage/interfaces/singular.py
diff -r e787cad2d557 -r f3c6593ad0c6 sage/interfaces/singular.py
a b 640 640 sage: I.parent() 641 641 Singular 642 642 """ 643 if isinstance(x, SingularElement) :643 if isinstance(x, SingularElement) and x.parent() is self: 644 644 return x 645 646 elif (not isinstance(x, ExpectElement) and hasattr(x, '_singular_')) or \647 (isinstance(x, ExpectElement) and x.hasattr('_singular_')):648 return getattr(x, '_singular_')(self)645 elif isinstance(x, ExpectElement): 646 return self(x.sage()) 647 elif not isinstance(x, ExpectElement) and hasattr(x, '_singular_'): 648 return x._singular_(self) 649 649 650 650 # some convenient conversions 651 651 if type in ("module","list") and isinstance(x,(list,tuple,Sequence)): -
sage/rings/integer_mod.pyx
diff -r e787cad2d557 -r f3c6593ad0c6 sage/rings/integer_mod.pyx
a b 394 394 """ 395 395 return '%s!%s'%(self.parent()._magma_init_(magma), self) 396 396 397 def _axiom_init_(self): 398 """ 399 Return a string representation of the corresponding to 400 (Pan)Axiom object. 401 402 EXAMPLES:: 403 404 sage: a = Integers(15)(4) 405 sage: a._axiom_init_() 406 '4 :: IntegerMod(15)' 407 408 sage: aa = axiom(a); aa #optional - axiom 409 4 410 sage: aa.type() #optional - axiom 411 IntegerMod 15 412 413 sage: aa = fricas(a); aa #optional - fricas 414 4 415 sage: aa.type() #optional - fricas 416 IntegerMod(15) 417 418 """ 419 return '%s :: %s'%(self, self.parent()._axiom_init_()) 420 421 _fricas_init_ = _axiom_init_ 422 397 423 def _sage_input_(self, sib, coerced): 398 424 r""" 399 425 Produce an expression which will reproduce this value when -
sage/rings/integer_mod_ring.py
diff -r e787cad2d557 -r f3c6593ad0c6 sage/rings/integer_mod_ring.py
a b 286 286 """ 287 287 return "ZZ/%s"%self.order() 288 288 289 def _axiom_init_(self): 290 """ 291 Returns a string representation of self in (Pan)Axiom. 292 293 EXAMPLES:: 294 295 sage: Z7 = Integers(7) 296 sage: Z7._axiom_init_() 297 'IntegerMod(7)' 298 299 sage: axiom(Z7) #optional - axiom 300 IntegerMod 7 301 302 sage: fricas(Z7) #optional - fricas 303 IntegerMod(7) 304 """ 305 return 'IntegerMod(%s)'%self.order() 306 307 _fricas_init_ = _axiom_init_ 308 289 309 def krull_dimension(self): 290 310 """ 291 311 EXAMPLES:: -
sage/rings/rational_field.py
diff -r e787cad2d557 -r f3c6593ad0c6 sage/rings/rational_field.py
a b 821 821 """ 822 822 return "QQ" 823 823 824 def _axiom_init_(self): 825 """ 826 EXAMPLES:: 827 828 sage: axiom(QQ) #optional - axiom 829 Fraction Integer 830 sage: fricas(QQ) #optional - fricas 831 Fraction(Integer) 832 833 """ 834 return 'Fraction Integer' 835 836 _fricas_init_ = _axiom_init_ 837 824 838 def _sage_input_(self, sib, coerced): 825 839 r""" 826 840 Produce an expression which will reproduce this value when evaluated. -
sage/rings/real_mpfr.pyx
diff -r e787cad2d557 -r f3c6593ad0c6 sage/rings/real_mpfr.pyx
a b 2143 2143 import sage.rings.complex_field 2144 2144 return sage.rings.complex_field.ComplexField(self.prec())(self) 2145 2145 2146 def _axiom_(self, axiom): 2147 """ 2148 Returns self as a floating point number in Axiom. 2149 2150 EXAMPLES:: 2151 2152 sage: R = RealField(100) 2153 sage: R(pi) 2154 3.1415926535897932384626433833 2155 sage: axiom(R(pi)) # optional - axiom 2156 3.1415926535 8979323846 26433833 2157 sage: fricas(R(pi)) # optional - fricas 2158 3.1415926535 8979323846 26433833 2159 2160 """ 2161 prec = self.parent().prec() 2162 2163 #Set the precision in Axiom 2164 old_prec = axiom('precision(%s)$Float'%prec) 2165 res = axiom('%s :: Float'%self.exact_rational()) 2166 axiom.eval('precision(%s)$Float'%old_prec) 2167 2168 return res 2169 2170 _fricas_ = _axiom_ 2171 2146 2172 def _pari_(self): 2147 2173 """ 2148 2174 Returns self as a Pari floating-point number. -
sage/structure/sage_object.pyx
diff -r e787cad2d557 -r f3c6593ad0c6 sage/structure/sage_object.pyx
a b 298 298 def _axiom_init_(self): 299 299 return self._interface_init_() 300 300 301 def _fricas_(self, G=None): 302 if G is None: 303 import sage.interfaces.fricas 304 G = sage.interfaces.fricas.fricas 305 return self._interface_(G) 306 307 def _fricas_init_(self): 308 return self._interface_init_() 309 301 310 def _maxima_(self, G=None): 302 311 if G is None: 303 312 import sage.interfaces.maxima