| 1 |
|
| 2 |
Theorem t1 : forall (A : Set) (a : A) (f : A -> A), f a = a -> f (f a) = a. |
| 3 |
intros. |
| 4 |
congruence. |
| 5 |
Qed. |
| 6 |
|
| 7 |
Theorem t2 : |
| 8 |
forall (A : Set) (a b : A) (f : A -> A) (g : A -> A -> A), |
| 9 |
a = f a -> g b (f a) = f (f a) -> g a b = f (g b a) -> g a b = a. |
| 10 |
intros. |
| 11 |
congruence. |
| 12 |
Qed. |
| 13 |
|
| 14 |
(* 15=0 /\ 10=0 /\ 6=0 -> 0=1 *) |
| 15 |
|
| 16 |
Theorem t3 : |
| 17 |
forall (N : Set) (o : N) (s d : N -> N), |
| 18 |
s (s (s (s (s (s (s (s (s (s (s (s (s (s (s o)))))))))))))) = o -> |
| 19 |
s (s (s (s (s (s (s (s (s (s o))))))))) = o -> |
| 20 |
s (s (s (s (s (s o))))) = o -> o = s o. |
| 21 |
intros. |
| 22 |
congruence. |
| 23 |
Qed. |
| 24 |
|
| 25 |
(* Examples that fail due to dependencies *) |
| 26 |
|
| 27 |
(* yields transitivity problem *) |
| 28 |
|
| 29 |
Theorem dep : |
| 30 |
forall (A : Set) (P : A -> Set) (f g : forall x : A, P x) |
| 31 |
(x y : A) (e : x = y) (e0 : f y = g y), f x = g x. |
| 32 |
intros; dependent rewrite e; exact e0. |
| 33 |
Qed. |
| 34 |
|
| 35 |
(* yields congruence problem *) |
| 36 |
|
| 37 |
Theorem dep2 : |
| 38 |
forall (A B : Set) |
| 39 |
(f : forall (A : Set) (b : bool), if b then unit else A -> unit) |
| 40 |
(e : A = B), f A true = f B true. |
| 41 |
intros; rewrite e; reflexivity. |
| 42 |
Qed. |
| 43 |
|
| 44 |
|
| 45 |
(* example that Congruence. can solve |
| 46 |
(dependent function applied to the same argument)*) |
| 47 |
|
| 48 |
Theorem dep3 : |
| 49 |
forall (A : Set) (P : A -> Set) (f g : forall x : A, P x), |
| 50 |
f = g -> forall x : A, f x = g x. intros. |
| 51 |
congruence. |
| 52 |
Qed. |
| 53 |
|
| 54 |
(* Examples with injection rule *) |
| 55 |
|
| 56 |
Theorem inj1 : |
| 57 |
forall (A : Set) (a b c d : A), (a, c) = (b, d) -> a = b /\ c = d. |
| 58 |
intros. |
| 59 |
split; congruence. |
| 60 |
Qed. |
| 61 |
|
| 62 |
Theorem inj2 : |
| 63 |
forall (A : Set) (a c d : A) (f : A -> A * A), |
| 64 |
f = pair (B:=A) a -> Some (f c) = Some (f d) -> c = d. |
| 65 |
intros. |
| 66 |
congruence. |
| 67 |
Qed. |
| 68 |
|
| 69 |
(* Examples with discrimination rule *) |
| 70 |
|
| 71 |
Theorem discr1 : true = false -> False. |
| 72 |
intros. |
| 73 |
congruence. |
| 74 |
Qed. |
| 75 |
|
| 76 |
Theorem discr2 : Some true = Some false -> False. |
| 77 |
intros. |
| 78 |
congruence. |
| 79 |
Qed. |
| 80 |
|
| 81 |
(* example with implications *) |
| 82 |
|
| 83 |
Theorem arrow : forall (A B: Prop) (C D:Set) , A=B -> C=D -> |
| 84 |
(A -> C) = (B -> D). |
| 85 |
congruence. |
| 86 |
Qed. |
| 87 |
|
| 88 |
|
| 89 |
Set Implicit Arguments. |
| 90 |
|
| 91 |
Parameter elt: Set. |
| 92 |
Parameter elt_eq: forall (x y: elt), {x = y} + {x <> y}. |
| 93 |
Definition t (A: Set) := elt -> A. |
| 94 |
Definition get (A: Set) (x: elt) (m: t A) := m x. |
| 95 |
Definition set (A: Set) (x: elt) (v: A) (m: t A) := |
| 96 |
fun (y: elt) => if elt_eq y x then v else m y. |
| 97 |
Lemma gsident: |
| 98 |
forall (A: Set) (i j: elt) (m: t A), get j (set i (get i m) m) = get j m. |
| 99 |
Proof. |
| 100 |
intros. unfold get, set. case (elt_eq j i); intro. |
| 101 |
congruence. |
| 102 |
auto. |
| 103 |
Qed. |
| 104 |
|
| 105 |
(* bug 2447 is now closed (PC, 2014) *) |
| 106 |
|
| 107 |
Section bug_2447. |
| 108 |
|
| 109 |
Variable T:Type. |
| 110 |
|
| 111 |
Record R := mkR {x:T;y:T;z:T}. |
| 112 |
|
| 113 |
Variables a a' b b' c c':T. |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
Lemma bug_2447: mkR a b c = mkR a' b c -> a = a'. |
| 118 |
congruence. |
| 119 |
Qed. |
| 120 |
|
| 121 |
Lemma bug_2447_variant1: mkR a b c = mkR a b' c -> b = b'. |
| 122 |
congruence. |
| 123 |
Qed. |
| 124 |
|
| 125 |
Lemma bug_2447_variant2: mkR a b c = mkR a b c' -> c = c'. |
| 126 |
congruence. |
| 127 |
Qed. |
| 128 |
|
| 129 |
|
| 130 |
End bug_2447. |
| 131 |
|
| 132 |
(* congruence was supposed to do discriminate but it was bugged for |
| 133 |
types with indices *) |
| 134 |
|
| 135 |
Inductive I : nat -> Type := C : I 0 | D : I 0. |
| 136 |
Goal ~C=D. |
| 137 |
congruence. |
| 138 |
Qed. |
| 139 |
|
| 140 |
(* Example by Jonathan Leivant, congruence up to universes *) |
| 141 |
Section JLeivant. |
| 142 |
Variables S1 S2 : Set. |
| 143 |
|
| 144 |
Definition T1 : Type := S1. |
| 145 |
Definition T2 : Type := S2. |
| 146 |
|
| 147 |
Goal T1 = T1. |
| 148 |
congruence. |
| 149 |
Undo. |
| 150 |
unfold T1. |
| 151 |
congruence. |
| 152 |
Qed. |
| 153 |
End JLeivant. |
| 154 |
|
| 155 |
(* An example with primitive projections *) |
| 156 |
|
| 157 |
Module PrimitiveProjections. |
| 158 |
Set Primitive Projections. |
| 159 |
Record t (A:Type) := { f : A }. |
| 160 |
Goal forall g (a:t nat), @f nat = g -> f a = 0 -> g a = 0. |
| 161 |
congruence. |
| 162 |
Undo. |
| 163 |
intros. |
| 164 |
unfold f in H0. (* internally turn the projection to unfolded form *) |
| 165 |
congruence. |
| 166 |
Qed. |
| 167 |
End PrimitiveProjections. |