Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168742
Image: ubuntu2004
class integermodring: def __init__(self, modulus): self.modulus = modulus def eval(self, s, globals, locals): _temp = locals['Integer'] locals['Integer'] = IntegerModRing(self.modulus) ans = python.eval(preparse(s), globals, locals) locals['Integer'] = _temp return ans
%integermodring(23) 42 - 9 * 6
11
42 - 9 * 6
-12
class pyint: def eval(self, s, globals, locals): _temp = locals['Integer'] locals['Integer'] = int ans = python.eval(preparse(s), globals, locals) locals['Integer'] = _temp return ans class myint: def eval(self, s, globals, locals): _temp = locals['Integer'] locals['Integer'] = float ans = python.eval(preparse(s), globals, locals) locals['Integer'] = _temp return ans
%pyint() print type(45) print 500 / 1000, 1000 / 1000 print 500 / 1000., 1000 / 1000.
<type 'int'> 0 1 0.500000000000000 1.00000000000000
%myint() print type(45) print 500 / 1000, 1000 / 1000 print 500 / 1000., 1000 / 1000.
<type 'float'> 0.5 1.0 0.500000000000000 1.00000000000000
print type(45) print 500 / 1000, 1000 / 1000 print 500 / 1000., 1000 / 1000.
<type 'sage.rings.integer.Integer'> 1/2 1 0.500000000000000 1.00000000000000
import matplotlib.pyplot as plt
%pyint() plt.plot([1, 1/2, 1/3, 1/4], [1, 1/4, 1/9, 1/16], 'ro') plt.axis([0, 1/2, 0, 2/5]) plt.savefig('pyint.png')

(0,0) ?

%myint() plt.plot([1, 1/2, 1/3, 1/4], [1, 1/4, 1/9, 1/16], 'ro') plt.axis([0, 1/2, 0, 2/5]) plt.savefig('myint.png')
plt.plot([1, 1/2, 1/3, 1/4], [1, 1/4, 1/9, 1/16], 'ro') plt.axis([0, 1/2, 0, 2/5]) plt.savefig('integer.png')
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/sage/sagenb/sage_notebook/worksheets/qed777/19/code/18.py", line 8, in <module> plt.axis([_sage_const_0 , _sage_const_1 /_sage_const_2 , _sage_const_0 , _sage_const_2 /_sage_const_5 ]) File "/home/sage/sage_install/sage-a/local/lib/python2.5/site-packages/matplotlib/pyplot.py", line 827, in axis v = ax.axis(*v, **kwargs) File "/home/sage/sage_install/sage-a/local/lib/python2.5/site-packages/matplotlib/axes.py", line 1250, in axis self.set_xlim([v[0], v[1]]) File "/home/sage/sage_install/sage-a/local/lib/python2.5/site-packages/matplotlib/axes.py", line 1944, in set_xlim xmin, xmax = mtransforms.nonsingular(xmin, xmax, increasing=False) File "/home/sage/sage_install/sage-a/local/lib/python2.5/site-packages/matplotlib/transforms.py", line 2237, in nonsingular if (not np.isfinite(vmin)) or (not np.isfinite(vmax)): TypeError: function not supported for these types, and can't coerce safely to supported types