Defining Set Operations / Group Operations

Hey All,

I’m exploring coding concepts from Group theory.

There’s a lot of questions I can ask here so I wanted to put them into one place and see if anyone can support me in finding the answers.

  • If I construct a Set of elements (undefined/abstract), how can I define an operation that will work (only) on those elements?
  • How can I call upon an element from a Set?
  • How can I add new elements to a Set, if the Set is already defined?

The sets and rules I am looking to build will impact different parts of the elements in a given set. The most simple functions are rotations. So if the function is applied to an element of the Set, it outputs another element of the Set.

And addition; so when I piece two elements in the Set, it makes a new element with some changes. I want this element to sit in another Set (to be defined).

Appreciate this is abstract and may need more detail; I may also be posting other threads along these lines :slight_smile:

All the best!

Are these homework questions?

Have you read the documentation on sets? These questions should all be answered in the documentation, except for this one:

  • If I construct a Set of elements (undefined/abstract), how can I define an operation that will work (only) on those elements?

This might be best handled via the type system.

Thank you pdeffebach!

No these are not homework haha :). I am trying to build something, that links colour, through group sets, to data for analysis. But I am struggling to get my head around how to explain it, and get uncertain as to which part to focus on

I will take a read over the documentation again; thank you for sharing!

The documentation is not covering what I am looking for.

Is it possible to define a function, such that the input is an element from a given Set, and the output is an element from a given Set.

e.g: I have three elements. a,b,c. I define a set S = {a,b,c}

I define a function f(x) for x belonging to S, such that:
f(a) = b
f(b) = c
f(c) = a

One step further would be:
Let S1 = {a,b,c} , Let S2 = {d,e,f}

g(x) maps S1 → S2, for x belonging to S1 and g(x) belonging to S2:
f(a) = d
f(b) = e
f(c) = f

Any help is appreciated!

Enums will probably do what you want. See documentation here

1 Like

From what I understand, you are trying to define a function on a finite domain. For that, I would just use a dictionary maybe wrapped in a type to make it callable:

julia> struct FiniteMap{In,Out}
           mapping::Dict{In,Out}
       end

julia> FiniteMap(ins, outs) = FiniteMap(Dict(zip(ins, outs)))
FiniteMap

julia> (f::FiniteMap)(x) = f.mapping[x]

julia> f = FiniteMap([:a, :b, :c], [1, 3, 2])
FiniteMap{Symbol, Int64}(Dict(:a => 1, :b => 3, :c => 2))

julia> xs = rand([:a, :b, :c], 8)
8-element Vector{Symbol}:
 :a
 :b
 :b
 :b
 :a
 :c
 :b
 :a

julia> f.(xs)
8-element Vector{Int64}:
 1
 3
 3
 3
 1
 2
 3
 1
3 Likes