| 1 |
Require Import TestSuite.admit. |
| 2 |
(* Check that inversion of names of mutual inductive fixpoints works *) |
| 3 |
(* (cf BZ#1031) *) |
| 4 |
|
| 5 |
Inductive tree : Set := |
| 6 |
| node : nat -> forest -> tree |
| 7 |
with forest : Set := |
| 8 |
| leaf : forest |
| 9 |
| cons : tree -> forest -> forest |
| 10 |
. |
| 11 |
Definition copy_of_compute_size_forest := |
| 12 |
fix copy_of_compute_size_forest (f:forest) : nat := |
| 13 |
match f with |
| 14 |
| leaf => 1 |
| 15 |
| cons t f0 => copy_of_compute_size_forest f0 + copy_of_compute_size_tree t |
| 16 |
end |
| 17 |
with copy_of_compute_size_tree (t:tree) : nat := |
| 18 |
match t with |
| 19 |
| node _ f => 1 + copy_of_compute_size_forest f |
| 20 |
end for copy_of_compute_size_forest |
| 21 |
. |
| 22 |
Eval simpl in (copy_of_compute_size_forest leaf). |
| 23 |
|
| 24 |
|
| 25 |
(* Another interesting case: Hrec has two occurrences: one cannot be folded |
| 26 |
back to f while the second can. *) |
| 27 |
Parameter g : (nat->nat)->nat->nat->nat. |
| 28 |
|
| 29 |
Definition f (n n':nat) := |
| 30 |
nat_rec (fun _ => nat -> nat) |
| 31 |
(fun x => x) |
| 32 |
(fun k Hrec => g Hrec (Hrec k)) |
| 33 |
n n'. |
| 34 |
|
| 35 |
Goal forall a b, f (S a) b = b. |
| 36 |
intros. |
| 37 |
simpl. |
| 38 |
match goal with [ |- g (f a) (f a a) b = b ] => idtac end. |
| 39 |
admit. |
| 40 |
Qed. |
| 41 |
|
| 42 |
(* Yet another example. *) |
| 43 |
|
| 44 |
Require Import TestSuite.list. |
| 45 |
|
| 46 |
Goal forall A B (a:A) l f (i:B), fold_right f i ((a :: l))=i. |
| 47 |
intros. |
| 48 |
simpl. |
| 49 |
match goal with [ |- f0 a (fold_right f0 i l) = i ] => idtac end. |
| 50 |
admit. |
| 51 |
Qed. (* Qed will fail if simplification is incorrect (de Bruijn!) *) |
| 52 |
|
| 53 |
(* Check that maximally inserted arguments do not break interpretation |
| 54 |
of references in simpl, vm_compute etc. *) |
| 55 |
|
| 56 |
Arguments fst {A} {B} p. |
| 57 |
|
| 58 |
Goal fst (0,0) = 0. |
| 59 |
simpl fst. |
| 60 |
Fail set (fst _). |
| 61 |
Abort. |
| 62 |
|
| 63 |
Goal fst (0,0) = 0. |
| 64 |
vm_compute fst. |
| 65 |
Fail set (fst _). |
| 66 |
Abort. |
| 67 |
|
| 68 |
Goal let f x := x + 0 in f 0 = 0. |
| 69 |
intro. |
| 70 |
vm_compute f. |
| 71 |
Fail set (f _). |
| 72 |
Abort. |
| 73 |
|
| 74 |
(* This is a change wrt 8.4 (waiting to know if it breaks script a lot or not)*) |
| 75 |
|
| 76 |
Goal 0+0=0. |
| 77 |
Fail simpl @eq. |
| 78 |
Abort. |
| 79 |
|
| 80 |
(* Check reference by notation in simpl *) |
| 81 |
|
| 82 |
Goal 0+0 = 0. |
| 83 |
simpl "+". |
| 84 |
Fail set (_ + _). |
| 85 |
Abort. |
| 86 |
|
| 87 |
(* Check occurrences *) |
| 88 |
|
| 89 |
Record box A := Box { unbox : A }. |
| 90 |
|
| 91 |
Goal unbox _ (unbox _ (unbox _ (Box _ (Box _ (Box _ True))))) = |
| 92 |
unbox _ (unbox _ (unbox _ (Box _ (Box _ (Box _ True))))). |
| 93 |
simpl (unbox _ (unbox _ _)) at 1. |
| 94 |
match goal with |- True = unbox _ (unbox _ (unbox _ (Box _ (Box _ (Box _ True))))) => idtac end. |
| 95 |
Undo 2. |
| 96 |
Fail simpl (unbox _ (unbox _ _)) at 5. |
| 97 |
simpl (unbox _ (unbox _ _)) at 1 4. |
| 98 |
match goal with |- True = unbox _ (Box _ True) => idtac end. |
| 99 |
Undo 2. |
| 100 |
Fail simpl (unbox _ (unbox _ _)) at 3 4. (* Nested and even overlapping *) |
| 101 |
simpl (unbox _ (unbox _ _)) at 2 4. |
| 102 |
match goal with |- unbox _ (Box _ True) = unbox _ (Box _ True) => idtac end. |
| 103 |
Abort. |
| 104 |
|
| 105 |
(* Check interpretation of ltac variables (was broken in 8.5 beta 1 and 2 *) |
| 106 |
|
| 107 |
Goal 2=1+1. |
| 108 |
match goal with |- (_ = ?c) => simpl c end. |
| 109 |
match goal with |- 2 = 2 => idtac end. (* Check that it reduced *) |
| 110 |
Abort. |
| 111 |
|
| 112 |
Module FurtherAppliedPrimitiveProjections. |
| 113 |
Set Primitive Projections. |
| 114 |
Record T := { u : nat -> nat }. |
| 115 |
Goal {| u:= fun x => x |}.(u) 0 = 0. |
| 116 |
simpl u. |
| 117 |
match goal with |- 0 = 0 => idtac end. (* Check that it reduced *) |
| 118 |
Abort. |
| 119 |
End FurtherAppliedPrimitiveProjections. |
| 120 |
|
| 121 |
Module BugUniverseMutualFix. |
| 122 |
Set Universe Polymorphism. |
| 123 |
Fixpoint foo1@{u v} (A : Type@{u}) n : Type@{v} := match n with 0 => A | S n => (foo2 A n * A)%type end |
| 124 |
with foo2@{u v} (A : Type@{u}) n : Type@{v} := match n with 0 => A | S n => (foo1 A n * A)%type end. |
| 125 |
Set Printing Universes. |
| 126 |
Definition bar@{u} (A : Type@{u}) n := foo1@{u u} A n. |
| 127 |
Goal forall n, bar unit (S n) = unit. |
| 128 |
simpl. |
| 129 |
Abort. |
| 130 |
End BugUniverseMutualFix. |
| 131 |
|
| 132 |
Module PolyUniverses. |
| 133 |
(* An example showing that the cache needs to take universes into account *) |
| 134 |
Set Universe Polymorphism. |
| 135 |
Record cell T S := Cell { hd : T; tl : S }. |
| 136 |
Arguments Cell {_ _}. |
| 137 |
Arguments hd {_ _}. |
| 138 |
Arguments tl {_ _}. |
| 139 |
Notation "x ::: y" := (Cell x y) (at level 60). |
| 140 |
Definition ilist T n := @Nat.iter n Type (cell T) unit. |
| 141 |
Fixpoint imap@{u u0 u1 u2} (T:Type@{u}) (S:Type@{u0}) (f : T -> S) n : ilist@{u2 u1} T n -> ilist@{u0 u1} S n := |
| 142 |
match n with |
| 143 |
| 0 => fun l => tt |
| 144 |
| S n => fun l => f l.(hd) ::: imap _ _ f _ l.(tl) |
| 145 |
end. |
| 146 |
Lemma imap_eq (T S : Type) (f g : T -> S) : |
| 147 |
forall n, forall x, @imap _ _ f n x = @imap _ _ g n x. |
| 148 |
induction n. intro; auto. |
| 149 |
intros []. |
| 150 |
Abort. |
| 151 |
|
| 152 |
End PolyUniverses. |
| 153 |
|
| 154 |
Module WithLet. |
| 155 |
|
| 156 |
Section S. |
| 157 |
Variable a : nat. |
| 158 |
Let b := 0. |
| 159 |
Variable c : nat. |
| 160 |
Fixpoint f n := |
| 161 |
match n with |
| 162 |
| 0 => a + b + c |
| 163 |
| S n => f n |
| 164 |
end. |
| 165 |
End S. |
| 166 |
|
| 167 |
Definition f' a c n := f a c n. |
| 168 |
|
| 169 |
Lemma L a c n : f' a c (S n) = f a c (S n). |
| 170 |
simpl. |
| 171 |
match goal with [ |- f' a c n = f a c n ] => idtac end. |
| 172 |
Abort. |
| 173 |
|
| 174 |
End WithLet. |
| 175 |
|
| 176 |
Module WithLetMutual. |
| 177 |
|
| 178 |
Section S. |
| 179 |
Context (a : nat) (b := 0) (c : nat). |
| 180 |
Fixpoint f n := match n with 0 => a + b + c | S n => g n end |
| 181 |
with g n := match n with 0 => a + b + c | S n => f n end. |
| 182 |
End S. |
| 183 |
|
| 184 |
Definition f' a c n := f a c n. |
| 185 |
|
| 186 |
Lemma L a c n : f' a c (S n) = f a c (S n). |
| 187 |
simpl. |
| 188 |
match goal with [ |- g a c n = g a c n ] => idtac end. |
| 189 |
Abort. |
| 190 |
|
| 191 |
End WithLetMutual. |
| 192 |
|
| 193 |
Module IotaTrigger1. |
| 194 |
|
| 195 |
Definition a x := match x with true => tt | false => tt end. |
| 196 |
Definition b x (y : unit) := a x. |
| 197 |
Definition c x := b x tt. |
| 198 |
Goal a true = tt. simpl. match goal with [ |- tt = tt ] => idtac end. Abort. |
| 199 |
Goal b true = fun _ => tt. simpl. match goal with [ |- b true = _ ] => idtac end. Abort. |
| 200 |
Goal c true = tt. simpl. match goal with [ |- tt = tt ] => idtac end. Abort. |
| 201 |
|
| 202 |
End IotaTrigger1. |
| 203 |
|
| 204 |
Module IotaTrigger2. |
| 205 |
|
| 206 |
Definition a x := match x with true => fun _ => tt | false => fun _ => tt end tt. |
| 207 |
Definition b x (y : unit) := a x. |
| 208 |
Definition c x := b x tt. |
| 209 |
Goal a true = tt. simpl. match goal with [ |- tt = tt ] => idtac end. Abort. |
| 210 |
Goal b true = fun _ => tt. simpl. match goal with [ |- b true = _ ] => idtac end. Abort. |
| 211 |
Goal c true = tt. simpl. match goal with [ |- tt = tt ] => idtac end. Abort. |
| 212 |
|
| 213 |
End IotaTrigger2. |
| 214 |
|
| 215 |
Module IotaTrigger3. |
| 216 |
|
| 217 |
Fixpoint f_fix_fun n := match n with 0 => fun _ : unit => true | S n => f_fix_fun n end. |
| 218 |
Definition test_fix_fun n := f_fix_fun n. |
| 219 |
Goal test_fix_fun 2 = fun _ => true. simpl. match goal with [ |- (fun _ => true) = _ ] => idtac end. Abort. |
| 220 |
Goal forall x, test_fix_fun (S x) = fun _ => true. intro. simpl. match goal with [ |- test_fix_fun x = _ ] => idtac end. Abort. |
| 221 |
(* REDUCED *) |
| 222 |
|
| 223 |
Definition test_fix_fun_partial n (x:unit) := f_fix_fun n. |
| 224 |
Goal test_fix_fun_partial 2 = fun _ _ => true. simpl. match goal with [ |- test_fix_fun_partial 2 = _ ] => idtac end. Abort. |
| 225 |
Goal forall x, test_fix_fun_partial (S x) = fun _ _ => true. intro. simpl. match goal with [ |- test_fix_fun_partial (S x) = _ ] => idtac end. Abort. |
| 226 |
(* NOT REDUCED: design choice that it is not enough fully applied to trigger the reduction *) |
| 227 |
(* remark: the presence of an inner "fun" does not matter *) |
| 228 |
|
| 229 |
Fixpoint f_fix n := match n with 0 => fun _ : unit => true | S n => f_fix n end. |
| 230 |
Definition test_fix n := f_fix n tt. |
| 231 |
Goal test_fix 2 = true. simpl. match goal with [ |- test_fix 2 = _ ] => idtac end. Abort. |
| 232 |
Goal forall x, test_fix (S x) = true. intro. simpl. match goal with [ |- test_fix (S x) = _ ] => idtac end. Abort. |
| 233 |
(* NOT REDUCED: design choice that we couldn't refold to test_fix after reduction *) |
| 234 |
|
| 235 |
Fixpoint f_mutual_fix n := match n with 0 => true | S n => g n end |
| 236 |
with g n := match n with 0 => true | S n => f_mutual_fix n end. |
| 237 |
Definition test_mutual_fix n := f_mutual_fix n. |
| 238 |
Goal test_mutual_fix 2 = true. simpl. match goal with [ |- true = _ ] => idtac end. Abort. |
| 239 |
Goal forall x, test_mutual_fix (S x) = true. intro. simpl. match goal with [ |- g x = _ ] => idtac end. Abort. |
| 240 |
(* REDUCED: design choice that mutual fixpoints refold to last encapsulating name *) |
| 241 |
|
| 242 |
Definition test_mutual_fix_partial n (x:unit) := f_mutual_fix n. |
| 243 |
Goal test_mutual_fix_partial 2 = fun _ => true. simpl. match goal with [ |- test_mutual_fix_partial 2 = _ ] => idtac end. Abort. |
| 244 |
Goal forall x, test_mutual_fix_partial (S x) = fun _ => true. intro. simpl. match goal with [ |- test_mutual_fix_partial (S x) = _ ] => idtac end. Abort. |
| 245 |
(* NOT REDUCED: design choice that it is not enough fully applied to trigger the reduction *) |
| 246 |
(* Moreover, was failing between #17993 and #18243 (see #18239) *) |
| 247 |
|
| 248 |
Fixpoint f_mutual_fix_cut n := match n with 0 => fun _ : unit => true | S n => g_cut n end |
| 249 |
with g_cut n := match n with 0 => fun _ : unit => true | S n => f_mutual_fix_cut n end. |
| 250 |
Definition test_mutual_fix_cut n := f_mutual_fix_cut n tt. |
| 251 |
Goal test_mutual_fix_cut 2 = true. simpl. match goal with [ |- true = _ ] => idtac end. Abort. |
| 252 |
Goal forall x, test_mutual_fix_cut (S x) = true. intro. simpl. match goal with [ |- g_cut x tt = _ ] => idtac end. Abort. |
| 253 |
(* REDUCED: by consistency with test_mutual_fix, which itself already differs from the case of a unary fix (new behavior from #18243) *) |
| 254 |
|
| 255 |
Definition test_mutual_fix_cut_partial n (x:unit) := f_mutual_fix_cut n x. |
| 256 |
Goal test_mutual_fix_cut_partial 2 = fun _ => true. simpl. match goal with [ |- test_mutual_fix_cut_partial 2 = _ ] => idtac end. Abort. |
| 257 |
Goal forall x, test_mutual_fix_cut_partial (S x) = fun _ => true. intro. simpl. match goal with [ |- test_mutual_fix_cut_partial (S x) = _ ] => idtac end. Abort. |
| 258 |
(* NOT REDUCED: by consistency with test_fix_fun_partial and test_mutual_fix_cut_partial *) |
| 259 |
(* Moreover was failing before #18243 (see #18239) *) |
| 260 |
|
| 261 |
Definition f_case n := match n with 0 => fun _ : unit => true | S n => fun _ => true end. |
| 262 |
Definition test_case n := f_case n tt. |
| 263 |
Goal test_case 2 = true. simpl. match goal with [ |- true = _ ] => idtac end. Abort. |
| 264 |
(* REDUCED *) |
| 265 |
|
| 266 |
End IotaTrigger3. |
| 267 |
|
| 268 |
Module Bug4056. |
| 269 |
|
| 270 |
CoInductive stream {A:Type} : Type := |
| 271 |
| scons: A->stream->stream. |
| 272 |
|
| 273 |
Definition stream_unfold {A} (s: @ stream A) := match s with |
| 274 |
| scons a s' => (a, scons a s') |
| 275 |
end. |
| 276 |
|
| 277 |
Section A. |
| 278 |
CoFixpoint inf_stream1 (x:nat) (n:nat) := |
| 279 |
scons n (inf_stream1 x (n+x)). |
| 280 |
End A. |
| 281 |
|
| 282 |
Section B. |
| 283 |
Variable (x:nat). |
| 284 |
CoFixpoint inf_stream2 (n:nat) := |
| 285 |
scons n (inf_stream2 (n+x)). |
| 286 |
End B. |
| 287 |
|
| 288 |
Goal (forall x n, stream_unfold (inf_stream1 x n) = stream_unfold (inf_stream2 x n)). |
| 289 |
(* simpl was exposing the cofix on the rhs but not the lhs *) |
| 290 |
intros. simpl. |
| 291 |
match goal with [ |- (n, scons n (inf_stream1 x (n + x))) = (n, scons n (inf_stream2 x (n + x))) ] => idtac end. |
| 292 |
Abort. |
| 293 |
|
| 294 |
Section C. |
| 295 |
Variable (x:nat). |
| 296 |
CoFixpoint mut_stream1 (n:nat) := scons n (mut_stream2 (n+x)) |
| 297 |
with mut_stream2 (n:nat) := scons n (mut_stream1 (n+x)). |
| 298 |
End C. |
| 299 |
|
| 300 |
Goal (forall x n, stream_unfold (mut_stream1 x n) = stream_unfold (mut_stream2 x n)). |
| 301 |
intros. simpl. |
| 302 |
match goal with [ |- (n, scons n (mut_stream2 x (n + x))) = (n, scons n (mut_stream1 x (n + x))) ] => idtac end. |
| 303 |
Abort. |
| 304 |
|
| 305 |
Definition inf_stream2_copy n := inf_stream2 n. (* inversible *) |
| 306 |
Definition mut_stream2_copy n := mut_stream2 n. (* inversible only towards mut_stream1/mut_stream2 *) |
| 307 |
|
| 308 |
Goal (forall x n, stream_unfold (inf_stream2_copy x n) = stream_unfold (mut_stream2_copy x n)). |
| 309 |
intros. simpl. |
| 310 |
match goal with [ |- (n, scons n (inf_stream2_copy x (n + x))) = (n, scons n (mut_stream1 x (n + x))) ] => idtac end. |
| 311 |
Abort. |
| 312 |
|
| 313 |
End Bug4056. |
| 314 |
|
| 315 |
Module RefoldingOfNeverConstantInArgOfDestructor. |
| 316 |
|
| 317 |
Arguments Nat.add : simpl never. |
| 318 |
Goal forall n, (S n + 1) * n = 0. |
| 319 |
intros. simpl. |
| 320 |
match goal with [ |- n + (n + 1) * n = 0 ] => idtac end. |
| 321 |
Abort. |
| 322 |
|
| 323 |
End RefoldingOfNeverConstantInArgOfDestructor. |