% Sage Linear Algebra Quick Reference
% (c) 2009 by Robert A. Beezer
% Licensed with the GNU Free Documentation License (GFDL)
%   http://www.gnu.org/copyleft/fdl.html
%
%  History
%
%    2009-05-10  Initial version based on Sage 3.4
%    2009-05-13  Added right paren to vector u in "vector operations" section
%    2010-08-15  Miscellaneous edits
%    2011-12-12  Update to Sage 4.8
%    2012-03-31  Modified. Use a4paper
%
\documentclass[a4paper]{article}
\usepackage{graphicx}  
\usepackage[landscape]{geometry}
%\usepackage[pdftex]{color}
\usepackage[dvipdfm]{color}

\usepackage{quickrefcard}  

\usepackage{multicol}
\usepackage{amsmath}
\usepackage{amsfonts}
\newcommand{\QQ}{\mathbb{Q}}
\newcommand{\ZZ}{\mathbb{Z}}
\newcommand{\FF}{\mathbb{F}}

\begin{document}
\begin{multicols*}{3}
\begin{center}
\textbf{Sage Quick Reference: Linear Algebra}\\
Robert A. Beezer (Mod. by nu)\\
Sage Version 4.8\\
\url{http://wiki.sagemath.org/quickref}\\
GNU Free Document License, extend for your own use\\
Based on work by Peter Jipsen, William Stein 
\end{center}
% backup over center environment gap
\vspace{-2ex}
%*********************************************
\sect[Vector Constructions]{ベクトルの作成}
\CAUTION{ベクトルの添字は0 始まり}

\EX{u = vector(QQ, [1, 3/2, -1])} 
有理数体上, 長さ3


\EX{v = vector(QQ, {2:4, 95:4, 210:0})} 
\BreakLineAndIndent
211成分, 非零なのは第2成分と第95成分の4だけ, sparse
\begin{original}
\CAUTION{First entry of a vector is numbered 0}

\EX{u = vector(QQ, [1, 3/2, -1])} length 3 over rationals

\EX{v = vector(QQ, {2:4, 95:4, 210:0})} 
\BreakLineAndIndent
  211 entries, nonzero in entry 4 and entry 95, sparse
\end{original}
%*********************************************
\sect[Vector Operations]{ベクトルへの操作}
\EX{u = vector(QQ, [1, 3/2, -1])}\\
\EX{v = vector(ZZ, [1, 8, -2])}\\
\EX{2*u - 3*v} 線型結合\\
\EX{u.dot_product(v)}\\
\EX{u.cross_product(v)}  順序は \sagecommand{u}$\times$\sagecommand{v}\\
\EX{u.inner_product(v)}  \sagecommand{u}と\sagecommand{v}の内積\\
\EX{u.pairwise_product(v)} 計算結果のベクトル\\
\EX{u.norm() == u.norm(2)} ユークリッドノルム\\
\EX{u.norm(1)} 要素の絶対値の和\\
\EX{u.norm(Infinity)} 絶対値が最大の要素\\
\EX{A.gram_schmidt()} 行列\sagecommand{A}の行を変換
\begin{original}
\EX{u = vector(QQ, [1, 3/2, -1])}\\
\EX{v = vector(ZZ, [1, 8, -2])}\\
\EX{2*u - 3*v} linear combination\\
\EX{u.dot_product(v)}\\
\EX{u.cross_product(v)}  order: \sagecommand{u}$\times$\sagecommand{v}\\
\EX{u.inner_product(v)}  inner product matrix from parent\\
\EX{u.pairwise_product(v)} vector as a result\\
\EX{u.norm() == u.norm(2)} Euclidean norm\\
\EX{u.norm(1)} sum of entries\\
\EX{u.norm(Infinity)} maximum entry\\
\EX{A.gram_schmidt()} converts the rows of matrix \sagecommand{A}
\end{original}
%*********************************************
\sect[Matrix Constructions]{行列の生成}
\CAUTION{行も列も添字は$0$始まり}

\EX{A = matrix(ZZ, [[1,2],[3,4],[5,6]])} 
%\BreakLineAndIndent
  $3\times 2$整数行列

\EX{B = matrix(QQ, 2, [1,2,3,4,5,6])} 
\BreakLineAndIndent
  リストから$2$行の行列を作る. 従って$2\times 3$有理数行列.  


\EX{C = matrix(CDF, 2, 2, [[5*I, 4*I], [I, 6]])} 
\BreakLineAndIndent
  複素数, 53-bit 精度の行列


\EX{Z = matrix(QQ, 2, 2, 0)} 零行列

\EX{D = matrix(QQ, 2, 2, 8)} 
%\BreakLineAndIndent
  対角成分は8, それ以外は0


\EX{E = block_matrix([[P,0],[1,R]])} とても柔軟な入力

\EX{II = identity_matrix(5)} $5\times5$単位行列
\BreakLineAndIndent
  \sagecommand{I} = $\sqrt{-1}$, 
  行列を代入して書き換えない様に注意


\EX{J = jordan_block(-2,3)} 
\BreakLineAndIndent
  $3\times 3$行列, 対角は$-2$, その一つ上は$1$

\EX{var('x y z'); K = matrix(SR, [[x,y+z],[0,x^2*z]])}  
\BreakLineAndIndent
  シンボリックな数式のなす環\sagecommand{SR}の元を成分とする行列.


\EX{L = matrix(ZZ, 20, 80, {(5,9):30, (15,77):-6})} 
\BreakLineAndIndent
  $20\times 80$, 2 つの要素だけ非零な行列, sparse
\begin{original}
\CAUTION{Row, column numbering begins at $0$}

\EX{A = matrix(ZZ, [[1,2],[3,4],[5,6]])} 
\BreakLineAndIndent
  $3\times 2$ over the integers

\EX{B = matrix(QQ, 2, [1,2,3,4,5,6])} 
\BreakLineAndIndent
  2 rows from a list, so $2\times 3$ over rationals

\EX{C = matrix(CDF, 2, 2, [[5*I, 4*I], [I, 6]])} 
\BreakLineAndIndent
  complex entries, 53-bit precision

\EX{Z = matrix(QQ, 2, 2, 0)} zero matrix

\EX{D = matrix(QQ, 2, 2, 8)} 
\BreakLineAndIndent
  diagonal entries all $8$, other entries zero

\EX{E = block_matrix([[P,0],[1,R]])}, very flexible input

\EX{II = identity_matrix(5)} $5\times5$ identity matrix 
\BreakLineAndIndent
  \sagecommand{I} = $\sqrt{-1}$, do not overwrite with matrix name

\EX{J = jordan_block(-2,3)} 
\BreakLineAndIndent
  $3\times 3$ matrix, $-2$ on diagonal, $1$'s on super-diagonal

\EX{var('x y z'); K = matrix(SR, [[x,y+z],[0,x^2*z]])}  
\BreakLineAndIndent
  symbolic expressions live in the ring \sagecommand{SR}

\EX{L = matrix(ZZ, 20, 80, {(5,9):30, (15,77):-6})} 
\BreakLineAndIndent
  $20\times 80$, two non-zero entries, sparse representation
\end{original}
%*********************************************
\sect[Matrix Multiplication]{行列の積}
\EX{u = vector(QQ, [1,2,3])},\quad\EX{v = vector(QQ, [1,2])}\\
\EX{A = matrix(QQ, [[1,2,3],[4,5,6]])}\\
\EX{B = matrix(QQ, [[1,2],[3,4]])}

\EX{u*A},\quad
\EX{A*v},\quad
\EX{B*A},\quad
\EX{B^6},\quad
\EX{B^(-3)} などと出来る.

\EX{B.iterates(v, 6)}で$vB^0, vB^1,\dots, vB^5$が出来る. 
\BreakLineAndIndent
  \sagecommand{rows = False}なら\sagecommand{v}は行列の冪の右にくる

\EX{f(x)=x^2+5*x+3}とすると\EX{f(B)}と出来る

\EX{B.exp()} 行列の指数関数, つまり$\sum_{k=0}^{\infty}\frac{1}{k!}B^k$
\begin{original}
\EX{u = vector(QQ, [1,2,3])},\quad\EX{v = vector(QQ, [1,2])}\\
\EX{A = matrix(QQ, [[1,2,3],[4,5,6]])}\\
\EX{B = matrix(QQ, [[1,2],[3,4]])}

\EX{u*A},\quad
\EX{A*v},\quad
\EX{B*A},\quad
\EX{B^6},\quad
\EX{B^(-3)} all possible

\EX{B.iterates(v, 6)}  produces $vB^0, vB^1,\dots, vB^5$ 
\BreakLineAndIndent
  \sagecommand{rows = False} moves \sagecommand{v} 
  to the right of matrix powers

\EX{f(x)=x^2+5*x+3} then \EX{f(B)} is possible

\EX{B.exp()} matrix exponential, i.e.\ $\sum_{k=0}^{\infty}\frac{1}{k!}B^k$
\end{original}
%*********************************************
\sect[Matrix Spaces]{行列の空間}
\EX{M = MatrixSpace(QQ, 3, 4)} $3\times 4$行列の$12$次元空間

\EX{A = M([1,2,3,4,5,6,7,8,9,10,11,12])} 
\BreakLineAndIndent
リストを\sagecommand{M}の元に変換.
\sagecommand{QQ}成分の$3\times 4$行列.

\EX{M.basis()}
\quad
\EX{M.dimension()}
\quad
\EX{M.zero_matrix()}
\begin{original}
\EX{M = MatrixSpace(QQ, 3, 4)} is space of $3\times 4$ matrices

\EX{A = M([1,2,3,4,5,6,7,8,9,10,11,12])} 
\BreakLineAndIndent
  coerce list to element of \sagecommand{M},  
  a $3\times 4$ matrix over \sagecommand{QQ}

\EX{M.basis()}
\quad
\EX{M.dimension()}
\quad
\EX{M.zero_matrix()}
\end{original}
%*********************************************
\sect[Matrix Operations]{行列の操作}
\EX{5*A+2*B} 線型結合\\
\EX{A.inverse()}, \EX{A^(-1)}, \EX{~A}, 非正則なら\sagecommand{ZeroDivisionError}\\
\EX{A.transpose()} 転置行列\\
\EX{A.conjugate()} 成分ごとの複素共役\\
\EX{A.conjugate_transpose()}\\
\EX{A.antitranspose()} 転置+順序の反転\\
\EX{A.adjoint()}  余因子行列\\
\EX{A.restrict(V)} 不変部分空間\sagecommand{V}への制限

\begin{original}
\EX{5*A+2*B} linear combination\\
\EX{A.inverse()}, \EX{A^(-1)}, \EX{~A}, singular is \sagecommand{ZeroDivisionError}\\
\EX{A.transpose()}\\
\EX{A.conjugate()} entry-by-entry complex conjugates\\
\EX{A.conjugate_transpose()}\\
\EX{A.antitranspose()} transpose + reverse orderings\\
\EX{A.adjoint()}  matrix of cofactors\\
\EX{A.restrict(V)} restriction to invariant subspace \sagecommand{V}
\end{original}
%*********************************************
\sect[Row Operations]{行基本変形}
行基本変形: (直接行列を書き換える)\\
\CAUTION{最初の行は$0$行目}\\
\EX{A.rescale_row(i,a)} \sagecommand{a*}(\sagecommand{i}行目)
 \quad(\sagecommand{i}行目を\sagecommand{a}倍)\\
\EX{A.add_multiple_of_row(i,j,a)} \sagecommand{a*}(\sagecommand{j}行目) + \sagecommand{i}行目\\
\EX{A.swap_rows(i,j)}
\sagecommand{j}行目と\sagecommand{i}行目の交換

列基本変形は, \sagecommand{row}$\rightarrow$\sagecommand{col}\\
\sagecommand{A}を書き換えたくない時は\EX{B=A.with_rescaled_row(i,a)}等
\begin{original}
Row Operations: (change matrix in place)\\
\CAUTION{first row is numbered 0}\\
\EX{A.rescale_row(i,a)} \sagecommand{a*}(row \sagecommand{i})\\
\EX{A.add_multiple_of_row(i,j,a)} \sagecommand{a*}(row \sagecommand{j}) + row \sagecommand{i}\\
\EX{A.swap_rows(i,j)}

Each has a column variant, \sagecommand{row}$\rightarrow$\sagecommand{col}\\
For a new matrix, use e.g.\ \EX{B = A.with_rescaled_row(i,a)}
\end{original}
%*********************************************
\sect[Echelon Form]{階段行列}
\EX{A.rref()},
\EX{A.echelon_form()},
\EX{A.echelonize()}\\
\NOTE{\sagecommand{rref()}では行列を商体で考える}\\
\EX{A = matrix(ZZ,[[4,2,1],[6,3,2]])}\\
\begin{tabular}{ll}
\EX{A.rref()} & \EX{A.echelon_form()}\\
$\left(\begin{array}{rrr}
2 & 1 & 0 \\
0 & 0 & 1
\end{array}\right)$
&
$\left(\begin{array}{rrr}
1 & \frac{1}{2} & 0 \\
0 & 0 & 1
\end{array}\right)$
\end{tabular}

\EX{A.pivots()} 列空間を生成している列の添字\\
\EX{A.pivot_rows()} 行空間を生成している行の添字
\begin{original}
\EX{A.rref()},
\EX{A.echelon_form()},
\EX{A.echelonize()}\\
\NOTE{\sagecommand{rref()} promotes matrix to fraction field}\\
\EX{A = matrix(ZZ,[[4,2,1],[6,3,2]])}\\
\begin{tabular}{ll}
\EX{A.rref()} & \EX{A.echelon_form()}\\
$\left(\begin{array}{rrr}
2 & 1 & 0 \\
0 & 0 & 1
\end{array}\right)$
&
$\left(\begin{array}{rrr}
1 & \frac{1}{2} & 0 \\
0 & 0 & 1
\end{array}\right)$
\end{tabular}

\EX{A.pivots()} indices of columns spanning column space\\
\EX{A.pivot_rows()} indices of rows spanning row space
\end{original}
%*********************************************
\sect[Pieces of Matrices]{小行列など}
\CAUTION{行も列も添字は$0$から}

\EX{A.nrows()}, \EX{A.ncols()}

\EX{A[i,j]} \sagecommand{i}行\sagecommand{j}列の成分

\EX{A[i]} Tupleとして\sagecommand{i}行目を返す. Tupleはimmutableなので,
\BreakLineAndIndent
  \CAUTION{OK: \sagecommand{A[2,3] = 8}, エラー: \sagecommand{A[2][3] = 8}}

\EX{A.row(i)} Sageのvectorとして\sagecommand{i}行目を返す\\
\EX{A.column(j)} Sageのvectorとして\sagecommand{j}列を返す

\EX{A.list()} 
single Python list を返す. (row-major order)

\EX{A.matrix_from_columns([8,2,8])}  
\BreakLineAndIndent
  リストにある列で新しい行列を作る. 列が重複しててもよい.\\
\EX{A.matrix_from_rows([2,5,1])} 
\BreakLineAndIndent
  リストにある行で新しい行列を作る. 未ソートでも可.\\
\EX{A.matrix_from_rows_and_columns([2,4,2],[3,1])} 
\BreakLineAndIndent
  行と列から新しい行列

\EX{A.rows()}  
  全ての行(tuplesのリスト)\\
\EX{A.columns()}  
  全ての列(tuples のリスト)

\EX{A.submatrix(i,j,nr,nc)} 
\BreakLineAndIndent
  \sagecommand{(i,j)}から始めて,
  \sagecommand{nr}行, \sagecommand{nc}列使った行列

\EX{A[2:4,1:7]}, \EX{A[0:8:2,3::-1]}
  Python風の部分リストの取得
\begin{original}
\CAUTION{row, column numbering begins at 0}

\EX{A.nrows()}, \EX{A.ncols()}

\EX{A[i,j]} entry in row \sagecommand{i} and column \sagecommand{j}

\EX{A[i]} row \sagecommand{i} as immutable Python tuple.  
Thus, \BreakLineAndIndent
  \CAUTION{OK: \sagecommand{A[2,3] = 8}, Error: \sagecommand{A[2][3] = 8}}

\EX{A.row(i)} returns row \sagecommand{i} as Sage vector\\
\EX{A.column(j)} returns column \sagecommand{j} as Sage vector

\EX{A.list()} returns single Python list, row-major order

\EX{A.matrix_from_columns([8,2,8])}  
\BreakLineAndIndent
  new matrix from columns in list, repeats OK\\
\EX{A.matrix_from_rows([2,5,1])} 
\BreakLineAndIndent
  new matrix from rows in list, out-of-order OK\\
\EX{A.matrix_from_rows_and_columns([2,4,2],[3,1])} 
\BreakLineAndIndent
  common to the rows and the columns

\EX{A.rows()}  all rows as a list of tuples\\
\EX{A.columns()}  all columns as a list of tuples

\EX{A.submatrix(i,j,nr,nc)} 
\BreakLineAndIndent
  start at entry \sagecommand{(i,j)}, 
  use \sagecommand{nr} rows, 
  \sagecommand{nc} cols

\EX{A[2:4,1:7]}, \EX{A[0:8:2,3::-1]} Python-style list slicing 
\end{original}
%*********************************************
\sect[Combining Matrices]{行列の組合せ}

\EX{A.augment(B)}  
\sagecommand{A}を左に, \sagecommand{B}を右に置いてできる行列\\
\EX{A.stack(B)}  
\sagecommand{A}を上に, \sagecommand{B}を下に配置; 
\sagecommand{B}はvectorでも可\\
\EX{A.block_sum(B)}  
\sagecommand{A}が左上\sagecommand{B}が右下のブロック対角行列\\
\EX{A.tensor_product(B)} 
\sagecommand{A}に従って
\sagecommand{B}の定数倍を配置した行列

\begin{original}
\EX{A.augment(B)}  
\sagecommand{A} in first columns, matrix \sagecommand{B} to the right\\
\EX{A.stack(B)}  
\sagecommand{A} in top rows, \sagecommand{B} below; 
\sagecommand{B} can be a vector\\
\EX{A.block_sum(B)}  
Diagonal, \sagecommand{A} upper left, \sagecommand{B} lower right\\
\EX{A.tensor_product(B)} 
Multiples of \sagecommand{B}, arranged as in \sagecommand{A}
\end{original}
%*********************************************
\sect[Scalar Functions on Matrices]{行列のスカラー関数}
\EX{A.rank()},\quad\EX{A.right_nullity()}\\
\EX{A.left_nullity() == A.nullity()}\\
\EX{A.determinant() == A.det()}\\
\EX{A.permanent()},\quad\EX{A.trace()}\\
\EX{A.norm() == A.norm(2)} ユークリッドノルム\\
\EX{A.norm(1)} 列和の最大\\
\EX{A.norm(Infinity)} 行和の最大\\
\EX{A.norm('frob')} フロベニウスノルム
\begin{original}
\EX{A.rank()},\quad\EX{A.right_nullity()}\\
\EX{A.left_nullity() == A.nullity()}\\
\EX{A.determinant() == A.det()}\\
\EX{A.permanent()},\quad\EX{A.trace()}\\
\EX{A.norm() == A.norm(2)} Euclidean norm\\
\EX{A.norm(1)} largest column sum\\
\EX{A.norm(Infinity)} largest row sum\\
\EX{A.norm('frob')} Frobenius norm
\end{original}
%*********************************************
\sect[Matrix Properties]{行列の情報}
\EX{.is_zero()};
\EX{.is_symmetric()};
\EX{.is_hermitian()};\\
%
\EX{.is_square()};
\EX{.is_orthogonal()};
\EX{.is_unitary()};\\
%
\EX{.is_scalar()};
\EX{.is_singular()};
\EX{.is_invertible()};\\
%
\EX{.is_one()};
\EX{.is_nilpotent()};
\EX{.is_diagonalizable()};
%\\
\EX{.is_unit()};
\EX{.is_skew_symmetric()};
\EX{.is_singular()};
\EX{.is_idempotent()};
\EX{.is_bistochastic()}
\begin{original}
% Edit (plus/minus) to make columns fit first page
%
\EX{.is_zero()};
\EX{.is_symmetric()};
\EX{.is_hermitian()};\\
%
\EX{.is_square()};
\EX{.is_orthogonal()};
\EX{.is_unitary()};\\
%
\EX{.is_scalar()};
\EX{.is_singular()};
\EX{.is_invertible()};\\
%
\EX{.is_one()};
\EX{.is_nilpotent()};
\EX{.is_diagonalizable()};
%\\
\EX{.is_unit()};
\EX{.is_skew_symmetric()};
\EX{.is_singular()};
\EX{.is_idempotent()};
\EX{.is_bistochastic()}
\end{original}
%*********************************************
\sect[Eigenvalues and Eigenvectors]{固有値と固有ベクトル}
\NOTE{
環(\sagecommand{QQ}), \sagecommand{RDF}, \sagecommand{CDF})の違いによる振る舞いの違いに注意}

\EX{A.charpoly('t')}  
変数を何も指定しなければ\sagecommand{x}が使われる
\BreakLineAndIndent
  \EX{A.characteristic_polynomial() == A.charpoly()}

\EX{A.fcp('t')}  
因数分解された特性多項式

\EX{A.minpoly()}  最小多項式
\BreakLineAndIndent
  \EX{A.minimal_polynomial() == A.minpoly()}

\EX{A.eigenvalues()} 固有値の(重複有りの未ソートな)リスト

\EX{A.eigenvectors_left()} ベクトルは左, \sagecommand{_right}も有り
\BreakLineAndIndent
  固有値毎に次のtupleを返す: 
\BreakLineAndDoubleIndent
    \sagecommand{e}: 固有値; 
\BreakLineAndDoubleIndent
    \sagecommand{V}: 固有空間の基底をなすベクトルのリスト; 
\BreakLineAndDoubleIndent
    \sagecommand{n}: 重複度 

\EX{A.eigenmatrix_right()} ベクトルは右, \sagecommand{_left}も有り
\BreakLineAndIndent
  次のペアを返す:\quad 
\BreakLineAndDoubleIndent
    \sagecommand{D}: 固有値が対角にある対角行列
\BreakLineAndDoubleIndent
    \sagecommand{P}: 各列が固有ベクトルの行列(leftなら行)
\BreakLineAndIndent[\skipin\skipin\phantom{P:}]
                     もし対角化可能でなければ, 0 ベクトルが列に現れる

固有空間: ``部分空間の生成(Constructing Subspaces)''を見よ
\begin{original}
\NOTE{Contrast behavior for exact rings (\sagecommand{QQ}) vs.\ \sagecommand{RDF}, \sagecommand{CDF}}

\EX{A.charpoly('t')}  no variable specified defaults to \sagecommand{x} 
\BreakLineAndIndent
  \EX{A.characteristic_polynomial() == A.charpoly()}

\EX{A.fcp('t')}  factored characteristic polynomial

\EX{A.minpoly()}  the minimum polynomial  
\BreakLineAndIndent
  \EX{A.minimal_polynomial() == A.minpoly()}

\EX{A.eigenvalues()} unsorted list, with mutiplicities

\EX{A.eigenvectors_left()} vectors on left, \sagecommand{_right} too 
\BreakLineAndIndent
  Returns, per eigenvalue, a triple: 
\BreakLineAndDoubleIndent
    \sagecommand{e}: eigenvalue; 
\BreakLineAndDoubleIndent
    \sagecommand{V}: list of eigenspace basis vectors; 
\BreakLineAndDoubleIndent
    \sagecommand{n}: multiplicity 

\EX{A.eigenmatrix_right()} vectors on right, \sagecommand{_left} too
\BreakLineAndIndent
  Returns pair:\quad 
\BreakLineAndDoubleIndent
    \sagecommand{D}: diagonal matrix with eigenvalues 
\BreakLineAndDoubleIndent
    \sagecommand{P}: eigenvectors as columns (rows for left version) 
\BreakLineAndIndent[\skipin\skipin\phantom{P:}]
                     with zero columns if matrix not diagonalizable

Eigenspaces: see ``Constructing Subspaces''
\end{original}
%*********************************************
\sect[Decompositions]{分解}
\NOTE{どの環の元かによって使えないものも有る.\\ 
数値計算には\sagecommand{RDF}か\sagecommand{CDF}を,
厳密計算には\sagecommand{QQ}を使う.\\
 ``ユニタリ行列''は実数の場合は``直交行列''.}

\EX{A.jordan_form(transformation=True)} 
\BreakLineAndIndent
次の行列のペアを返す: \sagecommand{A == P^(-1)*J*P} 
\BreakLineAndDoubleIndent
  \sagecommand{J}: 固有値に対するジョルダンブロックの行列
\BreakLineAndDoubleIndent
  \sagecommand{P}: 正則行列

\EX{A.smith_form()} 
\BreakLineAndIndent
次の行列の3つ組を返す: \sagecommand{D == U*A*V} 
\BreakLineAndDoubleIndent
  \sagecommand{D}: 単因子の対角行列
\BreakLineAndDoubleIndent
  \sagecommand{U, V}: 固有値1 の行列

\EX{A.LU()} 
\BreakLineAndIndent
次の行列の3つ組を返す: \sagecommand{P*A == L*U}  
\BreakLineAndDoubleIndent
  \sagecommand{P}: 置換行列
\BreakLineAndDoubleIndent
  \sagecommand{L}: 下三角行列
\BreakLineAndDoubleIndent
  \sagecommand{U}: 上三角行列

\EX{A.QR()} 
\BreakLineAndIndent
次の行列のペアを返す: \sagecommand{A == Q*R} 
\BreakLineAndDoubleIndent
  \sagecommand{Q}: ユニタリ行列
\BreakLineAndDoubleIndent
  \quad\sagecommand{R}: 上三角行列

\EX{A.SVD()} 
\BreakLineAndIndent
次の3つ組を返す: \sagecommand{A == U*S*(V-conj-transpose)} 
\BreakLineAndDoubleIndent
  \sagecommand{U}: ユニタリ行列  
\BreakLineAndDoubleIndent
  \sagecommand{S}: 非対角は$0$, 対角は非負, \sagecommand{A}と同じ次元
\BreakLineAndDoubleIndent
  \sagecommand{V}: ユニタリ行列

\EX{A.schur()} 
\BreakLineAndIndent
次の行列のペアを返す: \sagecommand{A == Q*T*(Q-conj-transpose)}  
\BreakLineAndDoubleIndent
  \sagecommand{Q}: ユニタリ行列
\BreakLineAndDoubleIndent
  \sagecommand{T}: 上三角行列, $2\times2$対角ブロックかも

\EX{A.rational_form()}, いわゆるフロベニウス形式

\EX{A.symplectic_form()}
\EX{A.hessenberg_form()}
\EX{A.cholesky()} (needs work)
%
\begin{original}
\NOTE{availability depends on base ring of matrix,\\ 
try \sagecommand{RDF} or \sagecommand{CDF} for numerical work,
\sagecommand{QQ} for exact.\\ ``unitary'' is ``orthogonal'' in real case}

\EX{A.jordan_form(transformation=True)} 
\BreakLineAndIndent
  returns a pair of matrices with: \sagecommand{A == P^(-1)*J*P} 
\BreakLineAndDoubleIndent
  \sagecommand{J}: matrix of Jordan blocks for eigenvalues 
\BreakLineAndDoubleIndent
  \sagecommand{P}: nonsingular matrix

\EX{A.smith_form()} triple with: \sagecommand{D == U*A*V} 
\BreakLineAndIndent
  \sagecommand{D}: elementary divisors on diagonal          
\BreakLineAndIndent
  \sagecommand{U, V}: with unit determinant

\EX{A.LU()} triple with: \sagecommand{P*A == L*U}  
\BreakLineAndIndent
  \sagecommand{P}: a permutation matrix       
\BreakLineAndIndent
  \sagecommand{L}: lower triangular matrix,\quad\sagecommand{U}: upper triangular matrix

\EX{A.QR()} pair with: \sagecommand{A == Q*R} 
\BreakLineAndIndent
  \sagecommand{Q}: a unitary matrix,
  \quad\sagecommand{R}: upper triangular matrix

\EX{A.SVD()} triple with: \sagecommand{A == U*S*(V-conj-transpose)} 
\BreakLineAndIndent
  \sagecommand{U}: a unitary matrix  
\BreakLineAndIndent
  \sagecommand{S}: zero off the diagonal, dimensions same as \sagecommand{A} 
\BreakLineAndIndent
  \sagecommand{V}: a unitary matrix

\EX{A.schur()} pair with: \sagecommand{A == Q*T*(Q-conj-transpose)}  
\BreakLineAndIndent
  \sagecommand{Q}: a unitary matrix  
\BreakLineAndIndent
  \sagecommand{T}: upper-triangular matrix, maybe $2\times2$ diagonal blocks

\EX{A.rational_form()}, aka Frobenius form

\EX{A.symplectic_form()}
\EX{A.hessenberg_form()}
\EX{A.cholesky()} (needs work)
\end{original}
%*********************************************
\sect[Solutions to Systems]{方程式系の解}
\EX{A.solve_right(B)} \sagecommand{_left}も有り
\BreakLineAndIndent
  \sagecommand{A*X = B}の解, 
  ただし\sagecommand{X}はベクトルまたは行列

\EX{A = matrix(QQ, [[1,2],[3,4]])}\\
\EX{b = vector(QQ, [3,4])}, なら \EX{A\b}は解\EX{(-2, 5/2)}
\begin{original}
\EX{A.solve_right(B)} \sagecommand{_left} too
\BreakLineAndIndent
  is solution to \sagecommand{A*X = B}, 
  where \sagecommand{X} is a vector {\bf or} matrix

\EX{A = matrix(QQ, [[1,2],[3,4]])}\\
\EX{b = vector(QQ, [3,4])}, then \EX{A\b} is solution \EX{(-2, 5/2)}
\end{original}
%*********************************************
\sect[Vector Spaces]{ベクトル空間}
\EX{VectorSpace(QQ, 4)}  
4次元, 係数体は有理数体

\EX{VectorSpace(RR, 4)}
  ``係数体''は53-bit精度の実数

\EX{VectorSpace(RealField(200), 4)} 
%\BreakLineAndIndent
  ``係数体''は200-bit精度%の実数


\EX{CC^4} 
4次元, 53-bit精度の複素数

\EX{Y = VectorSpace(GF(7), 4)}  有限体
\BreakLineAndIndent
  \EX{Y.list()}は$7^4=2401$個のベクトル
\begin{original}
\EX{VectorSpace(QQ, 4)}  dimension 4, rationals as field

\EX{VectorSpace(RR, 4)}  ``field'' is 53-bit precision reals

\EX{VectorSpace(RealField(200), 4)} 
\BreakLineAndIndent
  ``field'' has 200 bit precision

\EX{CC^4} 4-dimensional, 53-bit precision complexes

\EX{Y = VectorSpace(GF(7), 4)}  finite 
\BreakLineAndIndent
  \EX{Y.list()} has $7^4=2401$ vectors
\end{original}
%*********************************************
\sect[Vector Space Properties]{ベクトル空間の性質}
\EX{V.dimension()} \quad
\EX{V.basis()}     \quad
\EX{V.echelonized_basis()}

\EX{V.has_user_basis()} 
標準基底以外の基底を使っている?

\EX{V.is_subspace(W)} 
\sagecommand{W}が\sagecommand{V}の部分空間なら\sagecommand{True}

\EX{V.is_full()} 
(加群として) 階数が次元と等しいか?

\EX{Y = GF(7)^4},\quad\EX{T = Y.subspaces(2)}  
\BreakLineAndIndent
   \sagecommand{T}は\sagecommand{Y}の二次元部分空間に対するa generator object.
%\BreakLineAndIndent
   \sagecommand{[U for U in T]}は\sagecommand{Y}の(2850個の)二次元部分空間のリスト.
%\BreakLineAndIndent
  全ての部分空間に渡ってステップ実行するには\sagecommand{T.next()}を使っ
 てもよい.
\begin{original}
\EX{V.dimension()} \quad
\EX{V.basis()}     \quad
\EX{V.echelonized_basis()}

\EX{V.has_user_basis()} 
with non-canonical basis?

\EX{V.is_subspace(W)} 
\sagecommand{True} if \sagecommand{W} is a subspace of \sagecommand{V}

\EX{V.is_full()} 
rank equals degree (as module)?

\EX{Y = GF(7)^4},\quad\EX{T = Y.subspaces(2)}  
\BreakLineAndIndent
   \sagecommand{T} is 
   a generator object for 2-D subspaces of \sagecommand{Y}
\BreakLineAndIndent
   \sagecommand{[U for U in T]} is 
   list of 2850 2-D subspaces of \sagecommand{Y},
\BreakLineAndIndent
   or use \sagecommand{T.next()} to step through subspaces
\end{original}
%*********************************************
\sect[Constructing Subspaces]{部分空間の生成}
\EX{span([v1,v2,v3], QQ)} 
環\sagecommand{QQ}上\sagecommand{v1}, \sagecommand{v2}, \sagecommand{v3}
で生成される空間

\vspace*{0.7ex}
行列\sagecommand{A}に対し, 
返されるのは
\BreakLineAndIndent
  基礎環が体ならベクトル空間
\BreakLineAndIndent
  基礎環が体でないなら加群\\
\EX{A.left_kernel() == A.kernel()} \sagecommand{right_}も有り\\
\EX{A.row_space() == A.row_module()}\\
\EX{A.column_space() == A.column_module()}\\
\EX{A.eigenspaces_right()} ベクトルは右, \sagecommand{_left}も有り
\BreakLineAndIndent
    固有値と右固有空間の組\\
\EX{A.eigenspaces_right(format='galois')}
\BreakLineAndIndent
    固有多項式の既約因子毎に一つの固有空間.

\vspace*{0.7ex}
もし\sagecommand{V}と\sagecommand{W}が部分空間なら\\
\EX{V.quotient(W)} 
 \sagecommand{V}の\sagecommand{W}による商空間\\
\EX{V.intersection(W)} 
 \sagecommand{V}と\sagecommand{W}の共通部分\\
\EX{V.direct_sum(W)} 
 \sagecommand{V}と\sagecommand{W}の直和\\
\EX{V.subspace([v1,v2,v3])} 
リストのベクトルによる部分空間
\begin{original}
\EX{span([v1,v2,v3], QQ)} span of list of vectors over ring

\vspace*{0.7ex}
For a matrix \sagecommand{A}, objects returned are 
\BreakLineAndIndent
    vector spaces when base ring is a field 
\BreakLineAndIndent
    modules when base ring is just a ring  \\
\EX{A.left_kernel() == A.kernel()} \sagecommand{right_} too\\
\EX{A.row_space() == A.row_module()}\\
\EX{A.column_space() == A.column_module()}\\
\EX{A.eigenspaces_right()} vectors on right, \sagecommand{_left} too
\BreakLineAndIndent
    Pairs: eigenvalues with their right eigenspaces\\
\EX{A.eigenspaces_right(format='galois')}
\BreakLineAndIndent
    One eigenspace per irreducible factor of char poly

\vspace*{0.7ex}
If \sagecommand{V} and \sagecommand{W} are subspaces\\
\EX{V.quotient(W)} quotient of \sagecommand{V} by subspace \sagecommand{W}\\
\EX{V.intersection(W)} intersection of \sagecommand{V} and \sagecommand{W}\\
\EX{V.direct_sum(W)} direct sum of \sagecommand{V} and \sagecommand{W}\\
\EX{V.subspace([v1,v2,v3])} specify basis vectors in a list
\end{original}
%*********************************************
\sect[Dense versus Sparse]{DenseかSparseか}
\NOTE{アルゴリズムは表現の仕方に依存するかもしれない}

ベクトルと行列にはふたつの表現がある
\BreakLineAndIndent
   Dense: リスト(ベクトル), リストのリスト(行列)
\BreakLineAndIndent
   Sparse: Python dictionaries

\EX{.is_dense()}, \EX{.is_sparse()}  チェックする\\
\EX{A.sparse_matrix()} 
\sagecommand{A}と等しいsparse表現の行列を返す\\
\EX{A.dense_rows()} 
\sagecommand{A}行ベクトルをdense表現のベクトルとして返す\\
\sagecommand{sparse}(=\sagecommand{True}/\sagecommand{False})
というキーワードを持つコマンドも有.
\begin{original}
\NOTE{Algorithms may depend on representation}

Vectors and matrices have two representations 
\BreakLineAndIndent
   Dense: lists, and lists of lists 
\BreakLineAndIndent
   Sparse: Python dictionaries

\EX{.is_dense()}, \EX{.is_sparse()}  to check\\
\EX{A.sparse_matrix()} returns sparse version of \sagecommand{A}\\
\EX{A.dense_rows()} returns dense row vectors of \sagecommand{A}\\
Some commands have  boolean \sagecommand{sparse} keyword
\end{original}
%*********************************************
\sect{Rings}
\NOTE{多くのアルゴリズムが基礎環が何かに依存している}

\EXVAR{<object>}\EX{.base_ring(R)} ベクトル, 行列\dots に対し
\BreakLineAndIndent
   使用する環を指定する.


\EXVAR{<object>}\EX{.change_ring(R)} ベクトル, 行列\dots に対し
\BreakLineAndIndent
   使用する環(体)を\sagecommand{R}に変更する.


\EX{R.is_ring()},\quad\EX{R.is_field()},\quad\EX{R.is_exact()}

おもな環と体\BreakLineAndIndent
  \EX{ZZ}\quad 整数 $\ZZ$, 環 \BreakLineAndIndent
  \EX{QQ}\quad 有理数 $\QQ$, 体 \BreakLineAndIndent
  \EX{AA}, \EX{QQbar}\quad 代数的数のなす体$\overline{\QQ}$, 厳密(exact) \BreakLineAndIndent
  \EX{RDF}\quad 倍精度実数の体, 近似(inexact) \BreakLineAndIndent
  \EX{CDF}\quad 倍精度複素数の体, 近似(inexact) \BreakLineAndIndent
  \EX{RR}\quad 53-bit精度実数, 近似(inexact), \EX{RDF}とは異なる \BreakLineAndIndent
  \EX{RealField(400)}\quad 400-bit精度実数, 近似(inexact)  \BreakLineAndIndent
  \EX{CC}, \EX{ComplexField(400)}\quad 複素数も有り \BreakLineAndIndent
  \EX{RIF}\quad 実区間演算, 体 \BreakLineAndIndent
  \EX{GF(2)}\quad mod 2, 体, specialized implementations $\FF_2=\ZZ/2\ZZ$\BreakLineAndIndent
  \EX{GF(p) == FiniteField(p)}\quad \sagecommand{p}は素数, 体$\FF_p=\ZZ/p\ZZ$\BreakLineAndIndent
  \EX{Integers(6)}\quad 6を法とした整数, 環$\ZZ/6\ZZ$ \BreakLineAndIndent
  \EX{CyclotomicField(7)}\quad 
$\QQ$に1の7乗根を添加した体$\QQ(\zeta_7)$
 \BreakLineAndIndent
  \EX{QuadraticField(-5, 'x')}\quad 
$\QQ$に\sagecommand{x}$=\sqrt{-5}$を添加した体 \BreakLineAndIndent
  \EX{SR}\quad symbolic expressionのなす環.
\begin{original}
\NOTE{Many algorithms depend on the base ring}

\EXVAR{<object>}\EX{.base_ring(R)} for vectors, matrices,\dots 
\BreakLineAndIndent
   to determine the ring in use

\EXVAR{<object>}\EX{.change_ring(R)} for vectors, matrices,\dots
\BreakLineAndIndent
   to change to the ring (or field), \sagecommand{R}

\EX{R.is_ring()},\quad\EX{R.is_field()},\quad\EX{R.is_exact()}

Some common Sage rings and fields \BreakLineAndIndent
  \EX{ZZ}\quad integers, ring \BreakLineAndIndent
  \EX{QQ}\quad rationals, field \BreakLineAndIndent
  \EX{AA}, \EX{QQbar}\quad algebraic number fields, exact \BreakLineAndIndent
  \EX{RDF}\quad real double field, inexact \BreakLineAndIndent
  \EX{CDF}\quad complex double field, inexact \BreakLineAndIndent
  \EX{RR}\quad 53-bit reals, inexact, not same as \EX{RDF} \BreakLineAndIndent
  \EX{RealField(400)}\quad 400-bit reals, inexact  \BreakLineAndIndent
  \EX{CC}, \EX{ComplexField(400)}\quad complexes, too \BreakLineAndIndent
  \EX{RIF}\quad real interval field \BreakLineAndIndent
  \EX{GF(2)}\quad mod 2, field, specialized implementations \BreakLineAndIndent
  \EX{GF(p) == FiniteField(p)}\quad \sagecommand{p} prime, field \BreakLineAndIndent
  \EX{Integers(6)}\quad integers mod 6, ring only  \BreakLineAndIndent
  \EX{CyclotomicField(7)}\quad rationals with 7$^{\rm th}$ root of unity \BreakLineAndIndent
  \EX{QuadraticField(-5, 'x')}\quad rationals with \sagecommand{x}$=\sqrt{-5}$ \BreakLineAndIndent
  \EX{SR}\quad ring of symbolic expressions
\end{original}
%*********************************************
\sect[Vector Spaces versus Modules]{ベクトル空間vs加群}
加群とは(体では無く) 環上のベクトル空間
``みたいな'' もの.
先に述べたコマンド多くは加群にも使うことが出来る.
いくつかの
``ベクトル''は実際に加群の元.
\begin{original}
Module ``is'' a vector space over a ring, rather than a field.
Many commands above apply to modules.
Some ``vectors'' are really module elements.
\end{original}
%*********************************************
\sect[More Help]{もっと助けて}
コマンドの一部を書いて``tab-補完''\\
\EXVAR{<object>}\EX{.}を書いて``tab-補完''で関連するコマンドを表示\\
\EXVAR{<command>}\EX{?}でコマンドの説明と例\\
\EXVAR{<command>}\EX{??}でソースコードを表示
\begin{original}
``tab-completion'' on partial commands\\
``tab-completion'' on \EXVAR{<object>}\EX{.} for all relevant methods\\
\EXVAR{<command>}\EX{?} for summary and examples\\
\EXVAR{<command>}\EX{??} for complete source code
\end{original}
\end{multicols*}

\end{document}
