AUTHORS:
Bases: sage.symbolic.expression.Expression
An automatically created symbolic variable with an additional __call__() method designed so that doing self(foo,...) results in foo.self(...).
Exec the string s in the scope of the globals dictionary, and if any NameErrors are raised, try to fix them by defining the variable that caused the error to be raised, then eval again. Try up to max_names times.
INPUT:
- s – a string
- globals – a dictionary
- max_names – a positive integer (default: 10000)
Wrap the string s in a call that will cause evaluation of s to automatically create undefined variable names.
INPUT:
- s – a string
OUTPUT:
- a string
Turn automatic creation of variables and functional calling of methods on or off. Returns the current state if no argument is given.
This ONLY works in the Sage notebook. It is not supported on the command line.
INPUT:
OUTPUT:
EXAMPLES:
sage: automatic_names(True) # not tested
sage: x + y + z # not tested
x + y + z
Here, trig_expand, y, and theta are all automatically created:
sage: trig_expand((2*x + 4*y + sin(2*theta))^2) # not tested
4*(sin(theta)*cos(theta) + x + 2*y)^2
IMPLEMENTATION: Here’s how this works, internally. We define an AutomaticVariable class derived from Expression. An instance of AutomaticVariable is a specific symbolic variable, but with a special __call__() method. We overload the call method so that foo(bar, ...) gets transformed to bar.foo(...). At the same time, we still want expressions like f^2 - b to work, i.e., we don’t want to have to figure out whether a name appearing in a NameError is meant to be a symbolic variable or a function name. Instead, we just make an object that is both!
This entire approach is very simple—we do absolutely no parsing of the actual input. The actual real work amounts to only a few lines of code. The primary catch to this approach is that if you evaluate a big block of code in the notebook, and the first few lines take a long time, and the next few lines define 10 new variables, the slow first few lines will be evaluated 10 times. Of course, the advantage of this approach is that even very subtle code that might inject surprisingly named variables into the namespace will just work correctly, which would be impossible to guarantee with static parsing, no matter how sophisticated it is. Finally, given the target audience: people wanting to simplify use of Sage for Calculus for undergrads, I think this is an acceptable tradeoff, especially given that this implementation is so simple.
Return a list of completions in the given context.
INPUT:
OUTPUT:
Compile a file containing Cython code, then import and return the module. Raises an ImportError if anything goes wrong.
INPUT:
OUTPUT:
Imports all non-private (i.e., not beginning with an underscore) attributes of the specified Cython module into the given context. This is similar to:
from module import *
Raises an ImportError exception if anything goes wrong.
INPUT:
Format an object’s docstring to process and display in the Sage notebook.
INPUT:
OUTPUT:
AUTHORS:
Display HTML help for obj, a Python object, module, etc. This help is often more extensive than that given by ‘obj?’. This function does not return a value — it prints HTML as a side effect.
Note
This a wrapper around the built-in help. If formats the output as HTML without word wrap, which looks better in the notebook.
INPUT:
TESTS:
sage: import numpy.linalg
sage: import os, sage.misc.misc ; current_dir = os.getcwd()
sage: os.chdir(sage.misc.misc.tmp_dir('server_doctest'))
sage: sage.server.support.help(numpy.linalg.norm)
<html><table notracebacks bgcolor="#386074" cellpadding=10 cellspacing=10><tr><td bgcolor="#f5f5f5"><font color="#37546d">
<a target='_new' href='cell://docs-....html'>Click to open help window</a>
<br></font></tr></td></table></html>
sage: os.chdir(current_dir)
Preparse the contents of a worksheet cell in the notebook, respecting the user using preparser(False) to turn off the preparser. This function calls preparse_file() which also reloads attached files. It also does displayhook formatting by calling the displayhook_hack() function.
INPUT:
OUTPUT:
- a string
Format an object’s source code to process and display in the Sage notebook.
INPUT:
OUTPUT:
AUTHORS:
Evaluate an input with a “system” object that can evaluate inputs (e.g., python, gap).
INPUT:
OUTPUT:
EXAMPLES:
sage: from sage.misc.python import python
sage: sage.server.support.syseval(python, '2+4/3')
3
''
sage: sage.server.support.syseval(python, 'import os; os.chdir(".")')
''
sage: sage.server.support.syseval(python, 'import os; os.chdir(1,2,3)')
...
TypeError: chdir() takes exactly 1 argument (3 given)
sage: sage.server.support.syseval(gap, "2+3")
'5'