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, 01 Jun 2019 13:13:32 +0200How to handle elements of two different Galois fields simultaneously?https://ask.sagemath.org/question/46758/how-to-handle-elements-of-two-different-galois-fields-simultaneously/I would like to operate the elements of two different fields simultaneously. I have used the following codes, both are not working at the same time whereas only one work at a time.
G.<x> = GF(2^8, name='x', modulus=x^8 + x^5 + x^3 + x + 1)
F.<x> = GF(2^3, name='x', modulus=x^3 + x^2 + 1)
for i in range(2^3):
print G.fetch_int(i).integer_representation(), '=', G.fetch_int(i)
print F.fetch_int(i).integer_representation(), '=', F.fetch_int(i)Sat, 01 Jun 2019 10:45:13 +0200https://ask.sagemath.org/question/46758/how-to-handle-elements-of-two-different-galois-fields-simultaneously/Comment by FrédéricC for <p>I would like to operate the elements of two different fields simultaneously. I have used the following codes, both are not working at the same time whereas only one work at a time. </p>
<pre><code>G.<x> = GF(2^8, name='x', modulus=x^8 + x^5 + x^3 + x + 1)
F.<x> = GF(2^3, name='x', modulus=x^3 + x^2 + 1)
for i in range(2^3):
print G.fetch_int(i).integer_representation(), '=', G.fetch_int(i)
print F.fetch_int(i).integer_representation(), '=', F.fetch_int(i)
</code></pre>
https://ask.sagemath.org/question/46758/how-to-handle-elements-of-two-different-galois-fields-simultaneously/?comment=46759#post-id-46759Use different names..Sat, 01 Jun 2019 12:24:03 +0200https://ask.sagemath.org/question/46758/how-to-handle-elements-of-two-different-galois-fields-simultaneously/?comment=46759#post-id-46759Comment by BSFU for <p>I would like to operate the elements of two different fields simultaneously. I have used the following codes, both are not working at the same time whereas only one work at a time. </p>
<pre><code>G.<x> = GF(2^8, name='x', modulus=x^8 + x^5 + x^3 + x + 1)
F.<x> = GF(2^3, name='x', modulus=x^3 + x^2 + 1)
for i in range(2^3):
print G.fetch_int(i).integer_representation(), '=', G.fetch_int(i)
print F.fetch_int(i).integer_representation(), '=', F.fetch_int(i)
</code></pre>
https://ask.sagemath.org/question/46758/how-to-handle-elements-of-two-different-galois-fields-simultaneously/?comment=46760#post-id-46760@FrédéricC I have used different names, but this also gives error: raise ValueError("the degree of the modulus does not equal the degree of the field")
ValueError: the degree of the modulus does not equal the degree of the fieldSat, 01 Jun 2019 12:29:34 +0200https://ask.sagemath.org/question/46758/how-to-handle-elements-of-two-different-galois-fields-simultaneously/?comment=46760#post-id-46760Answer by rburing for <p>I would like to operate the elements of two different fields simultaneously. I have used the following codes, both are not working at the same time whereas only one work at a time. </p>
<pre><code>G.<x> = GF(2^8, name='x', modulus=x^8 + x^5 + x^3 + x + 1)
F.<x> = GF(2^3, name='x', modulus=x^3 + x^2 + 1)
for i in range(2^3):
print G.fetch_int(i).integer_representation(), '=', G.fetch_int(i)
print F.fetch_int(i).integer_representation(), '=', F.fetch_int(i)
</code></pre>
https://ask.sagemath.org/question/46758/how-to-handle-elements-of-two-different-galois-fields-simultaneously/?answer=46761#post-id-46761The modulus should be a polynomial over the prime field.
R.<x> = PolynomialRing(GF(2))
G = GF(2^8, name='x', modulus=x^8 + x^5 + x^3 + x + 1)
F = GF(2^3, name='x', modulus=x^3 + x^2 + 1)
for i in range(2^3):
print G.fetch_int(i).integer_representation(), '=', G.fetch_int(i)
print F.fetch_int(i).integer_representation(), '=', F.fetch_int(i)
To get the generator of, say, `F`, use `F.gen()`. Or give them different names like so (still using `x` in `R`):
G.<a> = GF(2^8, modulus=x^8 + x^5 + x^3 + x + 1)
F.<b> = GF(2^3, modulus=x^3 + x^2 + 1)Sat, 01 Jun 2019 13:13:32 +0200https://ask.sagemath.org/question/46758/how-to-handle-elements-of-two-different-galois-fields-simultaneously/?answer=46761#post-id-46761