Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Replacing the default pexpect module with the a newer version that supports unicode.

Views: 64

###Replacing the default pexpect module with the a newer version that supports unicode. http://trac.sagemath.org/ticket/10295

####To use a newer version of pexpect (or other module) in a Sage worksheet install the module in some directory using pip or other means:

~$ export PYTHONPATH=$HOME/lib/python2.7/site-packages ~$ mkdir -p $PYTHONPATH ~$ pip install -t $PYTHONPATH pexpect Downloading/unpacking pexpect Downloading pexpect-3.3.tar.gz (132kB): 132kB downloaded Running setup.py (path:/tmp/pip_build_4bc390137b654a659d3dbec4a4ce4d5a/pexpect/setup.py) egg_info for package pexpect Installing collected packages: pexpect Running setup.py install for pexpect Successfully installed pexpect Cleaning up...

Add the new directory to the interpreter's module search path.

sys.path.insert(0,'%s/lib/python2.7/site-packages'%os.environ['HOME'])

If you are replacing an existing module you must force a reload of that module and any of its dependent modules.

import pexpect reload(pexpect) pexpect.__version__ import expect reload(expect) #reload(sage.interfaces.expect) reload(sage.interfaces.axiom) reload(sage.interfaces.fricas)
<module 'pexpect' from '/projects/4bc39013-7b65-4a65-9d3d-bec4a4ce4d5a/lib/python2.7/site-packages/pexpect/__init__.pyc'> '3.3' <module 'expect' from './expect.pyc'> <module 'sage.interfaces.axiom' from '/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/interfaces/axiom.pyc'> <module 'sage.interfaces.fricas' from '/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/interfaces/fricas.pyc'>

Now FriCAS mode supports unicode variable names.

%fricas α+β
β + α Type: Polynomial(Integer)
alpha=fricas("α") beta=fricas("β") alpha/beta
α - β

But Sage itself still does not support unicode variable names.

var('α')
Error in lines 1-1 Traceback (most recent call last): File "/projects/4bc39013-7b65-4a65-9d3d-bec4a4ce4d5a/.sagemathcloud/sage_server.py", line 879, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/projects/4bc39013-7b65-4a65-9d3d-bec4a4ce4d5a/.sagemathcloud/sage_salvus.py", line 2736, in var return var0(*args, **kwds) File "/projects/4bc39013-7b65-4a65-9d3d-bec4a4ce4d5a/.sagemathcloud/sage_salvus.py", line 2698, in var0 v = sage.all.SR.var(name, **kwds) File "sage/symbolic/ring.pyx", line 595, in sage.symbolic.ring.SymbolicRing.var (build/cythonized/sage/symbolic/ring.cpp:8473) cpdef var(self, name, latex_name=None, domain=None): File "sage/symbolic/ring.pyx", line 648, in sage.symbolic.ring.SymbolicRing.var (build/cythonized/sage/symbolic/ring.cpp:8147) raise ValueError('The name "'+s+'" is not a valid Python identifier.') ValueError: The name "α" is not a valid Python identifier.
(alpha+beta).sage()
Error in lines 1-1 Traceback (most recent call last): File "/projects/4bc39013-7b65-4a65-9d3d-bec4a4ce4d5a/.sagemathcloud/sage_server.py", line 879, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/interfaces/interface.py", line 869, in sage return self._sage_() File "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/interfaces/axiom.py", line 883, in _sage_ R = PolynomialRing(base_ring, vars) File "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_ring_constructor.py", line 472, in PolynomialRing R = _multi_variate(base_ring, names, n, sparse, order, implementation) File "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_ring_constructor.py", line 564, in _multi_variate names = normalize_names(n, names) File "sage/structure/parent_gens.pyx", line 207, in sage.structure.parent_gens.normalize_names (build/cythonized/sage/structure/parent_gens.c:2797) names = _certify_names(names) File "sage/structure/parent_gens.pyx", line 146, in sage.structure.parent_gens._certify_names (build/cythonized/sage/structure/parent_gens.c:2245) raise ValueError, "variable names must be alphanumeric, but one is '%s' which is not."%N ValueError: variable names must be alphanumeric, but one is 'β' which is not.
#reload(sage.interfaces.expect) reload(sage.interfaces.gap)
<module 'sage.interfaces.gap' from '/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/interfaces/gap.pyc'>
gap.set('x', '2')
gap('x')
2
gap.set('α', '2')
Error in lines 1-1 Traceback (most recent call last): File "/projects/4bc39013-7b65-4a65-9d3d-bec4a4ce4d5a/.sagemathcloud/sage_server.py", line 879, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/interfaces/gap.py", line 1303, in set out = self._eval_line(cmd, allow_use_file=True) File "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/interfaces/gap.py", line 769, in _eval_line raise RuntimeError(message) RuntimeError: Gap produced error output Syntax error: expression expected α:=2;; ^ executing α:=2;;
reload(sage.interfaces.singular)
<module 'sage.interfaces.singular' from '/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/interfaces/singular.pyc'>
singular.set('int','α','2') singular('α')
2
singular.ring(0, '(x,y)', 'dp') singular('9x16 - 18x13y2')
// characteristic : 0 // number of vars : 2 // block 1 : ordering dp // : names x y // block 2 : ordering C 9*x^16-18*x^13*y^2
singular.ring(0, '(α,β)', 'dp')
// characteristic : 0 // number of vars : 2 // block 1 : ordering dp // : names N1 N2 // block 2 : ordering C
singular('9α16 - 18α13β2')
Error in lines 1-1 Traceback (most recent call last): File "/projects/4bc39013-7b65-4a65-9d3d-bec4a4ce4d5a/.sagemathcloud/sage_server.py", line 879, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/interfaces/singular.py", line 729, in __call__ return SingularElement(self, type, x, False) File "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/interfaces/singular.py", line 1189, in __init__ self._name = parent._create( value, type) File "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/interfaces/singular.py", line 690, in _create self.set(type, name, value) File "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/interfaces/singular.py", line 633, in set self.eval(cmd) File "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/interfaces/singular.py", line 590, in eval raise SingularError('Singular error:\n%s'%s) TypeError: Singular error: ? error occurred in or before STDIN line 23: `if(defined(sage9)){kill sage9;};def sage11=9N116 - 18N113N22;`

Apparently Maxima does not properly display unicode but otherwise does not complain.

alpha=maxima("α") beta=maxima("β") alpha/beta
\±/\²
maxima.set('α', '2') maxima('α')
2
alpha+1
\±+1
labs = r.paste('c("X","Y")', '1:10', sep='""'); labs
[1] "X1" "Y2" "X3" "Y4" "X5" "Y6" "X7" "Y8" "X9" "Y10"
labs = r.paste('c("α","β")', '1:10', sep='""'); labs
[1] "α1" "β2" "α3" "β4" "α5" "β6" "α7" "β8" "α9" "β10"
octave.set('α', '2')
Error in lines 1-1
octave.get('α')
''
https://github.com/sagemath/cloud/wiki/FAQ
Remeber to add a note to FAQ