Days 18 Linalg Demo
system:sage


{{{id=1|
m = matrix([[1,2], [3,4]])
///
}}}

{{{id=2|
m^-1
///
[  -2    1]
[ 3/2 -1/2]
}}}

{{{id=3|
m.echelon_form()
///
[1 0]
[0 2]
}}}

{{{id=7|
print m
///
[  0   0  -1]
[  7  -6  -1]
[ -1 -11   1]
}}}

{{{id=4|
m = random_matrix(ZZ, 3); show(m)
///
<html><div class="math">\left(\begin{array}{rrr}
0 & 0 & -1 \\
7 & -6 & -1 \\
-1 & -11 & 1
\end{array}\right)</div></html>
}}}

{{{id=5|
latex(m)
///
\left(\begin{array}{rrr}
0 & 0 & -1 \\
7 & -6 & -1 \\
-1 & -11 & 1
\end{array}\right)
}}}

{{{id=6|
R.<t> = QQ[[]]
///
}}}

{{{id=10|
R
///
Power Series Ring in t over Rational Field
}}}

{{{id=12|
show(R)
///
<html><div class="math">\Bold{Q}[[t]]</div></html>
}}}

{{{id=11|
t
///
t
}}}

{{{id=8|
f = sqrt(1+t); f
///
1 + 1/2*t - 1/8*t^2 + 1/16*t^3 - 5/128*t^4 + 7/256*t^5 - 21/1024*t^6 + 33/2048*t^7 - 429/32768*t^8 + 715/65536*t^9 - 2431/262144*t^10 + 4199/524288*t^11 - 29393/4194304*t^12 + 52003/8388608*t^13 - 185725/33554432*t^14 + 334305/67108864*t^15 - 9694845/2147483648*t^16 + 17678835/4294967296*t^17 - 64822395/17179869184*t^18 + 119409675/34359738368*t^19 + O(t^20)
}}}

{{{id=9|
latex(f)
///
1 + \frac{1}{2}t - \frac{1}{8}t^{2} + \frac{1}{16}t^{3} - \frac{5}{128}t^{4} + \frac{7}{256}t^{5} - \frac{21}{1024}t^{6} + \frac{33}{2048}t^{7} - \frac{429}{32768}t^{8} + \frac{715}{65536}t^{9} - \frac{2431}{262144}t^{10} + \frac{4199}{524288}t^{11} - \frac{29393}{4194304}t^{12} + \frac{52003}{8388608}t^{13} - \frac{185725}{33554432}t^{14} + \frac{334305}{67108864}t^{15} - \frac{9694845}{2147483648}t^{16} + \frac{17678835}{4294967296}t^{17} - \frac{64822395}{17179869184}t^{18} + \frac{119409675}{34359738368}t^{19} + O(t^{20})
}}}

{{{id=13|
show(f)
///
<html><div class="math">1 + \frac{1}{2}t - \frac{1}{8}t^{2} + \frac{1}{16}t^{3} - \frac{5}{128}t^{4} + \frac{7}{256}t^{5} - \frac{21}{1024}t^{6} + \frac{33}{2048}t^{7} - \frac{429}{32768}t^{8} + \frac{715}{65536}t^{9} - \frac{2431}{262144}t^{10} + \frac{4199}{524288}t^{11} - \frac{29393}{4194304}t^{12} + \frac{52003}{8388608}t^{13} - \frac{185725}{33554432}t^{14} + \frac{334305}{67108864}t^{15} - \frac{9694845}{2147483648}t^{16} + \frac{17678835}{4294967296}t^{17} - \frac{64822395}{17179869184}t^{18} + \frac{119409675}{34359738368}t^{19} + O(t^{20})</div></html>
}}}

{{{id=14|
sage_input(f.truncate())
///
R.<t> = QQ[]
119409675/34359738368*t^19 - 64822395/17179869184*t^18 + 17678835/4294967296*t^17 - 9694845/2147483648*t^16 + 334305/67108864*t^15 - 185725/33554432*t^14 + 52003/8388608*t^13 - 29393/4194304*t^12 + 4199/524288*t^11 - 2431/262144*t^10 + 715/65536*t^9 - 429/32768*t^8 + 33/2048*t^7 - 21/1024*t^6 + 7/256*t^5 - 5/128*t^4 + 1/16*t^3 - 1/8*t^2 + 1/2*t + 1
}}}

{{{id=15|
factor(14832)
///
2^4 * 3^2 * 103
}}}

{{{id=16|
R.<x> = QQbar[]
///
}}}

{{{id=17|
R
///
Univariate Polynomial Ring in x over Algebraic Field
}}}

{{{id=18|
a, b = (x^2-2).roots()
///
}}}

{{{id=21|
a[0].minpoly()
///
x^2 - 2
}}}

{{{id=22|
m = random_matrix(ZZ, 5, density=0.2)
///
}}}

{{{id=23|
m
///
[ 0  0  1  0  0]
[-4  0  0  0  0]
[ 0  1  0  0  0]
[-1  0  0  0  0]
[ 0  1  0  0  0]
}}}

{{{id=24|
b = random_matrix(ZZ, 5, 5) * m
///
}}}

{{{id=25|
x = m.solve_left(b)
///
}}}

{{{id=26|
x*m == b
///
True
}}}

{{{id=27|
x = m.solve_right(b)
///
}}}

{{{id=28|
m*x == b
///
True
}}}

{{{id=29|
x = m \ b
///
}}}

{{{id=30|
m*x
///
(1, 2, 3, 4, 5)
}}}

{{{id=31|
m = random_matrix(ZZ, 3000, density=.001)
///
}}}

{{{id=32|
time m.rank()
///
2652
Time: CPU 17.56 s, Wall: 17.11 s
}}}

{{{id=33|
m = random_matrix(ZZ, 3)
///
}}}

{{{id=34|
show(m.eigenspaces())
///
<html><div class="math">\left[\left(a_{0}, \mathrm{RowSpan}_{\Bold{Q}[a_{0}]/(a_{0}^{3} + 4 a_{0}^{2} + 7)}\left(\begin{array}{rrr}
1 & -\frac{1}{3} a_{0}^{2} - \frac{2}{3} a_{0} + \frac{7}{3} & \frac{1}{3} a_{0}^{2} + \frac{5}{3} a_{0} + \frac{2}{3}
\end{array}\right)\right)\right]</div></html>
}}}

{{{id=35|
m = random_matrix(GF(17), 3)
///
}}}

{{{id=36|
m.eigenspaces()
///
[
(15, Vector space of degree 3 and dimension 1 over Finite Field of size 17
User basis matrix:
[1 7 6]),
(13, Vector space of degree 3 and dimension 1 over Finite Field of size 17
User basis matrix:
[ 1 13 12]),
(9, Vector space of degree 3 and dimension 1 over Finite Field of size 17
User basis matrix:
[ 1 11  5])
]
}}}

{{{id=37|
m = random_matrix(QQ, 10)
///
}}}

{{{id=38|
m.minpoly()
///
x^10 - x^9 - 11*x^8 + 73/8*x^7 - 100*x^6 - 541/32*x^5 + 45189/64*x^4 + 2135/32*x^3 - 220523/128*x^2 - 670739/64*x - 959713/128
}}}

{{{id=39|
R = Frac(Qp(7)['x,y,z'])
///
}}}

{{{id=41|
m = matrix(R, [[1,2],[3,R.gen()]]); show(m)
///
<html><div class="math">\left(\begin{array}{rr}
1 + O(7^{20}) & 2 + O(7^{20}) \\
3 + O(7^{20}) & x
\end{array}\right)</div></html>
}}}

{{{id=42|
show(m^4)
///
<html><div class="math">\left(\begin{array}{rr}
(6 + O(7^{20})) x^{2} + (5 + 7 + O(7^{20})) x + 6 + 7^{2} + O(7^{20}) & (2 + O(7^{20})) x^{3} + (2 + O(7^{20})) x^{2} + (5 + 3 \cdot 7 + O(7^{20})) x + 5 + 3 \cdot 7 + O(7^{20}) \\
(3 + O(7^{20})) x^{3} + (3 + O(7^{20})) x^{2} + (4 + 5 \cdot 7 + O(7^{20})) x + 4 + 5 \cdot 7 + O(7^{20}) & x^{4} + (4 + 2 \cdot 7 + O(7^{20})) x^{2} + (5 + 7 + O(7^{20})) x + 6 \cdot 7 + O(7^{20})
\end{array}\right)</div></html>
}}}

{{{id=43|
show(m.echelon.261_form())
///
<html><div class="math">\left(\begin{array}{rr}
1 + O(7^{20}) & 0 \\
0 & \frac{x + 1 + 6 \cdot 7 + 6 \cdot 7^{2} + 6 \cdot 7^{3} + 6 \cdot 7^{4} + 6 \cdot 7^{5} + 6 \cdot 7^{6} + 6 \cdot 7^{7} + 6 \cdot 7^{8} + 6 \cdot 7^{9} + 6 \cdot 7^{10} + 6 \cdot 7^{11} + 6 \cdot 7^{12} + 6 \cdot 7^{13} + 6 \cdot 7^{14} + 6 \cdot 7^{15} + 6 \cdot 7^{16} + 6 \cdot 7^{17} + 6 \cdot 7^{18} + 6 \cdot 7^{19} + O(7^{20})}{x + 1 + 6 \cdot 7 + 6 \cdot 7^{2} + 6 \cdot 7^{3} + 6 \cdot 7^{4} + 6 \cdot 7^{5} + 6 \cdot 7^{6} + 6 \cdot 7^{7} + 6 \cdot 7^{8} + 6 \cdot 7^{9} + 6 \cdot 7^{10} + 6 \cdot 7^{11} + 6 \cdot 7^{12} + 6 \cdot 7^{13} + 6 \cdot 7^{14} + 6 \cdot 7^{15} + 6 \cdot 7^{16} + 6 \cdot 7^{17} + 6 \cdot 7^{18} + 6 \cdot 7^{19} + O(7^{20})}
\end{array}\right)</div></html>
}}}

{{{id=44|
show(m.echelon_form())
///
<html><div class="math">\left(\begin{array}{rr}
1 + O(7^{20}) & 0 \\
0 & \frac{x + 1 + 6 \cdot 7 + 6 \cdot 7^{2} + 6 \cdot 7^{3} + 6 \cdot 7^{4} + 6 \cdot 7^{5} + 6 \cdot 7^{6} + 6 \cdot 7^{7} + 6 \cdot 7^{8} + 6 \cdot 7^{9} + 6 \cdot 7^{10} + 6 \cdot 7^{11} + 6 \cdot 7^{12} + 6 \cdot 7^{13} + 6 \cdot 7^{14} + 6 \cdot 7^{15} + 6 \cdot 7^{16} + 6 \cdot 7^{17} + 6 \cdot 7^{18} + 6 \cdot 7^{19} + O(7^{20})}{x + 1 + 6 \cdot 7 + 6 \cdot 7^{2} + 6 \cdot 7^{3} + 6 \cdot 7^{4} + 6 \cdot 7^{5} + 6 \cdot 7^{6} + 6 \cdot 7^{7} + 6 \cdot 7^{8} + 6 \cdot 7^{9} + 6 \cdot 7^{10} + 6 \cdot 7^{11} + 6 \cdot 7^{12} + 6 \cdot 7^{13} + 6 \cdot 7^{14} + 6 \cdot 7^{15} + 6 \cdot 7^{16} + 6 \cdot 7^{17} + 6 \cdot 7^{18} + 6 \cdot 7^{19} + O(7^{20})}
\end{array}\right)</div></html>
}}}

{{{id=45|
m = random_matrix(ZZ, 5)
///
}}}

{{{id=46|
show(m.smith_form())
///
<html><div class="math">\left(\left(\begin{array}{rrrrr}
1 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 \\
0 & 0 & 0 & 3 & 0 \\
0 & 0 & 0 & 0 & 375
\end{array}\right), \left(\begin{array}{rrrrr}
0 & 0 & 0 & 0 & 1 \\
0 & 0 & 0 & 1 & 0 \\
0 & 0 & 1 & 0 & 0 \\
0 & 1 & 0 & -2 & -2 \\
1 & -83 & 0 & -21 & 42
\end{array}\right), \left(\begin{array}{rrrrr}
59 & 89 & -2 & 118 & 177 \\
-30 & -46 & 1 & -61 & -94 \\
-29 & -44 & 1 & -58 & -87 \\
0 & 0 & 0 & 0 & 1 \\
-2 & -3 & 0 & -4 & -6
\end{array}\right)\right)</div></html>
}}}

{{{id=47|
m = random_matrix(ZZ, 150)
time h = (m.hermite_form())
///
Time: CPU 1.13 s, Wall: 1.36 s
}}}

{{{id=48|
h[-1,-1]
///
8375677550724595192675641077288237457048522483917710157652778465125657401802410520334228193073121691278932506332980975346116095028405721348080390321223130549269468876005491649019466447132328083540300918478697656344292037964238876241671235887400940698709674611150640552770635581963126609487375496376019485012273435032381048445132650095
}}}

{{{id=49|
m = random_matrix(ZZ, 5); m
///
[ 2  1 23 -1  0]
[ 0 -1  1  0 -8]
[ 4 -2  7  4  3]
[ 2 -3  0 -1  2]
[ 0 -1  0 -1  1]
}}}

{{{id=50|
m.column(2)
///
(0, 0, 1)
}}}

{{{id=51|
m[:2,:3]
///
[ 2  1 23]
[ 0 -1  1]
}}}

{{{id=52|
L = range(10)
L
///
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
}}}

{{{id=53|
L[:4]
///
[0, 1, 2, 3]
}}}

{{{id=54|
L[2:4]
///
[2, 3]
}}}

{{{id=55|
V = QQ^3
V
///
Vector space of dimension 3 over Rational Field
}}}

{{{id=60|
V.basis()
///
[
(1, 0, 0),
(0, 1, 0),
(0, 0, 1)
]
}}}

{{{id=59|
V.1
///
(0, 1, 0)
}}}

{{{id=56|
W = span(QQ, (V.gen(0), V.1))
///
}}}

{{{id=57|
V/W
///
Vector space quotient V/W of dimension 1 over Rational Field where
V: Vector space of dimension 3 over Rational Field
W: Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[1 0 0]
[0 1 0]
}}}

{{{id=58|

///
}}}