19.2 Adding new setoid or morphisms

Under the toplevel load the Setoid_replace files with the command:

Require Setoid.
A setoid is just a type A and an equivalence relation on A.

The specification of a setoid can be found in the file

theories/Setoids/Setoid.v
It looks like :
Section Setoid.

Variable A : Type.
Variable Aeq : A -> A -> Prop.

Record Setoid_Theory : Prop :=
{ Seq_refl : (x:A) (Aeq x x);
  Seq_sym : (x,y:A) (Aeq x y) -> (Aeq y x);
  Seq_trans : (x,y,z:A) (Aeq x y) -> (Aeq y z) -> (Aeq x z)
}.

To define a setoid structure on A, you must provide a relation Aeq on A and prove that Aeq is an equivalence relation. That is, you have to define an object of type (Setoid_Theory A Aeq).

Finally to register a setoid the syntax is:

Add Setoid A Aeq ST
where Aeq is a term of type A->A->Prop and ST is a term of type (Setoid_Theory A Aeq).


Error messages:
  1. Not a valid setoid theory.
    That happens when the typing condition does not hold.
  2. A Setoid Theory is already declared for A.
    That happens when you try to declare a second setoid theory for the same type.
Currently, only one setoid structure may be declared for a given type. This allows automatic detection of the theory used to achieve the replacement.

The table of setoid theories is compatible with the Coq sectioning mechanism. If you declare a setoid inside a section, the declaration will be thrown away when closing the section. And when you load a compiled file, all the Add Setoid commands of this file that are not inside a section will be loaded.
Warning: Only the setoid on Prop is loaded by default with the Setoid_replace module. The equivalence relation used is iff i.e. the logical equivalence.