1

I am trying to prove that Z3 is a group.

Class Group G : Type :=
{
    e : G;
    mult : G -> G -> G;
    inv : G -> G;
    left_id : forall x:G, mult e x = x;
    left_inv : forall x:G, mult (inv x) x = e;
    assoc : forall x y z:G,
        mult x (mult y z) = mult (mult x y) z
}.

Record Z_3 : Type := Z3
{
  n :> nat;
  proof : n < 3
}.

(* Inhabitants of Z_3 type *)

Proposition lt_0_3 : 0 < 3.
Proof.
  repeat constructor.
Qed.

Definition z3_0 : Z_3 := (Z3 0 lt_0_3).

Proposition lt_1_3 : 1 < 3.
Proof.
  repeat constructor.
Qed.

Definition z3_1 : Z_3 := (Z3 1 lt_1_3).

Proposition lt_2_3 : 2 < 3.
Proof.
  repeat constructor.
Qed.

Definition z3_2 : Z_3 := (Z3 2 lt_2_3).
(* End of inhabitants definition *)

Proposition three_ne_0 : 3 <> 0.
Proof.
  intro. discriminate.
Qed.

Definition Z3_op (x y: Z_3) : Z_3 :=
  let a := (x + y) mod 3 in
  Z3 a (Nat.mod_upper_bound _ 3 three_ne_0).

Lemma Z_3_inv_lemma (k: nat) : (3 + k) < 3 -> False.
Proof.
  intro. inversion_clear H. inversion_clear H0. inversion_clear H. inversion_clear H0.
Qed.

Lemma void {t : Set} : False -> t.
Proof.
  intro. contradiction H.
Qed.

Definition Z_3_inv (x : Z_3) : Z_3 :=
  match x with
  | Z3 0 pf => Z3 0 pf
  | Z3 1 pf => Z3 2 lt_2_3
  | Z3 2 pf => Z3 1 lt_1_3
  | Z3 (S (S (S k))) pf => void (Z_3_inv_lemma k pf)
  end.

Proposition Z3_left_id : forall x: Z_3, (Z3_op z3_0 x) = x.
Proof.
  intro. unfold Z3_op. destruct x. inversion proof0.
  - 

Here I am stuck:

1 subgoal (ID 46)
  
  n0 : nat
  proof0 : n0 < 3
  H0 : n0 = 2
  ============================
  {|
  n := (z3_0 + {| n := n0; proof := proof0 |}) mod 3;
  proof := Nat.mod_upper_bound
             (z3_0 + {| n := n0; proof := proof0 |}) 3
             three_ne_0 |} = {| n := n0; proof := proof0 |}

rewrite H0. doesn't work. Sorry, it's too hard for me to move further when these records are involved.

user4035
  • 22,508
  • 11
  • 59
  • 94

1 Answers1

2

You should first create and apply a separate lemma, which lets you prove equalities between Z3 elements. Then you're reduced to having an equality of sigma types, for which you can e.g. follow https://stackoverflow.com/a/27080869/53974.

In your case, however, axioms can be avoided — you don’t need functional extensionality, and you can avoid the axiom of proof irrelevance by storing a type of proofs that is provably proof-irrelevant; it might be that z < 3 already is proof-irrelevant, because < is written to admit a unique inhabitant.

But otherwise, you can replace z < 3 with z <? 3 = true, which is proof-irrelevant by Hedberg’s theorem.

Blaisorblade
  • 6,438
  • 1
  • 43
  • 76
  • "you can avoid the axiom of proof irrelevance by storing a type of proofs that is provably proof-irrelevant" - how to do it? Can you give an example? – user4035 Oct 11 '20 at 16:57