# Groups and fields
Reference: https://www.youtube.com/watch?v=jnhjM_2hDJE
## Group
A group consists of two things:
1. A set of elements. eg. `[1, 2, 3, 4, 5]`
2. An operation. eg. `+` or `*`
Generically an operation is denoted by a dot like `.`
A group needs to fulfill **four** different properties:
1. **Closure**: For elements `a, b` in the group, `a.b` is also in the group.
2. **Associativity**: For elements `a, b, c` in the group, `(a.b).c = a.(b.c)`
3. **Identity**: There is one special element `I` in the group such that any element `a` from the group operating with `I` gives `a` itself. `I.a = a`
4. **Invertibility**: Every element `a` from the group has an inverse `b` from the group such that `a.b = I`
**Note:** generally we dont require that `0` has an inverse
There is an optional **fifth** property. Groups which have this fifth property is called a commutative group or an **abelian** group.
1. **Commutivity**: For elements `a, b` in the group, `a.b = b.a`
### Examples
**Example 1**
1. Set of elements = `[0, 1, 2, 3, 4, 5]`
2. Operation = `additive integer mod 6` meaning `a.b = (a + b) % 6`
Lets check the properties:
1. **Closure**: **Yes**.
`(1 + 3) % 6 = 4` where `4` is in the set.
`(4 + 5) % 6 = 3` where `3` is in the set.
Any two elements from this set added together and modded with `6` is also in the set.
2. **Associativity**: **Yes**.
`(((1 + 4) % 6) + 5) % 6 = 4` where `4` is in the set.
Any three elements from this set added together and modded by `6` is also in the set.
3. **Identity**: **Yes**.
Lets take `0` as the identity element.
`(0 + 4) % 6 = 4`
`(0 + 0) % 6 = 0`
Any element in the set added to `0` and modded by `6` gives the element itself.
4. **Invertibility**: **Yes**.
Lets take `0` as the identity element.
`(1 + 5) % 6 = 0`
`(3 + 3) % 6 = 0`
Every element in the set has another element in the set which when added together and modded with `6` gives the identity element `0`.
Note an elements inverse can be itself.
5. **Commutivity**: **Yes**.
`(2 + 5) % 6 = (5 + 2) % 6 = 1`
So this set of elements and the operation is not just a **group**, it's an **abelian group**.
**Example 2**
1. Set of elements = `[0, 1, 2, 3, 4, 5]`
2. Operation = `multiplicative integer mod 6` meaning `a.b = (a * b) % 6`
Lets check the properties:
1. **Closure**: **Yes**.
`(1 * 3) % 6 = 3` where `3` is in the set.
`(4 * 5) % 6 = 2` where `2` is in the set.
Any two elements from this set multiplied together and modded with `6` is also in the set.
2. **Associativity**: **Yes**.
`(((1 * 4) % 6) * 5) % 6 = 2` where `2` is in the set.
Any three elements from this set multiplied together and modded by `6` is also in the set.
3. **Identity**: **Yes**.
Lets take `1` as the identity element.
`(1 * 4) % 6 = 4`
`(1 * 1) % 6 = 1`
Any element in the set multiplied to `1` and modded by `6` gives the element itself.
4. **Invertibility**: **No**.
Lets take `1` as the identity element.
Inverse of `5` is `5` itself.
`(5 * 5) % 6 = 1`
But there is no such inverse element present for `4`
`(4 * 0) % 6 = 0`
`(4 * 1) % 6 = 4`
`(4 * 2) % 6 = 2`
`(4 * 3) % 6 = 0`
`(4 * 4) % 6 = 4`
`(4 * 5) % 6 = 2`
So this set of elements and the operation is **not a group**.
*If we chose a prime number like `5` for the modding in the above set, we do get a group. This is why we see prime numbers often in cryptography.*
## Field
A field is a:
1. set of elements that is an **abelian group** under both the `+` and `*` operations
2. has distributive property
eg. `integers mod 5` **is** a field.
Real numbers are on a infinite field.
Cryptography is more interested in finite fields.
Groups and finite fields are important because the discrete logarithm problem is hard to solve.
_**TODO**: detail the above statement more_