# \[ANN\] Released GaloisFields v1.0

**URL:** <https://discourse.julialang.org/t/ann-released-galoisfields-v1-0/33071>\
**Category:** Package Announcements\
**Tags:** package, announcement, math, algebra\
**Created:** [January 7, 2020, 6:44pm UTC](https://discourse.julialang.org/t/ann-released-galoisfields-v1-0/33071 "2020-01-07T18:44:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tkluck](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkluck/32/15769_2.png) [@tkluck](https://discourse.julialang.org/u/tkluck)\
**Post date:** [January 7, 2020, 6:44pm UTC](https://discourse.julialang.org/t/ann-released-galoisfields-v1-0/33071/1 "2020-01-07T18:44:32Z")

</div>

I just released v1.0 of [`GaloisFields.jl`](https://github.com/tkluck/GaloisFields.jl). For those people not familiar – a Galois field (or ‘finite field’) is a finite set that supports addition and multiplication, both with their inverses subtraction and division. The most well-known examples are the integers modulo a prime number p. This package allows using these sets wherever a `Number` is expected.

Commonly, a bottleneck when using Galois fields is the modulo (`mod`) operation. An interesting feature of this package is the use of broadcasting to reduce the number of these: whenever there’s a sufficient number of bits in `Int`, we postpone computing this reduction until the end. Here’s the performance effect:

```julia
julia> using GaloisFields
julia> const F = GaloisField(29);
julia> x = rand(F, 1000); y = rand(F, 1000); z = rand(F);
julia> @btime x .+ z .* y; # fused modulo optimization
  2.547 μs (7 allocations: 1.22 KiB)
julia> @btime broadcast((x,z,y) -> x + z * y, x, z, y); # same operation, no special optimization
  4.998 μs (1 allocation: 1.06 KiB)

```

`@b-reinke` contributed bug fixes and @Keno contributed support for [`BitIntegers.jl`](https://github.com/rfourquet/BitIntegers.jl) and code to compute primitive roots of unity. For fields of prime power order, we use [Frank Lübeck’s](http://www.math.rwth-aachen.de/~Frank.Luebeck/index.html) [database of Conway polynomials](http://www.math.rwth-aachen.de/~Frank.Luebeck/data/ConwayPol/index.html?LANG=en).

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [January 8, 2020, 4:01am UTC](https://discourse.julialang.org/t/ann-released-galoisfields-v1-0/33071/2 "2020-01-08T04:01:50Z")

</div>

How do cast `15` in the `GaloisField(7)`? It’s should be the identity.

Is there a function to check if an element is a generator in the field?

---

<div class="post-metadata">

**Author:** ![tkluck](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkluck/32/15769_2.png) [@tkluck](https://discourse.julialang.org/u/tkluck)\
**Post date:** [January 8, 2020, 10:03am UTC](https://discourse.julialang.org/t/ann-released-galoisfields-v1-0/33071/3 "2020-01-08T10:03:52Z")

</div>

Thanks for asking!

> [@xiaodai](#):
>
> How do cast `15` in the `GaloisField(7)` ? It’s should be the identity.

```julia
julia> using GaloisFields
julia> const F = GaloisField(7);
julia> F(15)
1
julia> convert(F, 15)
1

```

> [@xiaodai](#):
>
> Is there a function to check if an element is a generator in the field?

There is, thanks to @Keno:

```julia
julia> GaloisFields.is_primitive_root.(F, F.(1:6), char(F) - 1)
6-element BitArray{1}:
 0
 0
 1
 0
 1
 0

```

---

<div class="post-metadata">

**Author:** ![SSF](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@SSF](https://discourse.julialang.org/u/SSF)\
**Post date:** [April 7, 2023, 5:33pm UTC](https://discourse.julialang.org/t/ann-released-galoisfields-v1-0/33071/4 "2023-04-07T17:33:33Z")

</div>

Hi everyone, Hi @tkluck !  
I don’t know if it makes sense to post 2 years after package announcement, but I am trying to use GaloisField with 2^p extension. It seems I have issues with it. Could you provide some help / information? (new to Julia, sorry if my post is not in the appropriate place).

```julia
julia> using GaloisFields
julia> const F = GaloisField(2^8)
(𝔽₂₅₆, ##312)

```

I can see the tuple output which is not the same as without extension. Then when I want to convert, the following issue is output:

```julia
julia> F(256)
ERROR: MethodError: objects of type Tuple{DataType, 𝔽₂₅₆} are not callable
Stacktrace:
 [1] top-level scope
   @ REPL[8]:1

```

And if I use the first tuple element, it acts as GF(2):

```julia
julia> a = F[1](15)
1
julia> typeof(a)
𝔽₂₅₆

```

Thanks for your help!  
B.R.

---

<div class="post-metadata">

**Author:** ![thofma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thofma/32/1691_2.png) [@thofma](https://discourse.julialang.org/u/thofma)\
**Post date:** [April 15, 2023, 6:13am UTC](https://discourse.julialang.org/t/ann-released-galoisfields-v1-0/33071/5 "2023-04-15T06:13:28Z")

</div>

I am sure you found the answer. But to have the answer also in writing here: `15` is equal to `1` in GF(2^8).

---

<div class="post-metadata">

**Author:** ![SSF](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@SSF](https://discourse.julialang.org/u/SSF)\
**Post date:** [April 15, 2023, 9:24am UTC](https://discourse.julialang.org/t/ann-released-galoisfields-v1-0/33071/6 "2023-04-15T09:24:09Z")

</div>

Well yes I think I did. In fact I was expecting a behavior like e.g. in matlab where you can name all the elements of GF(2^p) by an integer between 0 and 2^p-1, instead of using a generator element \alpha. I understood that it was not implemented like this.  
Thanks for your message however!

---

<div class="post-metadata">

**Author:** ![tkluck](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkluck/32/15769_2.png) [@tkluck](https://discourse.julialang.org/u/tkluck)\
**Post date:** [April 18, 2023, 8:01am UTC](https://discourse.julialang.org/t/ann-released-galoisfields-v1-0/33071/7 "2023-04-18T08:01:46Z")

</div>

@SSF thanks for using GaloisFields.jl . The same question came up on Github before and here’s my answer there: [Mapping to/from extension fields · Issue #17 · tkluck/GaloisFields.jl · GitHub](https://github.com/tkluck/GaloisFields.jl/issues/17#issuecomment-878634349)

I should probably add methods for `reinterpret` to do what you’re asking here.

---

<div class="post-metadata">

**Author:** ![SSF](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@SSF](https://discourse.julialang.org/u/SSF)\
**Post date:** [April 18, 2023, 10:29am UTC](https://discourse.julialang.org/t/ann-released-galoisfields-v1-0/33071/8 "2023-04-18T10:29:28Z")

</div>

thanks for pointing this Github question and your answer, that’s fine for me!
