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.Fri, 29 Jun 2018 12:56:57 -0500TypeError : Object not iterablehttp://ask.sagemath.org/question/42769/typeerror-object-not-iterable/I am trying to build the multiplicative group of a finite field.
I define a finite field, its multiplicative group, and a conversion map
from the finite field to its multiplicative group as follows:
sage: F.<a> = GF(7^2)
sage: G = AbelianGroupWithValues([a], n=1,
....: gens_orders=[48], values_group=F)
sage: phi = G.convert_map_from(F)
Up to here, everything is fine.
Now there is an error when trying to use phi:
sage: phi(a)
Traceback (most recent call last)
...
TypeError: 'sage.rings.finite_rings.element_givaro.FiniteField_givaroElement' object is not iterable
What does this mean?Thu, 28 Jun 2018 16:18:27 -0500http://ask.sagemath.org/question/42769/typeerror-object-not-iterable/Comment by slelievre for <p>I am trying to build the multiplicative group of a finite field.</p>
<p>I define a finite field, its multiplicative group, and a conversion map
from the finite field to its multiplicative group as follows:</p>
<pre><code>sage: F.<a> = GF(7^2)
sage: G = AbelianGroupWithValues([a], n=1,
....: gens_orders=[48], values_group=F)
sage: phi = G.convert_map_from(F)
</code></pre>
<p>Up to here, everything is fine.</p>
<p>Now there is an error when trying to use phi:</p>
<pre><code>sage: phi(a)
Traceback (most recent call last)
...
TypeError: 'sage.rings.finite_rings.element_givaro.FiniteField_givaroElement' object is not iterable
</code></pre>
<p>What does this mean?</p>
http://ask.sagemath.org/question/42769/typeerror-object-not-iterable/?comment=42771#post-id-42771Related to:
- [Ask Sage question #42726: Multiplicative group of a field](https://ask.sagemath.org/question/42726)
- [Sage Trac ticket #7234: Unit groups for finite fields](https://trac.sagemath.org/ticket/7234)Fri, 29 Jun 2018 03:23:28 -0500http://ask.sagemath.org/question/42769/typeerror-object-not-iterable/?comment=42771#post-id-42771Answer by rburing for <p>I am trying to build the multiplicative group of a finite field.</p>
<p>I define a finite field, its multiplicative group, and a conversion map
from the finite field to its multiplicative group as follows:</p>
<pre><code>sage: F.<a> = GF(7^2)
sage: G = AbelianGroupWithValues([a], n=1,
....: gens_orders=[48], values_group=F)
sage: phi = G.convert_map_from(F)
</code></pre>
<p>Up to here, everything is fine.</p>
<p>Now there is an error when trying to use phi:</p>
<pre><code>sage: phi(a)
Traceback (most recent call last)
...
TypeError: 'sage.rings.finite_rings.element_givaro.FiniteField_givaroElement' object is not iterable
</code></pre>
<p>What does this mean?</p>
http://ask.sagemath.org/question/42769/typeerror-object-not-iterable/?answer=42779#post-id-42779If you expand the traceback you see that it is trying to construct an `AbelianGroupElement` from the input `a` (of type `FiniteField_givaroElement`), which does not work because the constructor expects `exponents` (of type `tuple`) as the second argument (over which it tries to *iterate*) instead.
I'm not sure `phi = G.convert_map_from(F)` should be expected to work in this case, because to calculate `phi(x)` for arbitrary `x` in `F` it would have to solve for $k$ in the equation $x = a^k$ (discrete logarithm problem).
However, you can still define the desired map yourself, e.g. as follows:
1. Name the generator of `G`, either by `g = G.gen()` or naming it in the definition:
`G.<g> = AbelianGroupWithValues([a], [48])`
2. Define the map `conversion_map = lambda x: g^x.log(a)`.
For example, `conversion_map(a^50)` yields `g^2` in `G`, and `conversion_map(a^50).value() == a^50` is `True`.
Remark: The documentation warns that `x.log(a)` is currently implemented inefficiently.Fri, 29 Jun 2018 12:56:57 -0500http://ask.sagemath.org/question/42769/typeerror-object-not-iterable/?answer=42779#post-id-42779