Skip to content

Commit a535a93

Browse files
author
Gregory Malecha
committed
implementation of Sum.
1 parent 5c27c83 commit a535a93

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

theories/Data/Sum.v

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
Require Import ExtLib.Core.RelDec.
2+
Require Import ExtLib.Tactics.Consider.
3+
Require Import ExtLib.Tactics.Injection.
4+
5+
Set Implicit Arguments.
6+
Set Strict Implicit.
7+
8+
9+
Section PairParam.
10+
Variable T : Type.
11+
Variable eqT : T -> T -> Prop.
12+
Variable U : Type.
13+
Variable eqU : U -> U -> Prop.
14+
15+
Inductive sum_eq : T + U -> T + U -> Prop :=
16+
| Inl_eq : forall a b, eqT a b -> sum_eq (inl a) (inl b)
17+
| Inr_eq : forall a b, eqU a b -> sum_eq (inr a) (inr b).
18+
19+
Variable EDT : RelDec eqT.
20+
Variable EDU : RelDec eqU.
21+
22+
Global Instance RelDec_equ_sum
23+
: RelDec (sum_eq) :=
24+
{ rel_dec := fun x y =>
25+
match x , y with
26+
| inl x , inl y => rel_dec x y
27+
| inr x , inr y => rel_dec x y
28+
| inl _ , inr _ => false
29+
| inr _ , inl _ => false
30+
end }.
31+
32+
Variable EDCT : RelDec_Correct EDT.
33+
Variable EDCU : RelDec_Correct EDU.
34+
35+
Global Instance RelDec_Correct_equ_sum : RelDec_Correct RelDec_equ_sum.
36+
Proof.
37+
constructor; destruct x; destruct y; split; simpl in *; intros;
38+
repeat match goal with
39+
| [ H : context [ rel_dec ?X ?Y ] |- _ ] =>
40+
consider (rel_dec X Y); intros; subst
41+
| [ |- context [ rel_dec ?X ?Y ] ] =>
42+
consider (rel_dec X Y); intros; subst
43+
end; intuition; try solve [ constructor; auto | congruence ].
44+
+ inversion H. intuition.
45+
+ inversion H.
46+
+ inversion H.
47+
+ inversion H; intuition.
48+
Qed.
49+
End PairParam.
50+
51+
Section SumEq.
52+
Variable T : Type.
53+
Variable U : Type.
54+
55+
Variable EDT : RelDec (@eq T).
56+
Variable EDU : RelDec (@eq U).
57+
58+
(** Specialization for equality **)
59+
Global Instance RelDec_eq_pair : RelDec (@eq (T + U)) :=
60+
{ rel_dec := fun x y =>
61+
match x , y with
62+
| inl x , inl y => rel_dec x y
63+
| inr x , inr y => rel_dec x y
64+
| inl _ , inr _ => false
65+
| inr _ , inl _ => false
66+
end }.
67+
68+
Variable EDCT : RelDec_Correct EDT.
69+
Variable EDCU : RelDec_Correct EDU.
70+
71+
Global Instance RelDec_Correct_eq_pair : RelDec_Correct RelDec_eq_pair.
72+
Proof.
73+
constructor; destruct x; destruct y; split; simpl in *; intros;
74+
repeat match goal with
75+
| [ H : context [ rel_dec ?X ?Y ] |- _ ] =>
76+
consider (rel_dec X Y); intros; subst
77+
| [ |- context [ rel_dec ?X ?Y ] ] =>
78+
consider (rel_dec X Y); intros; subst
79+
end; congruence.
80+
Qed.
81+
End SumEq.
82+
83+
Global Instance Injective_inl T U a c : Injective (@inl T U a = inl c) :=
84+
{| result := a = c |}.
85+
Proof. abstract (inversion 1; intuition). Defined.
86+
87+
Global Instance Injective_inr T U a c : Injective (@inr T U a = inr c) :=
88+
{| result := a = c |}.
89+
Proof. abstract (inversion 1; intuition). Defined.
90+
91+
Global Instance Injective_inl_False T U a c : Injective (@inl T U a = inr c) :=
92+
{| result := False |}.
93+
Proof. abstract (inversion 1; intuition). Defined.
94+
95+
Global Instance Injective_inr_False T U a c : Injective (@inr T U a = inl c) :=
96+
{| result := False |}.
97+
Proof. abstract (inversion 1; intuition). Defined.

0 commit comments

Comments
 (0)