In [1]:
2*3
Out[1]:
6
In [2]:
2^5
Out[2]:
32
In [3]:
20/4
Out[3]:
5
In [4]:
2/3
Out[4]:
2/3
In [5]:
2/3 + 7/3
Out[5]:
3
In [12]:
4/3+11/3
Out[12]:
5
In [7]:
2/3+10/17
Out[7]:
64/51
In [13]:
4/7+11/7
Out[13]:
15/7
In [9]:
13*7
43*2
Out[9]:
86
In [10]:
print(13*7)
43*2
91
Out[10]:
86
In [11]:
a = 3
a+5
Out[11]:
8

This is a "markdown" cell for text

Now we are going to do graphing $x^2$

In [14]:
2^4
Out[14]:
16
In [15]:
plot(x^2)
Out[15]:
In [17]:
z = var('z') # have to tell sage that z should be a symbolic variable
plot(z^2)
Out[17]:
In [19]:
plot(sin(x),(-6,6))
Out[19]:
In [21]:
sin(pi) # this is a comment - sin is evaluated in degrees
Out[21]:
0
In [24]:
# typing a question mark after a command gives a help page about it
plot?
In [25]:
sin?
In [30]:
p1 = plot(sin(x^2), (-6,6), color='red')
In [28]:
p2 = plot(sin(x), (-6,6))
In [31]:
p1+p2
Out[31]:
In [34]:
# doesn't work on SINC site computers, may work on yours
y= var('y') # tells sage that y is a symbolic variable
plot3d(x^2+y^2, (x,-2,2), (y,-2,2))
Out[34]:
In [1]:
factor(24) # factors number into primes
Out[1]:
2^3 * 3
In [40]:
factor(1102129121293812302138) 
Out[40]:
2 * 7^2 * 41 * 111773 * 2454062605417
In [47]:
factor(2^501-1) #takes too long, we should interrupt using stop bottom
/opt/sagemath-8.9/local/lib/python2.7/site-packages/sage/repl/ipython_kernel/__main__.py:1: RuntimeWarning: cypari2 leaked 1160984 bytes on the PARI stack
  from ipykernel.kernelapp import IPKernelApp
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-47-c065b5d2d2ae> in <module>()
----> 1 factor(Integer(2)**Integer(501)-Integer(1))

/opt/sagemath-8.9/local/lib/python2.7/site-packages/sage/arith/misc.py in factor(n, proof, int_, algorithm, verbose, **kwds)
   2592     if isinstance(n, Integer):
   2593         return m(proof=proof, algorithm=algorithm, int_=int_,
-> 2594                  verbose=verbose, **kwds)
   2595 
   2596     # Polynomial or other factorable object

/opt/sagemath-8.9/local/lib/python2.7/site-packages/sage/rings/integer.pyx in sage.rings.integer.Integer.factor (build/cythonized/sage/rings/integer.c:25512)()
   4022         if algorithm == 'pari':
   4023             from sage.rings.factorint import factor_using_pari
-> 4024             F = factor_using_pari(n, int_=int_, debug_level=verbose, proof=proof)
   4025             F.sort()
   4026             return IntegerFactorization(F, unit=unit, unsafe=True,

/opt/sagemath-8.9/local/lib/python2.7/site-packages/sage/rings/factorint.pyx in sage.rings.factorint.factor_using_pari (build/cythonized/sage/rings/factorint.c:6401)()
    343             pari.set_debug_level(debug_level)
    344 
--> 345         p, e = n.__pari__().factor(proof=proof)
    346         if int_:
    347             return [(int(p[i]), int(e[i])) for i in range(len(p))]

cypari2/gen.pyx in cypari2.gen.Gen.factor()

KeyboardInterrupt: 
In [48]:
factor(24)
Out[48]:
2^3 * 3
In [49]:
divisors(24)
Out[49]:
[1, 2, 3, 4, 6, 8, 12, 24]
In [51]:
factor(x^2+2*x+1) # x^2+2x+1 doesn't work
Out[51]:
(x + 1)^2
In [52]:
factor(x^4-1)
Out[52]:
(x^2 + 1)*(x + 1)*(x - 1)
In [53]:
expand((x-4)*(x^2+17))
Out[53]:
x^3 - 4*x^2 + 17*x - 68
In [54]:
diff(x^3)
Out[54]:
3*x^2
In [56]:
list_of_divisors = divisors(24) # stores divisors(24) into list_of_divisors
In [57]:
list_of_divisors
Out[57]:
[1, 2, 3, 4, 6, 8, 12, 24]
In [60]:
list_of_divisors[0] # list indexing starts at 0
Out[60]:
1
In [63]:
list_of_divisors[7] 
Out[63]:
24
In [64]:
list1 = [4,5,6]
In [65]:
list2 = [13,15,17]
In [66]:
list1+list2
Out[66]:
[4, 5, 6, 13, 15, 17]
In [67]:
list3 = [1,2,3,"word"] # "word" is a string
In [68]:
list1+list3
Out[68]:
[4, 5, 6, 1, 2, 3, 'word']
In [69]:
"word" + "another word" # adding strings
Out[69]:
'wordanother word'
In [70]:
list3[1:3] # includes list3[1], but not list3[3]
Out[70]:
[2, 3]
In [72]:
list3[1]
Out[72]:
2
In [73]:
list3[2]
Out[73]:
3
In [ ]: