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.Tue, 08 Feb 2022 19:47:38 +0100How to construct a matrix space ?https://ask.sagemath.org/question/60999/how-to-construct-a-matrix-space/I know we can create a matrix space using "MatrixSpace" but I am looking to create a specific space. I tried :
M = MatrixSpace(ZZ,4)
B = M.basis()
sub = [B[0,0],B[1,3],B[2,2],B[3,1]]
SubM = M.submodule(sub)
SubM.basis()
The program show me : `Finite family {0: B[0], 1: B[1], 2: B[2], 3: B[3]}`
And when I take a random element of SubM( with `SubM.random_element()`), it tells me it isn't in M.
I thought the problem came from my generator so I tried with :
`sub = [matrix(4,4,{(0,0):1}),matrix(4,4,{(1,3):1}),matrix(4,4,{(2,2):1}),matrix(4,4,{(3,1):1})] `
But I have the same result.
Do you know what I am doing wrong ?
I also need to do a XOR between matrix space, do you think it is possible ? How ?
Thanks you for your time :D
Mon, 07 Feb 2022 18:10:42 +0100https://ask.sagemath.org/question/60999/how-to-construct-a-matrix-space/Comment by IHaveNoIdea for <p>I know we can create a matrix space using "MatrixSpace" but I am looking to create a specific space. I tried :</p>
<pre><code>M = MatrixSpace(ZZ,4)
B = M.basis()
sub = [B[0,0],B[1,3],B[2,2],B[3,1]]
SubM = M.submodule(sub)
SubM.basis()
</code></pre>
<p>The program show me : <code>Finite family {0: B[0], 1: B[1], 2: B[2], 3: B[3]}</code></p>
<p>And when I take a random element of SubM( with <code>SubM.random_element()</code>), it tells me it isn't in M.</p>
<p>I thought the problem came from my generator so I tried with : </p>
<p><code>sub = [matrix(4,4,{(0,0):1}),matrix(4,4,{(1,3):1}),matrix(4,4,{(2,2):1}),matrix(4,4,{(3,1):1})]</code></p>
<p>But I have the same result.
Do you know what I am doing wrong ?</p>
<p>I also need to do a XOR between matrix space, do you think it is possible ? How ?</p>
<p>Thanks you for your time :D</p>
https://ask.sagemath.org/question/60999/how-to-construct-a-matrix-space/?comment=61016#post-id-61016it is not really explained but I guess that it is a matrix space which have as element the xor of elements of 2 matrix spaces.Tue, 08 Feb 2022 18:05:40 +0100https://ask.sagemath.org/question/60999/how-to-construct-a-matrix-space/?comment=61016#post-id-61016Comment by Max Alekseyev for <p>I know we can create a matrix space using "MatrixSpace" but I am looking to create a specific space. I tried :</p>
<pre><code>M = MatrixSpace(ZZ,4)
B = M.basis()
sub = [B[0,0],B[1,3],B[2,2],B[3,1]]
SubM = M.submodule(sub)
SubM.basis()
</code></pre>
<p>The program show me : <code>Finite family {0: B[0], 1: B[1], 2: B[2], 3: B[3]}</code></p>
<p>And when I take a random element of SubM( with <code>SubM.random_element()</code>), it tells me it isn't in M.</p>
<p>I thought the problem came from my generator so I tried with : </p>
<p><code>sub = [matrix(4,4,{(0,0):1}),matrix(4,4,{(1,3):1}),matrix(4,4,{(2,2):1}),matrix(4,4,{(3,1):1})]</code></p>
<p>But I have the same result.
Do you know what I am doing wrong ?</p>
<p>I also need to do a XOR between matrix space, do you think it is possible ? How ?</p>
<p>Thanks you for your time :D</p>
https://ask.sagemath.org/question/60999/how-to-construct-a-matrix-space/?comment=61002#post-id-61002What is "XOR between matrix space"?Mon, 07 Feb 2022 20:43:52 +0100https://ask.sagemath.org/question/60999/how-to-construct-a-matrix-space/?comment=61002#post-id-61002Answer by Max Alekseyev for <p>I know we can create a matrix space using "MatrixSpace" but I am looking to create a specific space. I tried :</p>
<pre><code>M = MatrixSpace(ZZ,4)
B = M.basis()
sub = [B[0,0],B[1,3],B[2,2],B[3,1]]
SubM = M.submodule(sub)
SubM.basis()
</code></pre>
<p>The program show me : <code>Finite family {0: B[0], 1: B[1], 2: B[2], 3: B[3]}</code></p>
<p>And when I take a random element of SubM( with <code>SubM.random_element()</code>), it tells me it isn't in M.</p>
<p>I thought the problem came from my generator so I tried with : </p>
<p><code>sub = [matrix(4,4,{(0,0):1}),matrix(4,4,{(1,3):1}),matrix(4,4,{(2,2):1}),matrix(4,4,{(3,1):1})]</code></p>
<p>But I have the same result.
Do you know what I am doing wrong ?</p>
<p>I also need to do a XOR between matrix space, do you think it is possible ? How ?</p>
<p>Thanks you for your time :D</p>
https://ask.sagemath.org/question/60999/how-to-construct-a-matrix-space/?answer=61001#post-id-61001To see the basis of `SubM` as elements of `M` use
[b.lift() for b in SubM.basis()]
Similarly, to get a random element of `SubM` lifted to `M` run:
SubM.random_element().lift()Mon, 07 Feb 2022 20:43:10 +0100https://ask.sagemath.org/question/60999/how-to-construct-a-matrix-space/?answer=61001#post-id-61001Comment by Max Alekseyev for <p>To see the basis of <code>SubM</code> as elements of <code>M</code> use</p>
<pre><code>[b.lift() for b in SubM.basis()]
</code></pre>
<p>Similarly, to get a random element of <code>SubM</code> lifted to <code>M</code> run:</p>
<pre><code>SubM.random_element().lift()
</code></pre>
https://ask.sagemath.org/question/60999/how-to-construct-a-matrix-space/?comment=61021#post-id-61021I assume you need to use `.retract()` method. See [details in the docs](https://doc.sagemath.org/html/en/reference/modules/sage/modules/with_basis/subquotient.html#sage.modules.with_basis.subquotient.SubmoduleWithBasis).Tue, 08 Feb 2022 19:47:38 +0100https://ask.sagemath.org/question/60999/how-to-construct-a-matrix-space/?comment=61021#post-id-61021Comment by IHaveNoIdea for <p>To see the basis of <code>SubM</code> as elements of <code>M</code> use</p>
<pre><code>[b.lift() for b in SubM.basis()]
</code></pre>
<p>Similarly, to get a random element of <code>SubM</code> lifted to <code>M</code> run:</p>
<pre><code>SubM.random_element().lift()
</code></pre>
https://ask.sagemath.org/question/60999/how-to-construct-a-matrix-space/?comment=61017#post-id-61017Thank you for your answer !
By chance, do you know how can I "reverse" `.lift()` ? When I create a matrix and try to check if it is in SubM, it always return false.Tue, 08 Feb 2022 18:08:12 +0100https://ask.sagemath.org/question/60999/how-to-construct-a-matrix-space/?comment=61017#post-id-61017