CoCalc Shared Filessage-8.1.ipynbOpen in CoCalc with one click!
Authors: harald @schil.ly, Harald Schilly
Views : 19
Description: sagemath 8.1 on cocalc

Sage 8.1 on CoCalc

https://www.sagemath.org

In [1]:
version()
'SageMath version 8.1, Release Date: 2017-12-07'
In [2]:
C = matrix([[3, 4, 5], [2, 3, 4], [1, 2, 3]]) C.echelon_form() str(C.echelon_form())
'[ 1 0 -1]\n[ 0 1 2]\n[ 0 0 0]'
In [3]:
B = matrix([[1, 3, 2], [1, 3, 2], [1, 3, 6]]) for ev, evec, mult in B.eigenvectors_left(): print("Eigenvalue: {} with eigenvector: {} of multiplicity {}".format(ev, evec[0], mult))
Eigenvalue: 8 with eigenvector: (1, 3, 4) of multiplicity 1 Eigenvalue: 2 with eigenvector: (1, 3, -2) of multiplicity 1 Eigenvalue: 0 with eigenvector: (1, -1, 0) of multiplicity 1
In [4]:
A = matrix(RDF, [[1, -2, 9], [4, 0, 2], [1, -2, 1]]) b = vector(RDF, [9, 5, -1]) x = A.solve_right(b) print("x: {}".format(x)) print("check A*x: {}".format(A * x)) print("bashslash: {}".format(A \ b))
x: (0.625, 1.4375, 1.25) check A*x: (9.0, 5.0, -1.0) bashslash: (0.625, 1.4375, 1.25)
In [5]:
A * x
(9.0, 5.0, -1.0)
In [6]:
A \ b
(0.625, 1.4375, 1.25)
In [ ]:
In [ ]:
In [7]:
B = BraidGroup(3) B
Braid group on 3 strands
In [8]:
a = B([2, 2, -1, -1, 2, 2]) b = B([2, 1, 2, 1]) print(a.is_pseudoanosov()) print(b.is_pseudoanosov())
True False
In [9]:
c = b * a / b d = a.conjugating_braid(c) d * c / d == a
True
In [10]:
d
s1*s0
In [11]:
c * a / d == c
False
In [ ]:
In [12]:
print("testing collaboration") factor(2018)
testing collaboration
2 * 1009

Elliptic Curves

In [13]:
EllipticCurve('123a').plot()
In [14]:
plot(sin)
In [48]:
var('x') plot(3*x + sin(4*x) * cos(2*x))
In [49]:
12398^293
224920054752209012888072239925666166152953315927462721091292220365989203840057376636804982037728842165211127754871180466185804122534771829601833896090835864196025436431924983737586223453054912366095785663715431040046594888989222421603285849332689122816156762538783671266032400455580674287929966023135712111798722104970689971267808493577063364619666993520659753007743124278585124546857412675047916113619801821701603298491596605616499083576796213009485555458658940236325255710647178563003216835067008947943476212542736824832348107381461218975410691680581263762269729207679626566396639963055239930575299610332004044486445038816865938212752679155455404917676116387237772041501081051928065361009924493262242457662069704890209189008254392022246914545263944336919637398245670306009262211730782937608082885675974083069527353881856749463300889196935129916598467151441999086699148318718203024413285031988755115636641407312419386479420956656440082347351337046535199009414178575816234342725422000488935597626813023611877232335981288141998222754683092883556669209212865773658833243333407531495199652510507949303438066553930402482227408453820470971508908699749310101805069233667208284943155721408078335784578449408
In [50]:
GF_13.<x,y> = GF(13)[]
In [51]:
GF_13
Multivariate Polynomial Ring in x, y over Finite Field of size 13
In [52]:
5 * x + 10 * x + y
2*x + y
In [53]:
Integer("abc", base=35)
12647
In [54]:
Integer("z", base=36)
35
In [55]:
R = IntegerModRing(97) a = R(2) / R(3) print(a) print(a.rational_reconstruction()) b = R(47) print(b^20052005) print(b.modulus()) print("is b square? {}".format(b.is_square()))
33 2/3 50 97 is b square? True
In [56]:
x = Integer('secret', base=36) x
1717162949
In [57]:
x.str(base=36)
'secret'
In [58]:
gcd(2011946, 1450942)
2018
In [26]:
2018 * next_prime(718)
1450942
In [27]:
print(gcd(2011946, 1450942)) print(factor(2018)) c = factorial(25) print(c) print([valuation(c,p) for p in prime_range(2,23)]) print(next_prime(2005)) print(previous_prime(2005)) print('%s %s %s' % (divisors(28), sum(divisors(28)), 2*28))
2018 2 * 1009 15511210043330985984000000 [22, 10, 6, 3, 2, 1, 1, 1] 2011 2003 [1, 2, 4, 7, 14, 28] 56 56
In [28]:
d,u,v = xgcd(20,18) print("d: {d}, u: {u}, v: {v}".format(**locals())) print(d == u*20 + v*18)
d: 2, u: 1, v: -1 True
In [29]:
for m in srange(1, 10): print("m {}: {:>6d}".format(m, inverse_mod(m, 997)))
m 1: 1 m 2: 499 m 3: 665 m 4: 748 m 5: 399 m 6: 831 m 7: 285 m 8: 374 m 9: 554
In [ ]:
inverse_mod?
In [30]:
prime_divisors(20172018)
[2, 3, 79, 42557]
In [31]:
euler_phi(20172018)
6638736
In [32]:
prime_to_m_part(20172018, 2019)
6724006
In [33]:
x = crt(2, 1, 3, 5); x print(x % 3) # x mod 3 = 2 print(x % 5) # x mod 5 = 1 print([binomial(13,m) for m in range(14)]) print([binomial(13,m)%2 for m in range(14)]) print([kronecker(m,13) for m in range(1,13)]) n = 10000 print(sum([moebius(m) for m in range(1,n)])) print(Partitions(4).list())
2 1 [1, 13, 78, 286, 715, 1287, 1716, 1716, 1287, 715, 286, 78, 13, 1] [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1] [1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, 1] -23 [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
In [34]:
K = Qp(11) print(K) a = K(211/17) print(a) b = K(3211/11^2) print(b) print(a + b)
11-adic Field with capped relative precision 20 4 + 4*11 + 11^2 + 7*11^3 + 9*11^5 + 5*11^6 + 4*11^7 + 8*11^8 + 7*11^9 + 9*11^10 + 3*11^11 + 10*11^12 + 11^13 + 5*11^14 + 6*11^15 + 2*11^16 + 3*11^17 + 11^18 + 7*11^19 + O(11^20) 10*11^-2 + 5*11^-1 + 4 + 2*11 + O(11^18) 10*11^-2 + 5*11^-1 + 8 + 6*11 + 11^2 + 7*11^3 + 9*11^5 + 5*11^6 + 4*11^7 + 8*11^8 + 7*11^9 + 9*11^10 + 3*11^11 + 10*11^12 + 11^13 + 5*11^14 + 6*11^15 + 2*11^16 + 3*11^17 + O(11^18)
In [35]:
R.<x> = PolynomialRing(QQ) K = NumberField(x^3 + x^2 - 2*x + 8, 'a') K.galois_group(type="pari")
Galois group PARI group [6, -1, 2, "S3"] of degree 3 of the Number Field in a with defining polynomial x^3 + x^2 - 2*x + 8
In [ ]:
In [36]:
[1, 5, .., 100]
[1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97]

formula [x]2+[y]2[x]^2 + [y]^2

In [37]:
C = matrix([[3, 4, 5], [2, 3, 4], [1, 2, 3]]) C.echelon_form()
[ 1 0 -1] [ 0 1 2] [ 0 0 0]
In [38]:
C = matrix([[3, 4, 5], [2, 3, 4], [1, 2, 3]]) C = C.change_ring(GF(2)) C.echelon_form()
[1 0 1] [0 1 0] [0 0 0]
In [39]:
show(GF(2))
F2\Bold{F}_{2}
In [40]:
C = matrix([[3, 4, 5], [2, 3, 4], [1, 2, 3]]) print(C.echelon_form()) C2 = C.change_ring(GF(2)) print(C2) print(C2.echelon_form())
[ 1 0 -1] [ 0 1 2] [ 0 0 0] [1 0 1] [0 1 0] [1 0 1] [1 0 1] [0 1 0] [0 0 0]
In [41]:
A = matrix([[ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9,10,11,12]]) A[1, 3]
8
In [42]:
A[:, 1]
[ 2] [ 6] [10]
In [43]:
A = matrix([[ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9,10,11,12]]) print(A[0, :] + A[1, :])
[ 6 8 10 12]
In [44]:
print(A[0, :] * A[1, :].transpose())
[70]
In [45]:
print(A[:, 1] + A[:, 2])
[ 5] [13] [21]
In [46]:
A.elementwise_product(A)
[ 1 4 9 16] [ 25 36 49 64] [ 81 100 121 144]
In [59]:
A[0:2, 1:3]
[2 3] [6 7]
In [ ]: