Section square_colouring.
Definition square := 'I_4.
Canonical square_eqType := Eval hnf in [eqType of square].
Canonical square_choiceType := Eval hnf in [choiceType of square].
Canonical square_countType := Eval hnf in [countType of square].
Canonical square_finType := Eval hnf in [finType of square].
Canonical square_subType := Eval hnf in [subType of square].
Canonical square_subCountType :=
Eval hnf in [subCountType of square].
Canonical square_subFinType := Eval hnf in [subFinType of square].
Definition mksquare i : square := Sub (i %% _) (ltn_mod i 4).
Definition c0 := mksquare 0.
Definition c1 := mksquare 1.
Definition c2 := mksquare 2.
Definition c3 := mksquare 3.
(*rotations*)
Definition R1 (sc : square) : square := tnth [tuple c1; c2; c3; c0] sc.
Definition R2 (sc : square) : square := tnth [tuple c2; c3; c0; c1] sc.
Definition R3 (sc : square) : square := tnth [tuple c3; c0; c1; c2] sc.
Ltac get_inv elt l :=
match l with
| (_, (elt, ?x))  => x
| (elt, ?x)  => x
| (?x, _) => get_inv elt x
end.
Definition rot_inv := ((R1, R3), (R2, R2), (R3, R1)).
Ltac inj_tac :=
move: (erefl rot_inv); unfold rot_inv;
match goal with |- ?X = _ -> injective ?Y =>
move=> _; let x := get_inv Y X in
apply: (can_inj (g:=x)); move=> [val H1]
end.
Canonical rot_group := Group group_set_rot.
Definition rotations := [set id1; r1; r2; r3].
(*symmetries*)
Definition Sh (sc : square) : square := tnth [tuple c1; c0; c3; c2] sc.
Definition sh := (perm Sh_inj).
Definition Sv (sc : square) : square := tnth [tuple c3; c2; c1; c0] sc.
Definition sv := (perm Sv_inj).
Definition Sd1 (sc : square) : square := tnth [tuple c0; c3; c2; c1] sc.
Definition sd1 := (perm Sd1_inj).

Lemma sd1_inv : sd1^-1 = sd1.