Using Implicit Class Type Parameters in Coq Notation

I am trying to bow my head to class classes in Coq (I have done this in the past, but I am far from being an experienced user). As an exercise, I am trying to write a group theory library. This is what I came up with:

Class Group {S : Type} {op : S → S → S} := {
  id : S;

  inverse : S → S;

  id_left {x} : (op id x) = x;
  id_right {x} : (op x id) = x;

  assoc {x y z} : (op (op x y) z) = (op x (op y z));

  right_inv {x} : (op x (inverse x)) = id;
}.

I especially like implicit parameters Sand op(if I understand them correctly).

Making some notation for inversions is easy:

Notation "- x" := (@inverse _ _ _ x)
  (at level 35, right associativity) : group_scope.

Now I would like to make a x * ycut for (op x y). When working with partitions, this is quite simple:

Section Group.
Context {S} {op} { G : @Group S op }.

(* Reserved at top of file *)
Notation "x * y" := (op x y) : group_scope.
(* ... *)
End Group.

, , . , . , ( inverse), , op Group, ( (@op _ _ _ x y)). , , , . - ?

(25 2018 .)

, , :

Reserved Notation "x * y" (at level 40, left associativity).

Class alg_group_binop (S : Type) := alg_group_op : S → S → S.

Delimit Scope group_scope with group.
Infix "*" := alg_group_op: group_scope.

Open Scope group_scope.

Class Group {S : Type} {op : alg_group_binop S} : Type := {
  id : S;

  inverse : S → S;

  id_left {x} : id * x = x;
  id_right {x} : x * id = x;

  assoc {x y z} : (x * y) * z = x * (y * z);

  right_inv {x} : x * (inverse x) = id;

}.
+4
2

Coq (§3.9.2 ):

ibid. :

Class monoid_binop (A:Type) := monoid_op : A -> A -> A.

Nota: , monoid_op , , monoid_op f δβ- f.

:

Delimit Scope M_scope with M.
Infix "*" := monoid_op: M_scope.
Open Scope M_scope.

Monoid, monoid_binop A A → A → A, infix x * y monoid_op x y:

Class Monoid (A:Type) (dot : monoid_binop A) (one : A) : Type := {
  dot_assoc : forall x y z:A, x*(y*z) = x*y*z;
  one_left : forall x, one * x = x;
  one_right : forall x, x * one = x
}.
+3

, , .

Definition group_op {S op} {G : @Group S op} := op.
Infix "*" := group_op.

also work here? (I tried only two basic tests.)

This will save you a change in definition Group.

0
source

Source: https://habr.com/ru/post/1692559/


All Articles