ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 14 Sep 2019 17:33:58 +0200Computation of a simultaneous block-diagonalizationhttps://ask.sagemath.org/question/47916/computation-of-a-simultaneous-block-diagonalization/Let $n$ be a positive integer and consider of finite set $S \subset M_n(\mathbb{C})$ such that $S^* = S$ (i.e. if $M \in S$ then $M^* \in S$). The algebra generated by $S$ is a finite dimensional $*$-algebra over $\mathbb{C}$, so is isomorphic to a direct sum of matrix algebras, i.e. there are $n_1 \le n_2 \le \dots \le n_r$ such that:
$$\langle S \rangle \simeq \bigoplus_{i=1}^r M_{n_i}(\mathbb{C})$$
I know how to get $\langle S \rangle$ by using `FiniteDimensionalAlgebra(CC,[M for M in S])`.
**Question**: How to compute with SageMath the change of basis $P$ such that for all $M \in S$, we have $P^{-1}MP$ block-diagonal as for the above decomposition?
*Remark*: When the matrices commute over each other, it is called a *simultaneous diagonalization*, and I know how to compute it using `jordan_form(transformation=True)` several times.
In some sense, what I am looking for in general is how to compute a *simultaneous block-diagonalization*Sébastien PalcouxSat, 14 Sep 2019 17:33:58 +0200https://ask.sagemath.org/question/47916/Given a matrix $M$ how to form the following matrix $N$ from $M$.https://ask.sagemath.org/question/47642/given-a-matrix-m-how-to-form-the-following-matrix-n-from-m/> Given a matrix $M$ how to form the following matrix $N$ from $M$.
Suppose $M=$\begin{bmatrix} 0 &3 \\ 2 &0 \end{bmatrix}
Here $M$ is a $2\times 2$ matrix with 1st row $[0,3]$ and 2nd row $[2,0]$.
We need to form $N$ such that
$N=$ \begin{bmatrix} 3& 3\\ 2&2\end{bmatrix}
Here $N$ is a $2\times 2$ matrix with 1st row $[3,3]$ and 2nd row $[2,2]$.
Thus $N$ is formed from $M$ by just adding all the off the diagonal elements of $M$ in a given row to the diagonal element
So the diagonal element of $N$ is the sum of all the remaining entries in a given row of $M$ whereas the rest of the elements of $N$ are the same as $M$.
So the elements of $N$ are obtained from $M$ in the following way :
$a_{11}=0+3=3, a_{12}=3,a_{21}=2,a_{22}=2+0=2$
How to code it?
Please help.CaptchaWed, 28 Aug 2019 13:40:55 +0200https://ask.sagemath.org/question/47642/Concatenate two sparse matrices over a Polynomial Ringhttps://ask.sagemath.org/question/47205/concatenate-two-sparse-matrices-over-a-polynomial-ring/ Hi all,
I am wondering if there is a way to concatenate two sparse matrices over a polynomial ring. Here is a toy example that I am testing with:
S.<x,y> = PolynomialRing(QQ,2)
udict = {(0,0):1, (0,1):x, (1,1):y}
vdict = {(0,0):2*x,(1,0):y}
U = matrix(4,4,ud,sparse=True)
V = matrix(4,2,vd,sparse=True)
I would like to make a larger matrix that is $4 \times 6$, that has the block form $[U|V]$. I attempted to use the block_matrix command, but it said that the given number of rows and columns were incompatible with the number of submatrices.
In Python, for a sparse matrix (csr_matrix or coo_matrix), there is the command hstack from scipy.sparse. Is there a similar command where I can concatenate a list of these sparse matrices? This would be ideal for my general problem.
Thank you for your time!BarkThu, 18 Jul 2019 14:00:49 +0200https://ask.sagemath.org/question/47205/Map a matrix to a block matrixhttps://ask.sagemath.org/question/41974/map-a-matrix-to-a-block-matrix/ Hello,
I have a function that maps an element $x$ into a $1\times n$ matrix, say for example $[x,x,x]$. I would like to map this function to a matrix and consider the resulting matrix as a "block matrix". E.g: change matrix([[1,2],[3,4]]) into matrix([[1,1,1,2,2,2],[3,3,3,4,4,4]]).
For now, I use a trick that basically converts back the matrix to a a list using something like:
block_matrix([[f(elt) for elt in row] for row in M.rows()])
but it looks quite dirty so I would like to know if there are some better way to proceed.
Thank you!tobiasBoraWed, 11 Apr 2018 00:15:48 +0200https://ask.sagemath.org/question/41974/Multiplying matrices with different parentshttps://ask.sagemath.org/question/41642/multiplying-matrices-with-different-parents/ I am trying to multiple a symbolic 1x1 matrix with one element in it, by a square matrix over a finite field. for example
[-9*x0^2 - 11*x0*x1 - 5*x1^2 - 11*x0*x2 - 4*x1*x2 + 7*x2^2 + 13*x1*x3 + 8*x2*x3 + 4*x3^2 - 6*x0*x4 - 4*x1*x4 - 15*x2*x4 + 9*x0*x5 - 8*x1*x5 - 5*x2*x5 - 3*x3*x5]
to be multiplied with them matrix
[18 23 14 1 6 21]
[24 3 3 0 2 0]
[17 25 2 16 23 8]
[ 8 21 16 5 1 9]
[14 28 8 17 12 12]
[ 6 24 18 19 3 1]
however when i try this i get the following error:
TypeError: unsupported operand parent(s) for *: 'Full MatrixSpace of 1 by 1 dense matrices over Multivariate Polynomial Ring in x0, x1, x2, x3, x4, x5 over Finite Field of size 31' and 'Full MatrixSpace of 6 by 6 dense matrices over Finite Field of size 31'
Is there a way to do this? DalvirMon, 19 Mar 2018 19:00:57 +0100https://ask.sagemath.org/question/41642/How can we make the AES S-box using Lagrange interpolation?https://ask.sagemath.org/question/40008/how-can-we-make-the-aes-s-box-using-lagrange-interpolation/I found the Sage code for the AES S-box online. It is given below.
However, I do not know how to find the coefficients of ***a*** to ***h*** using Lagrange interpolation. They seem to appear from nowhere, but I am told they are the result of *Lagrange interpolation*. I only know how to apply Lagrange interpolation if I have a function and some given points. But it seems there are no given points.
Can anyone help? An example of how to use Lagrange interpolation in Sage for just one or two of these polynomials, say $a =x^2+1$, and $b = x^3+1$ would be very helpful.
R = PolynomialRing(GF(2),'x',1)
x = R.gen()
m = x^8 + x^4 + x^3 + x + 1
v = x^6 + x^5 + x + 1
y = x^7 + x^4 + x^2 + 1
a = x^2 + 1
b = x^3 + 1
c = x^7 + x^6 + x^5 + x^4 + x^3 + 1
d = x^5 + x^2 + 1
e = x^7 + x^6 + x^5 + x^4 + x^2
f = 1
g = x^7 + x^5 + x^4 + x^2 + 1
h = x^7 + x^3 + x^2 + x + 1
s = a*(y^254) + b*(y^253) + c*(y^251) + d*(y^247) + e*(y^239) + f*(y^223) + g*(y^191) + h*(y^127) + v
print (s % m)Redbook1Fri, 08 Dec 2017 10:27:20 +0100https://ask.sagemath.org/question/40008/Partition of a given matrix into block matrix formhttps://ask.sagemath.org/question/39556/partition-of-a-given-matrix-into-block-matrix-form/Q: Suppose B= block_matrix([ [P, Q], [R, S] ]) be a given matrix. Now if I type B[0,0], sage gives me the very first element of the matrix P, but I actually need the matrix P. How to get this one?
My actual problem is as follows.
Q: I have a 12X12 matrix A, I want to partition it into 3X3 block matrix. Then I need another 12x12 matrix (partitioned into 3x3 block) where (i,j)th block is the sum of (i,j)th block and (j,i)th block of the given matrix A.
Any suggestion will be highly appreciated. Thank you in advanced.Deepak SarmaWed, 15 Nov 2017 08:09:16 +0100https://ask.sagemath.org/question/39556/