Casting a univariate poly to multivariate

51 views
Skip to first unread message

Evrim Ulu

unread,
May 15, 2015, 10:05:27 AM5/15/15
to sage-s...@googlegroups.com
Hello,

I am looking for a nicer way to cast a univariate poly to a multivariate ring with the different base fields.
Basically base fields are both GF(2^3) but with different generators. I want generator of the first to be mapped to the generator of the second.

sage: f
x^6 + a*x^5 + (a + 1)*x^4 + (a^2 + a + 1)*x^3 + (a^2 + 1)*x^2 + (a + 1)*x + a^2 + a + 1
sage: f.parent()
Univariate Polynomial Ring in x over Finite Field in a of size 2^3
sage: R
Multivariate Polynomial Ring in l0, l1, l2, f0, f1, f2, f3, f4, f5, f6, f7, b0, b1, b2, b3, x, y over Finite Field in h of size 2^3


First one has a generator a, the second has the generator h.
My current solution is very unsagey.

f = sage_eval(str(f), locals={'x':x,'a':h})
x^6 + (h)*x^5 + (h + 1)*x^4 + (h^2 + h + 1)*x^3 + (h^2 + 1)*x^2 + (h + 1)*x + (h^2 + h + 1)

Best,
evrim.

Simon King

unread,
May 18, 2015, 4:19:42 AM5/18/15
to sage-s...@googlegroups.com
Hi Evrim,

On 2015-05-15, Evrim Ulu <evri...@gmail.com> wrote:
> sage: f
> x^6 + a*x^5 + (a + 1)*x^4 + (a^2 + a + 1)*x^3 + (a^2 + 1)*x^2 + (a + 1)*x +
> a^2 + a + 1
> sage: f.parent()
> Univariate Polynomial Ring in x over Finite Field in a of size 2^3
> sage: R
> Multivariate Polynomial Ring in l0, l1, l2, f0, f1, f2, f3, f4, f5, f6, f7,
> b0, b1, b2, b3, x, y over Finite Field in h of size 2^3
>
>
> First one has a generator a, the second has the generator h.

The transformation *should* be possible by just doing R(f). However, it
doesn't work.

I did some tests, and found that I could not construct *any* isomorphism
of field extensions. Does anyone know how to construct an isomorphism
between GF(8,'a') and GF(8,'h') leaving the prime field invariant?

Of course, there is no canonical isomorphism between these two field
extensions. However, I do believe that there should be a (non-canonical)
*conversion* between the two field extensions, sending the generator of
the first to the generator of the second. That currently doesn't work.

So, for now, I don't see a better solution for your problem than string
evaluation.

Best regards,
Simon

Simon King

unread,
May 18, 2015, 5:43:46 AM5/18/15
to sage-s...@googlegroups.com
Hi Evrim!

On 2015-05-18, Simon King <simon...@uni-jena.de> wrote:
> I did some tests, and found that I could not construct *any* isomorphism
> of field extensions. Does anyone know how to construct an isomorphism
> between GF(8,'a') and GF(8,'h') leaving the prime field invariant?

Aha! This is how it works:

sage: from sage.rings.finite_rings.hom_finite_field import FiniteFieldHomomorphism_generic
sage: phi = FiniteFieldHomomorphism_generic(Hom(K1,K2)); phi
Ring morphism:
From: Finite Field in a of size 2^3
To: Finite Field in h of size 2^3
Defn: a |--> h
sage: R1.<x> = K1[]
sage: R2.<l0, l1, l2, f0, f1, f2, f3, f4, f5, f6, f7, b0, b1, b2, b3, x, y> = K2[]
sage: f = R1.random_element()
sage: f
(a^2 + 1)*x^2 + (a + 1)*x + a + 1
sage: K2.register_coercion(phi)
sage: R2(f)
(h^2 + 1)*x^2 + (h + 1)*x + (h + 1)

Note, however, that the above solution is a bit dangerous. Registering a
coercion map after creation of an object can have severe implications for
the stability of a Sage session.

Here is how you can create a conversion homomorphism:

sage: F, R = R2.construction()
sage: F # This is a functor of rings that creates a polynomial ring
MPoly[l0,l1,l2,f0,f1,f2,f3,f4,f5,f6,f7,b0,b1,b2,b3,x,y]

One can apply the functor F to the morphism phi:

sage: psi = F(phi); psi
Ring morphism:
From: Multivariate Polynomial Ring in l0, l1, l2, f0, f1, f2, f3, f4, f5, f6, f7, b0, b1, b2, b3, x, y over Finite Field in a of size 2^3
To: Multivariate Polynomial Ring in l0, l1, l2, f0, f1, f2, f3, f4, f5, f6, f7, b0, b1, b2, b3, x, y over Finite Field in h of size 2^3
Defn: Induced from base ring by
Ring morphism:
From: Finite Field in a of size 2^3
To: Finite Field in h of size 2^3
Defn: a |--> h

And then one can apply the resulting induced homomorphism to an element
of R1 (conversion from R1 to the domain of psi is implicit):

sage: f = R1.random_element()
sage: f
a*x + a^2 + 1
sage: psi(f)
(h)*x + (h^2 + 1)

In summary:

- There are ways to make the conversion automatic, but I would recommend
against it (perhaps it is safer to use K2.register_conversion instead
of K2.register_coercion?)
- You can obtain a homomorphism and use it explicitly for conversion.
Depending on the application, this solution is preferred.

Best regards,
Simon


Vincent Delecroix

unread,
May 18, 2015, 6:28:45 AM5/18/15
to sage-s...@googlegroups.com


On 18/05/15 11:43, Simon King wrote:
> Hi Evrim!
>
> On 2015-05-18, Simon King <simon...@uni-jena.de> wrote:
>> I did some tests, and found that I could not construct *any* isomorphism
>> of field extensions. Does anyone know how to construct an isomorphism
>> between GF(8,'a') and GF(8,'h') leaving the prime field invariant?
>
> Aha! This is how it works:
>
> sage: from sage.rings.finite_rings.hom_finite_field import FiniteFieldHomomorphism_generic
> sage: phi = FiniteFieldHomomorphism_generic(Hom(K1,K2)); phi

Or even simpler for that step

sage: Ka = GF(8,'a')
sage: Kh = GF(8,'h')
sage: Hom(Ka,Kh)([Kh.gen()])
Ring morphism:
From: Finite Field in a of size 2^3
To: Finite Field in h of size 2^3
Defn: a |--> h

or even the one-liner

sage: Ka.hom([Kh.gen()])
Ring morphism:
From: Finite Field in a of size 2^3
To: Finite Field in h of size 2^3
Defn: a |--> h

Vincent

Simon King

unread,
May 18, 2015, 6:41:46 AM5/18/15
to sage-s...@googlegroups.com
Hi Vincent,

On 2015-05-18, Vincent Delecroix <20100.d...@gmail.com> wrote:
> Or even simpler for that step
>
> sage: Ka = GF(8,'a')
> sage: Kh = GF(8,'h')
> sage: Hom(Ka,Kh)([Kh.gen()])
> Ring morphism:
> From: Finite Field in a of size 2^3
> To: Finite Field in h of size 2^3
> Defn: a |--> h
>
> or even the one-liner
>
> sage: Ka.hom([Kh.gen()])
> Ring morphism:
> From: Finite Field in a of size 2^3
> To: Finite Field in h of size 2^3
> Defn: a |--> h

Strange. It was the first thing that I tried, but it didn't work for me.
Perhaps I had a typo in it.

Anyway, yes, that's simpler.

Best regards,
Simon


Evrim Ulu

unread,
May 18, 2015, 9:07:03 AM5/18/15
to sage-s...@googlegroups.com
Vincent, thanks for the easy solution,
Simon,  thanks for the internals, and a quick lecture here.

Below is what i've got.

Best,
evrim.

Ka.<a> = GF(8,'a')
Kh.<h> = GF(8,'h')
hom1 = Ka.hom([Kh.gen()])

R1.<x> = Ka[]
R2.<l0, l1, l2, f0, f1, f2, f3, f4, f5, f6, f7, b0, b1, b2, b3, x, y> = Kh[]
F, R = R2.construction()
print F   # This is a functor of rings that creates a polynomial ring
# MPoly[l0,l1,l2,f0,f1,f2,f3,f4,f5,f6,f7,b0,b1,b2,b3,x,y]

hom2 = F(hom1)
# sage: hom2
# Ring morphism:
#   From: Multivariate Polynomial Ring in l0, l1, l2, f0, f1, f2, f3, f4, f5, f6, f7, b0, b1, b2, b3, x, y over Finite Field in a of size 2^3
#   To:   Multivariate Polynomial Ring in l0, l1, l2, f0, f1, f2, f3, f4, f5, f6, f7, b0, b1, b2, b3, x, y over Finite Field in h of size 2^3
#   Defn: Induced from base ring by
#         Ring morphism:
#           From: Finite Field in a of size 2^3
#           To:   Finite Field in h of size 2^3
#           Defn: a |--> h

# sage: f = R1.random_element()
# sage: f
# x^2 + a*x + a^2 + a
# sage: hom2(f)
# x^2 + (h)*x + (h^2 + h)






--
You received this message because you are subscribed to a topic in the Google Groups "sage-support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-support/zYoDnuoqr1g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-support...@googlegroups.com.
To post to this group, send email to sage-s...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Nils Bruin

unread,
May 18, 2015, 11:39:42 AM5/18/15
to sage-s...@googlegroups.com
On Monday, May 18, 2015 at 2:43:46 AM UTC-7, Simon King wrote:
- There are ways to make the conversion automatic, but I would recommend
  against it (perhaps it is safer to use K2.register_conversion instead
  of K2.register_coercion?)
- You can obtain a homomorphism and use it explicitly for conversion.
  Depending on the application, this solution is preferred.
 
I think registering conversions is only safer in the sense that conversions don't get used automatically in so many situations. However, I think the algorithms for finding composed conversions and they way they are cached are very similar to what happens for coercion. So I think registering conflicting conversions will cause consistency problems in the conversion graph in exactly the same way as happens for coercions.

Simon King

unread,
May 19, 2015, 5:18:21 AM5/19/15
to sage-s...@googlegroups.com
Hi Nils,

On 2015-05-18, Nils Bruin <nbr...@sfu.ca> wrote:
> On Monday, May 18, 2015 at 2:43:46 AM UTC-7, Simon King wrote:
>
>> - There are ways to make the conversion automatic, but I would recommend
>> against it (perhaps it is safer to use K2.register_conversion instead
>> of K2.register_coercion?)
>> - You can obtain a homomorphism and use it explicitly for conversion.
>> Depending on the application, this solution is preferred.
>>
>
> I think registering conversions is only safer in the sense that conversions
> don't get used automatically in so many situations.

Yes, that's exactly what I meant.

Do you agree that conversion (not coercion) between finite fields of equal
size (mapping generator to generator) should be enabled by default?

Best regards,
Simon

John Cremona

unread,
May 19, 2015, 5:38:56 AM5/19/15
to SAGE support
-- assuming that the generators have the same minimal polynomial of
course! what about the general case?

John

>
> Best regards,
> Simon
>
> --
> You received this message because you are subscribed to the Google Groups "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.

Simon King

unread,
May 19, 2015, 5:48:15 AM5/19/15
to sage-s...@googlegroups.com
Hi John,

On 2015-05-19, John Cremona <john.c...@gmail.com> wrote:
> -- assuming that the generators have the same minimal polynomial of
> course! what about the general case?

We are talking here about default conversion. I guess
K1.hom([K2.gen()]) (mapping generator to generator) is the only
reasonable default. And We can check (and probably do check already)
whether mapping generator to generator really extends to a homomorphism
of field extensions.

Best regards,
Simon


John Cremona

unread,
May 19, 2015, 7:54:20 AM5/19/15
to SAGE support
OK. By "general case" I meant where the two fields had generators
with different minimal polynomials, where one has to do a little work
to find a suitable image for the generator:

sage: F3 = GF(3)
sage: R.<x> = F3[]
sage: F9a.<a> = GF(9,'a',x^2+1)
sage: F9b.<b> = GF(9,'b',x^2+x-1)
sage: f = F9a.hom([F9a.gen().minpoly().roots(F9b)[0][0]]); f
Ring morphism:
From: Finite Field in a of size 3^2
To: Finite Field in b of size 3^2
Defn: a |--> 2*b + 1

sage: f(a)
2*b + 1
sage: [f(s) for s in F9a]
[0, 2*b, 2*b + 1, b + 1, 2, b, b + 2, 2*b + 2, 1]
Reply all
Reply to author
Forward
0 new messages