In [1]:
2*3
Out[1]:
6
In [2]:
2^4
Out[2]:
16
In [3]:
1.4+2.6
Out[3]:
4.00000000000000
In [4]:
2/3
Out[4]:
2/3
In [5]:
2/3+1.7
Out[5]:
2.36666666666667
In [6]:
a=2/3+1.7
In [7]:
a
Out[7]:
2.36666666666667
In [8]:
a+5
Out[8]:
7.36666666666667
In [9]:
sin(pi)
Out[9]:
0
In [10]:
diff(3*x^2)
Out[10]:
6*x
In [11]:
y=var('y')
diff(3*y^2)
Out[11]:
6*y
In [12]:
type(a)
Out[12]:
<type 'sage.rings.real_mpfr.RealNumber'>
In [13]:
sin(4) # will not approximate
Out[13]:
sin(4)
In [14]:
N(sin(4))
Out[14]:
-0.756802495307928
In [15]:
N(sin(5), digits=10)
Out[15]:
-0.9589242747

this is a markdown cell $3x^2$

In [16]:
plot?
In [17]:
z=var('z')
plot(sin(z),(z,-6,6), axes=false)
Out[17]:
In [18]:
a
Out[18]:
2.36666666666667
In [19]:
p1=plot(sin(z),(z,-6,6), axes=false)
In [20]:
p2=plot(cos(z^2),(z,-6,6))
In [21]:
show(p2)
In [22]:
show(p1+p2)
In [23]:
plot3d(x^2+2*y^2, (x,-2,2), (y,-2,2))
Out[23]:
In [24]:
p3=parametric_plot([cos(x),sin(x)], (x,0,pi))
In [25]:
show(p1+p3, axes=true)
In [26]:
factor(33)
Out[26]:
3 * 11
In [27]:
factor(2^31-1)
Out[27]:
2147483647
In [28]:
divisors(63)
Out[28]:
[1, 3, 7, 9, 21, 63]
In [29]:
is_prime(2^31+1)
Out[29]:
False
In [30]:
next_prime(7)
Out[30]:
11
In [31]:
gcd(11,121)
Out[31]:
11
In [32]:
gcd(3,7)
Out[32]:
1
In [33]:
x^2+2*x
Out[33]:
x^2 + 2*x
In [34]:
factor(x^2+2*x)
Out[34]:
(x + 2)*x
In [35]:
expand((x^2+17)*(37*x+x^5))
Out[35]:
x^7 + 17*x^5 + 37*x^3 + 629*x
In [36]:
%%time
factor(2^1273-1)
CPU times: user 13.1 s, sys: 95.5 ms, total: 13.2 s
Wall time: 13.4 s
Out[36]:
7639 * 272423 * 524287 * 193707721 * 761838257287 * 1010009364091859253946415882096915728247316963909668502131231962730629328112490054000200587148472755783548706757385217843090477620400711906456373617417113648349531726049904957160259747323084716670346629639738294532363180676161254571893455289289168546575712395096989246115213097149677953936893821176229778487061896303166426347880400358979822044582847
In [37]:
a
Out[37]:
2.36666666666667
In [38]:
a
Out[38]:
2.36666666666667
In [39]:
listy=[1,2,7]
In [40]:
listy
Out[40]:
[1, 2, 7]
In [41]:
listy[0]
Out[41]:
1
In [42]:
listy[2]
Out[42]:
7
In [43]:
listy=[1,1.4,"word",[1,2]]
In [44]:
listy[0]+listy[2]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-44-d113155fda7c> in <module>()
----> 1 listy[Integer(0)]+listy[Integer(2)]

/Applications/SageMath/local/lib/python2.7/site-packages/sage/rings/integer.pyx in sage.rings.integer.Integer.__add__ (build/cythonized/sage/rings/integer.c:11471)()
   1687             return y
   1688 
-> 1689         return coercion_model.bin_op(left, right, operator.add)
   1690 
   1691     cpdef _add_(self, right):

/Applications/SageMath/local/lib/python2.7/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.bin_op (build/cythonized/sage/structure/coerce.c:10649)()
   1209         # We should really include the underlying error.
   1210         # This causes so much headache.
-> 1211         raise bin_op_exception(op, x, y)
   1212 
   1213     cpdef canonical_coercion(self, x, y):

TypeError: unsupported operand parent(s) for +: 'Integer Ring' and '<type 'str'>'
In [45]:
"word1" + "other word"
Out[45]:
'word1other word'
In [46]:
listy
Out[46]:
[1, 1.40000000000000, 'word', [1, 2]]
In [47]:
listy[1:3]
Out[47]:
[1.40000000000000, 'word']