ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 02 Apr 2017 15:27:03 -0500Solving modular systems of equationhttp://ask.sagemath.org/question/37146/solving-modular-systems-of-equation/ I am trying to solve a system of equations mod $p$, for $p$ prime. I have build matrices $A$ and $b$ and I am using the function solve_right() to solve $Ax = b$. But I need to solve $Ax = b$ mod $p$. Is there any functions that could do that ? thanks !Sun, 02 Apr 2017 10:31:52 -0500http://ask.sagemath.org/question/37146/solving-modular-systems-of-equation/Answer by B r u n o for <p>I am trying to solve a system of equations mod $p$, for $p$ prime. I have build matrices $A$ and $b$ and I am using the function solve_right() to solve $Ax = b$. But I need to solve $Ax = b$ mod $p$. Is there any functions that could do that ? thanks !</p>
http://ask.sagemath.org/question/37146/solving-modular-systems-of-equation/?answer=37147#post-id-37147If you define your matrices containing elements of the field $\mathbb Z/p\mathbb Z$, `solve_right` does what you need.
sage: A = matrix(GF(17), [[6,3], [3,8]])
sage: b = matrix(GF(17), [1, 2]).transpose()
sage: A.solve_right(b)
[14]
[12]
If for some reason you need matrices over (say) $\mathbb Z$ but still need to solve *modulo* some prime $p$, you can use `change_ring`.
sage: A = matrix(ZZ, [[1,2], [3,4]])
sage: b = matrix(ZZ, [5, 6]).transpose()
sage: A.change_ring(GF(17)).solve_right(b.change_ring(GF(17)))
[13]
[13]
Sun, 02 Apr 2017 14:24:13 -0500http://ask.sagemath.org/question/37146/solving-modular-systems-of-equation/?answer=37147#post-id-37147Comment by Sasha-dpt for <p>If you define your matrices containing elements of the field $\mathbb Z/p\mathbb Z$, <code>solve_right</code> does what you need.</p>
<pre><code>sage: A = matrix(GF(17), [[6,3], [3,8]])
sage: b = matrix(GF(17), [1, 2]).transpose()
sage: A.solve_right(b)
[14]
[12]
</code></pre>
<p>If for some reason you need matrices over (say) $\mathbb Z$ but still need to solve <em>modulo</em> some prime $p$, you can use <code>change_ring</code>.</p>
<pre><code>sage: A = matrix(ZZ, [[1,2], [3,4]])
sage: b = matrix(ZZ, [5, 6]).transpose()
sage: A.change_ring(GF(17)).solve_right(b.change_ring(GF(17)))
[13]
[13]
</code></pre>
http://ask.sagemath.org/question/37146/solving-modular-systems-of-equation/?comment=37148#post-id-37148great, thanks. I'll try the last option.Sun, 02 Apr 2017 15:27:03 -0500http://ask.sagemath.org/question/37146/solving-modular-systems-of-equation/?comment=37148#post-id-37148