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.Fri, 12 Nov 2021 14:25:31 +0100Cannot create Matrix with Variables over modulo ringhttps://ask.sagemath.org/question/59685/cannot-create-matrix-with-variables-over-modulo-ring/The following code does not work in the official sage cell server at sagecell(.)sagemath(.)org.
R = IntegerModRing(22)
K=matrix(R, [[var("k_{}_{}".format(u,v), latex_name="k_{{{},{}}}".format(u,v)) for v in (1..2)] for u in (1..2)])
print(K)
It complains that the k_i_j cannot be converted to integer. It works without errors if the ring is not specified during the creation of the matrix:
K=matrix([[var("k_{}_{}".format(u,v), latex_name="k_{{{},{}}}".format(u,v)) for v in (1..2)] for u in (1..2)])
Where is the problem? Is there a way to denote the k_i_j as integers / elements of the modulo ring?Thu, 11 Nov 2021 15:42:52 +0100https://ask.sagemath.org/question/59685/cannot-create-matrix-with-variables-over-modulo-ring/Answer by Max Alekseyev for <p>The following code does not work in the official sage cell server at sagecell(.)sagemath(.)org.</p>
<pre><code>R = IntegerModRing(22)
K=matrix(R, [[var("k_{}_{}".format(u,v), latex_name="k_{{{},{}}}".format(u,v)) for v in (1..2)] for u in (1..2)])
print(K)
</code></pre>
<p>It complains that the k_i_j cannot be converted to integer. It works without errors if the ring is not specified during the creation of the matrix:</p>
<pre><code>K=matrix([[var("k_{}_{}".format(u,v), latex_name="k_{{{},{}}}".format(u,v)) for v in (1..2)] for u in (1..2)])
</code></pre>
<p>Where is the problem? Is there a way to denote the k_i_j as integers / elements of the modulo ring?</p>
https://ask.sagemath.org/question/59685/cannot-create-matrix-with-variables-over-modulo-ring/?answer=59709#post-id-59709The variables you are trying to use in `K` are not in its ring `R`. Also, it's better to avoid dealing with symbolic ring (i.e. defining variables via `var`) whenever possible. A better way here is to define `R` as a polynomial ring in your variables like:
k_vars = [ ["k_{}_{}".format(u,v) for v in (1..2)] for u in (1..2) ]
R = PolynomialRing(IntegerModRing(22), sum(k_vars,[]) )
R._latex_names = sum( [["k_{{{},{}}}".format(u,v) for v in (1..2)] for u in (1..2)], [] )
K = matrix(R, k_vars)Fri, 12 Nov 2021 14:25:31 +0100https://ask.sagemath.org/question/59685/cannot-create-matrix-with-variables-over-modulo-ring/?answer=59709#post-id-59709