|
| 1 | +From Coq Require Import ssreflect ssrfun. |
| 2 | +From HB Require Import structures. |
| 3 | + |
| 4 | +Module Enclosing. |
| 5 | +(**************************************************************************) |
| 6 | +(* Stage 0: +Ring+ *) |
| 7 | +(**************************************************************************) |
| 8 | + |
| 9 | +HB.mixin Record Ring_of_TYPE A := { |
| 10 | + zero : A; |
| 11 | + one : A; |
| 12 | + add : A -> A -> A; |
| 13 | + opp : A -> A; |
| 14 | + mul : A -> A -> A; |
| 15 | + addrA : associative add; |
| 16 | + addrC : commutative add; |
| 17 | + add0r : left_id zero add; |
| 18 | + addNr : left_inverse zero opp add; |
| 19 | + mulrA : associative mul; |
| 20 | + mul1r : left_id one mul; |
| 21 | + mulr1 : right_id one mul; |
| 22 | + mulrDl : left_distributive mul add; |
| 23 | + mulrDr : right_distributive mul add; |
| 24 | +}. |
| 25 | +HB.structure Definition Ring := { A of Ring_of_TYPE A }. |
| 26 | + |
| 27 | +(* Notations *) |
| 28 | + |
| 29 | +Module RingExports. |
| 30 | +Declare Scope hb_scope. |
| 31 | +Delimit Scope hb_scope with G. |
| 32 | +Local Open Scope hb_scope. |
| 33 | +Notation "0" := zero : hb_scope. |
| 34 | +Notation "1" := one : hb_scope. |
| 35 | +Infix "+" := (@add _) : hb_scope. |
| 36 | +Notation "- x" := (@opp _ x) : hb_scope. |
| 37 | +Infix "*" := (@mul _) : hb_scope. |
| 38 | +Notation "x - y" := (x + - y) : hb_scope. |
| 39 | +End RingExports. |
| 40 | +HB.export RingExports. |
| 41 | + |
| 42 | +(* Theory *) |
| 43 | + |
| 44 | +Section Theory. |
| 45 | +Local Open Scope hb_scope. |
| 46 | +Variable R : Ring.type. |
| 47 | +Implicit Type (x : R). |
| 48 | + |
| 49 | +Lemma addr0 : right_id (@zero R) add. |
| 50 | +Proof. by move=> x; rewrite addrC add0r. Qed. |
| 51 | + |
| 52 | +Lemma addrN : right_inverse (@zero R) opp add. |
| 53 | +Proof. by move=> x; rewrite addrC addNr. Qed. |
| 54 | + |
| 55 | +Lemma subrr x : x - x = 0. |
| 56 | +Proof. by rewrite addrN. Qed. |
| 57 | + |
| 58 | +Lemma addrNK x y : x + y - y = x. |
| 59 | +Proof. by rewrite -addrA subrr addr0. Qed. |
| 60 | + |
| 61 | +End Theory. |
| 62 | + |
| 63 | +Module Exports. |
| 64 | +HB.reexport. |
| 65 | +End Exports. |
| 66 | +End Enclosing. |
| 67 | + |
| 68 | +(* We miss the coercions, canonical and elpi metadata *) |
| 69 | +Fail Check forall (R : Enclosing.Ring.type) (x : R), x = x. |
| 70 | +Fail Check 0%G. |
| 71 | + |
| 72 | +Export Enclosing.Exports. |
| 73 | + |
| 74 | +Check forall (R : Enclosing.Ring.type) (x : R), x = x. |
| 75 | +Check 0%G. |
0 commit comments