# Is Julia lazy?

**URL:** <https://discourse.julialang.org/t/is-julia-lazy/64192>\
**Category:** New to Julia\
**Created:** [July 7, 2021, 4:25am UTC](https://discourse.julialang.org/t/is-julia-lazy/64192 "2021-07-07T04:25:57Z")\
**Posts on this page:** 1\
**Showing post:** 73

<div class="post-metadata">

**Author:** ![genkuroki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/genkuroki/32/18030_2.png) [@genkuroki](https://discourse.julialang.org/u/genkuroki)\
**Post date:** [July 10, 2021, 12:40am UTC](https://discourse.julialang.org/t/is-julia-lazy/64192/73 "2021-07-10T00:40:06Z")

</div>

> [@Gilles\_Dubois](#):
>
> Not to reinvent the wheel. Checking the library :

Don’t you need `det`, `inv`, etc. of a matrix for math educational purpose?

```julia
using GaloisFields, LinearAlgebra
GF7 = @GaloisField 7
B = GF7[1 2; 3 4]
det(B)

```

```julia
MethodError: no method matching abs(::𝔽₇)
...

```

```julia
inv(B)

```

```julia
MethodError: no method matching abs(::𝔽₇)
...

```

In the sense of my _minimal definition_ example, minimality requires that `inv` and `lu` in LinearAlgebra.jl be available. I have tried to make the code small so that you can easily read it for using Julia in math education.

P.S. Iterator example (continuation of the minimal definition example above)

```julia
"""See https://docs.julialang.org/en/v1/manual/interfaces/"""
Base.iterate(Fp::Type{F{p, T}}) where {p, T<:Integer} = (zero(Fp), zero(T))
function Base.iterate(Fp::Type{F{p, T}}, state) where {p, T<:Integer}
    nextstate = state + 1
    nextstate < p ? (Fp(nextstate), nextstate) : nothing
end
Base.IteratorSize(Fp::Type{F{p, T}}) where {p, T<:Integer} = Base.HasLength()
Base.length(Fp::Type{F{p, T}}) where {p, T<:Integer} = p
Base.eltype(Fp::Type{F{p, T}}) where {p, T<:Integer} = Fp

squares(Fp) = Fp[x^2 for x in Fp]
squareroots(k, Fp) = Fp[x for x in Fp if x^2 == k]
@show(collect(F7), squares(F7), squareroots.(0:6, Ref(F7)));

```

Output:

```julia
collect(F7) = F{7, BigInt}[F7(0), F7(1), F7(2), F7(3), F7(4), F7(5), F7(6)]
squares(F7) = F{7, BigInt}[F7(0), F7(1), F7(4), F7(2), F7(2), F7(4), F7(1)]
squareroots.(0:6, Ref(F7)) = Vector{F{7, BigInt}}[[F7(0)], [F7(1), F7(6)], [F7(3), F7(4)], [], [F7(2), F7(5)], [], []]

```

---

_[View the full topic](https://discourse.julialang.org/t/is-julia-lazy/64192)._
