For a full list see: https://www.sagemath.org/links-components.html
726471264+36816
sqrt(5.0)
sqrt(5).n()
show(sqrt(5))
a = 615711658618567
a.is_prime()
a.factor()
a.previous_prime()
a.next_prime()
Over Finite Fields
K.<a> = GF(5^45);K
a.multiplicative_order()
a.is_square()
b = a.square_root()
b
b^2
a, b = 282, 384
gcd(a,b)
d, x, y = xgcd(a,b)
print(d,x,y)
x*a+y*b == d
P.<x> = QQ[]
F = (x^2 + 2)*x^3
G = (x^2+2)*(x-3)
g, u, v = QQ._xgcd_univariate_polynomial(F,G)
print(f'g={g}, u={u}, v={v}')
u*F + v*G==g # Verification of Bezout's Identity
P1 = [] # list of pairs (n,n) when n is prime
P2 = [] # list of pairs (n,d) where d|n and n is not prime
for n in xsrange(1,500):
if n.is_prime():
P1.append((n,n))
else:
P2.extend([(n,d) for d in n.divisors()[1:]])
G1 = point2d(P1,color='red',pointsize=20)
G2 = point2d(P2,color='blue',pointsize=5)
(G1 + G2).show()
Let us explore the function
f(x) = sin(x^2)+x*exp(2-x^2)+x^2-3*x+1
show(f(x))
latex(f(x))
f.plot(-2,4,color ='red',figsize=5)
f.diff()
f3 = f.diff(3)
f.plot(-1,1,color='red')+f3.plot(-1,1,color='blue')
f.find_local_maximum(0,2)
f.find_root(1,2)
f.taylor(x,0,8)
#help(solve)
reset()
var('y')
sols = solve([x^3==y,y^2==x], [x,y]);
sols
var('x,y')
f(x,y)=(x^2-y^2)*exp(-x^2-y^2)
ct = contour_plot(f(x,y),(x,-2,2),(y,-2,2),contours=12,fill=False,
labels=True,cmap='hsv',label_colors='black')
gr = f.gradient()
vf = plot_vector_field(gr,(x,-2,2),(y,-2,2),color='red')
ct+vf
latex(f(x,y))
plot3d(f(x,y),(x,-2,2),(y,-2,2))
f.diff(x)
f.diff(x,y)
f.gradient()
f.hessian()(x=1,y=-1)
v = vector(QQ,[-2,3])
u = vector(QQ,[1,-1])
reset()
A = matrix(QQ, [
[1, 1, 2, -1 ,1, 1],
[-6, 3, 7, -3, 0, 3],
[-2, 0, 5, -1, 0, 1],
[-10, 0, 10, -2, 1, 5],
[2, 0, -2, 1, 3, -1],
[-6, 2, 6, -3, 3, 6]])
A.jordan_form()
@interact
def linear_transformation(A=matrix(QQ,[[1,1],[1/2,-1]]),
u=matrix(QQ,[2,2]),v=matrix(QQ,[-1,2])):
u=vector(QQ,[u[0,0],u[0,1]])
v=vector(QQ,[v[0,0],v[0,1]])
r =1.1
e=vector(QQ,[1/10,1/10])
u1 = A*u
v1 = A*v
p1=plot(u,color='red')+plot(v,color='green')
p1=p1+plot(u+v,color='blue')
p1=p1+line((u,u+v),linestyle="--",color='black')
p1=p1+line((v,u+v),linestyle="--",color='black')
p2=plot(A*u,color='red')+plot(A*v,color='green')
p2=p2+plot(A*(u+v),color='blue')
p2=p2+line((A*u,A*(u+v)),linestyle="--",color='black')
p2=p2+line((A*v,A*(u+v)),linestyle="--",color='black')
t=text('$u$',r*u)+text('$v$',r*v)+text('$u+v$',r*(u+v))
t=t+text('$Au$',r*A*u,color='red')+text('$Av$',r*A*v,color='red')+text('$A(u+v)$',r*A*(u+v),color='red')
show(p1+p2+t,aspect_ratio=1)
G =SymmetricGroup(6)
a = G.random_element()
a.order()
G = GL(3,5)
S = SL(3,5)
G.order()
S.order()
n,p=2,5
G = GL(n,GF(p))
print(G.order())
print(factor(G.order()))
O2 = [g for g in G if g.multiplicative_order()==2]
O4 = [g for g in G if g.multiplicative_order()==4]
(len(O2),len(O4))
for i in range(len(O2)):
for j in range(len(O4)):
A,B= O4[i],O4[j]
H = MatrixGroup([matrix(GF(p),n,flatten(A.list())),
matrix(GF(p),n,flatten(B.list()))]);
if(H.order()==32):
break
print(H.order())
G = CyclicPermutationGroup(30)
subgroups = G.subgroups()
P = Poset((subgroups, lambda h,k: h.is_subgroup(k)))
relabeling = {h:h.order() for (i,h) in enumerate(P)}
Q = P.relabel(relabeling)
LZ30_2=Q.plot(figsize=5,element_size=500)
LZ30_2
Image processing usng SVD from Python Numpy
from matplotlib.pyplot import imread
import pylab
import numpy as np
img=pylab.imread('Image2.png')
matrix_plot(img)
R1 = img[:,:,0] # Red channel
G1 = img[:,:,1] # Green Channel
B1 = img[:,:,2] # Blue Channel
R1.shape,G1.shape,B1.shape
graphics_array([matrix_plot(R1),matrix_plot(G1),matrix_plot(B1)])
img.shape
img_transposed = np.transpose(img, (2, 0, 1))
img_transposed.shape
U, s, Vt = np.linalg.svd(img_transposed)
Sigma = np.zeros(img_transposed.shape)
for j in range(3):
np.fill_diagonal(Sigma[j, :, :], s[j, :])
Sigma.shape
reconstructed = U @ Sigma @ Vt
k= 5
approx_img = U @ Sigma[..., :k] @ Vt[..., :k, :]
pylab.imshow(np.transpose(approx_img, (1, 2, 0)))
k= 10
approx_img = U @ Sigma[..., :k] @ Vt[..., :k, :]
pylab.imshow(np.transpose(approx_img, (1, 2, 0)))
k= 20
approx_img = U @ Sigma[..., :k] @ Vt[..., :k, :]
pylab.imshow(np.transpose(approx_img, (1, 2, 0)))
k= 50
approx_img = U @ Sigma[..., :k] @ Vt[..., :k, :]
pylab.imshow(np.transpose(approx_img, (1, 2, 0)))
k= 100
approx_img = U @ Sigma[..., :k] @ Vt[..., :k, :]
pylab.imshow(np.transpose(approx_img, (1, 2, 0)))
References