| 1 |
From elpi.apps Require Import tc. |
| 2 |
From Corelib Require Import Morphisms RelationClasses ListDef Setoid. |
| 3 |
|
| 4 |
Generalizable All Variables. |
| 5 |
Elpi TC Solver Override TC.Solver All. |
| 6 |
|
| 7 |
Class Inj {A B} (R : relation A) (S : relation B) (f : A -> B) := |
| 8 |
inj x y : S (f x) (f y) -> R x y. |
| 9 |
|
| 10 |
Class Inj2 {A B C} (R1 : relation A) (R2 : relation B) |
| 11 |
(S : relation C) (f : A -> B -> C) : Prop := |
| 12 |
inj2 x1 x2 y1 y2 : S (f x1 x2) (f y1 y2) -> R1 x1 y1 /\ R2 x2 y2. |
| 13 |
|
| 14 |
(* Elpi TC Solver Override TC.Solver Only Inj Inj2. *) |
| 15 |
|
| 16 |
Definition gInj x := x + 1. |
| 17 |
Definition fInj x := x * 3. |
| 18 |
|
| 19 |
Axiom eq1 : relation nat. |
| 20 |
Axiom eq2 : relation nat. |
| 21 |
Axiom eq3 : relation nat. |
| 22 |
|
| 23 |
Local Instance isInjg : Inj eq3 eq1 gInj. Admitted. |
| 24 |
|
| 25 |
Local Instance isInjf : Inj eq1 eq3 fInj. Admitted. |
| 26 |
|
| 27 |
Local Instance isInjf_old : Inj eq1 eq2 fInj. Admitted. |
| 28 |
Local Instance isInjg_old : Inj eq2 eq3 gInj. Admitted. |
| 29 |
|
| 30 |
Local Instance isInjf_eq : Inj eq eq fInj. Admitted. |
| 31 |
Local Instance isInjg_eq : Inj eq eq gInj. Admitted. |
| 32 |
|
| 33 |
Local Instance id_inj {A} : Inj eq eq (@id A). Admitted. |
| 34 |
Local Instance inl_inj {A B} : Inj eq eq (@inl A B). Admitted. |
| 35 |
Local Instance inr_inj {A B} : Inj eq eq (@inr A B). Admitted. |
| 36 |
|
| 37 |
Definition compose {T1 T2 T3: Type} (g: T2 -> T3) (f : T1 -> T2) (x: T1) := g(f x). |
| 38 |
Local Instance compose_inj {A B C} R1 R2 R3 (f : A -> B) (g : B -> C) : |
| 39 |
Inj R1 R2 f -> Inj R2 R3 g -> Inj R1 R3 (compose g f). |
| 40 |
Admitted. |
| 41 |
|
| 42 |
Goal exists A B, Inj A B (compose gInj fInj). Admitted. |
| 43 |
|
| 44 |
Goal forall (T1 T2 : Type) (f: T1 -> T2), |
| 45 |
let r := Inj eq eq f in |
| 46 |
let x := true in |
| 47 |
(if x then r else r) -> Inj eq eq f. |
| 48 |
intros ? ? f r x H. |
| 49 |
unfold x, r in H. |
| 50 |
apply _. |
| 51 |
Qed. |
| 52 |
|
| 53 |
Goal forall (T1 T2 : Type) (f: T1 -> T2), |
| 54 |
let r := Inj eq eq f in |
| 55 |
let b := true in |
| 56 |
let cond := (match b with |
| 57 |
| true => r |
| 58 |
| false => f = f end) in |
| 59 |
cond -> Inj eq eq f. |
| 60 |
intros. |
| 61 |
unfold cond in H. |
| 62 |
simpl in H. |
| 63 |
unfold r in H. |
| 64 |
apply _. |
| 65 |
Qed. |
| 66 |
|
| 67 |
Elpi TC Solver Override TC.Solver All. |
| 68 |
Local Instance inj2_inj_1 `{Inj2 A B C R1 R2 R3 ff} y : Inj R1 R3 (fun x => ff x y). |
| 69 |
Admitted. |
| 70 |
|
| 71 |
Global Instance inj2_inj_2 `{Inj2 A B C R1 R2 R3 ff} x : Inj R2 R3 (ff x). |
| 72 |
Admitted. |
| 73 |
|
| 74 |
(* TODO: This does not work *) |
| 75 |
Goal Inj2 eq eq eq Nat.mul -> Inj eq eq (Nat.mul 0). |
| 76 |
intros. |
| 77 |
apply _. |
| 78 |
Qed. |
| 79 |
|
| 80 |
Goal Inj2 eq eq eq Nat.add -> Inj eq eq (fun x => Nat.add x 0). |
| 81 |
intros. |
| 82 |
apply _. |
| 83 |
Qed. |
| 84 |
|
| 85 |
Definition p (T : Type) := @pair T T. |
| 86 |
|
| 87 |
Goal Inj eq eq (compose fInj gInj). |
| 88 |
Proof. |
| 89 |
apply _. |
| 90 |
Qed. |
| 91 |
|
| 92 |
Set Warnings "+elpi". |
| 93 |
|
| 94 |
Elpi Accumulate tc.db lp:{{ |
| 95 |
shorten tc-elpi.apps.tc.tests.injTest.{tc-Inj}. |
| 96 |
% shorten tc-injTest.{tc-Inj}. |
| 97 |
tc-Inj T1 T2 R1 R3 F S :- |
| 98 |
F = (fun _ _ _), |
| 99 |
G = {{ compose _ _ }}, |
| 100 |
coq.unify-eq G F ok, |
| 101 |
tc-Inj T1 T2 R1 R3 G S. |
| 102 |
}}. |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
Goal Inj eq eq (compose fInj gInj). apply _. Qed. |
| 107 |
Goal Inj eq eq (fun x => fInj (gInj x)). apply _. Qed. |
| 108 |
|
| 109 |
Goal forall (A: Type) (x: A -> A), |
| 110 |
let y := Inj eq eq x in |
| 111 |
let z := y in z -> |
| 112 |
Inj eq eq (compose x x). |
| 113 |
Proof. |
| 114 |
intros T x y z H. |
| 115 |
unfold z, y in H. |
| 116 |
apply _. |
| 117 |
Qed. |