Your matrix is over GF(2) not over the symbolic ring SR: sage: m1 = SR(GF(2)(1)) * var("m1") sage: m2 = SR(GF(2)(1)) * var("m2") sage: m3 = SR(GF(2)(1)) * var("m3") sage: m4 = SR(GF(2)(1)) * var("m4")
sage: q = Matrix(SR, [ [m1, m2], [m3, m4], ]) sage: q^2 [ m1^2 + m2*m3 m1*m2 + m2*m4] [m1*m3 + m3*m4 m2*m3 + m4^2] On Tuesday 30 Sep 2014 08:46:42 Kim Schoener wrote: > I'm not sure I understand fully what you're saying. I did > > m1 = SR(GF(2)(1)) * var("m1") > m2 = SR(GF(2)(1)) * var("m2") > m3 = SR(GF(2)(1)) * var("m3") > m4 = SR(GF(2)(1)) * var("m4") > > but the Matrix definition > > q = Matrix(GF(2), [ > [m1, m2], > [m3, m4], > ]) > > still results in the same error: "unable to convert x (=x1) to an integer". > > How do I define a variable in the SR that I can work with? I can't seem to > figure it out from the example you gave me. > > Thank you, > Kim > > Am Dienstag, 30. September 2014 17:04:10 UTC+2 schrieb Volker Braun: > > Anything symbolic is in the symbolic ring SR, finite field elements are in > > GF(2). You can wrap finite field elements in the symbolic ring if you want > > to do symbolic computations with finite field coefficients: > > > > sage: SR(GF(5)(3)) * x > > 3*x > > sage: _ * 2 > > x > > > > though the symbolic elemnts still don't know anything about finite fields, > > they just carry the coefficients along. > > > > On Tuesday, September 30, 2014 3:14:03 PM UTC+1, Kim Schoener wrote: > >> Heya! > >> > >> I want to do something relatively easy in Sage but can't figure out how. > >> Hopefully you can help me. I want to do some symbolic operations > >> (matrix/vector) in the GF(2). Let's start out with real numbers first: > >> > >> (m1, m2, m3, m4) = (var("m1"), var("m2"), var("m3"), var("m4")) > >> q = Matrix([ > >> > >> [m1, m2], > >> [m3, m4], > >> > >> ]) > >> print(q) > >> print(q * q) > >> > >> Works pefectly: > >> > >> [m1 m2] > >> [m3 m4] > >> [ m1^2 + m2*m3 m1*m2 + m2*m4] > >> [m1*m3 + m3*m4 m2*m3 + m4^2] > >> > >> But when I try the same thing in GF(2) by definiing > >> > >> q = Matrix(GF(2), [ > >> > >> [m1, m2], > >> [m3, m4], > >> > >> ]) > >> > >> I get: > >> > >> [...] > >> > >> File "parent.pyx", line 1069, in sage.structure.parent.Parent.__call__ > >> > >> (sage/structure/parent.c:8546) > >> > >> File "coerce_maps.pyx", line 156, in > >> > >> sage.structure.coerce_maps.NamedConvertMap._call_ > >> (sage/structure/coerce_maps.c:4930) > >> > >> File "expression.pyx", line 857, in > >> > >> sage.symbolic.expression.Expression._integer_ > >> (sage/symbolic/expression.cpp:5877) > >> TypeError: unable to convert x (=m1) to an integer > >> > >> However, the matrix definition seems to be okay, when I do > >> > >> q = Matrix(GF(2), [ > >> > >> [1, 1 ], > >> [1, 0], > >> > >> ]) > >> print(q * q) > >> > >> I get > >> > >> [0 1] > >> [1 1] > >> > >> which is what I'd expect. Why does it not work with variables when > >> working in GF(2) and how can I get this to work the way I want it to? > >> > >> Thank you so much, > >> Regards, > >> Kim
signature.asc
Description: This is a digitally signed message part.