| 1 |
|
| 2 |
(* Refine and let-in's *) |
| 3 |
|
| 4 |
Goal exists x : nat, x = 0. |
| 5 |
refine (let y := 0 + 0 in _). |
| 6 |
exists y; auto. |
| 7 |
Save test1. |
| 8 |
|
| 9 |
Goal exists x : nat, x = 0. |
| 10 |
refine (let y := 0 + 0 in ex_intro _ (y + y) _). |
| 11 |
auto. |
| 12 |
Save test2. |
| 13 |
|
| 14 |
Goal nat. |
| 15 |
refine (let y := 0 in 0 + _). |
| 16 |
exact 1. |
| 17 |
Save test3. |
| 18 |
|
| 19 |
(* Example submitted by Yves on coqdev *) |
| 20 |
|
| 21 |
Goal forall l : list nat, l = l. |
| 22 |
Proof. |
| 23 |
refine |
| 24 |
(fun l => |
| 25 |
match l return (l = l) with |
| 26 |
| nil => _ |
| 27 |
| cons O l0 => _ |
| 28 |
| cons (S _) l0 => _ |
| 29 |
end). |
| 30 |
Abort. |
| 31 |
|
| 32 |
(* Submitted by Roland Zumkeller (BZ#888) *) |
| 33 |
|
| 34 |
(* The Fix and CoFix rules expect a subgoal even for closed components of the |
| 35 |
(co-)fixpoint *) |
| 36 |
|
| 37 |
Goal nat -> nat. |
| 38 |
refine (fix f (n : nat) : nat := S _ |
| 39 |
with pred (n : nat) : nat := n |
| 40 |
for f). |
| 41 |
exact 0. |
| 42 |
Qed. |
| 43 |
|
| 44 |
(* Submitted by Roland Zumkeller (BZ#889) *) |
| 45 |
|
| 46 |
(* The types of metas were in metamap and they were not updated when |
| 47 |
passing through a binder *) |
| 48 |
|
| 49 |
Goal forall n : nat, nat -> n = 0. |
| 50 |
refine |
| 51 |
(fun n => fix f (i : nat) : n = 0 := match i with |
| 52 |
| O => _ |
| 53 |
| S _ => _ |
| 54 |
end). |
| 55 |
Abort. |
| 56 |
|
| 57 |
(* Submitted by Roland Zumkeller (BZ#931) *) |
| 58 |
(* Don't turn dependent evar into metas *) |
| 59 |
|
| 60 |
Goal (forall n : nat, n = 0 -> Prop) -> Prop. |
| 61 |
intro P. |
| 62 |
refine (P _ _). |
| 63 |
reflexivity. |
| 64 |
Abort. |
| 65 |
|
| 66 |
(* Submitted by Jacek Chrzaszcz (BZ#1102) *) |
| 67 |
|
| 68 |
(* le problème a été résolu ici par normalisation des evars présentes |
| 69 |
dans les types d'evars, mais le problème reste a priori ouvert dans |
| 70 |
le cas plus général d'evars non instanciées dans les types d'autres |
| 71 |
evars *) |
| 72 |
|
| 73 |
Goal exists n:nat, n=n. |
| 74 |
refine (ex_intro _ _ _). |
| 75 |
Abort. |
| 76 |
|
| 77 |
(* Used to failed with error not clean *) |
| 78 |
|
| 79 |
Definition div : |
| 80 |
forall x:nat, (forall y:nat, forall n:nat, {q:nat | y = q*n}) -> |
| 81 |
forall n:nat, {q:nat | x = q*n}. |
| 82 |
refine |
| 83 |
(fun m div_rec n => |
| 84 |
match div_rec m n with |
| 85 |
| exist _ _ _ => _ |
| 86 |
end). |
| 87 |
Abort. |
| 88 |
|
| 89 |
|
| 90 |
(* Use to fail because sigma was not propagated to get_type_of *) |
| 91 |
(* Revealed by r9310, fixed in r9359 *) |
| 92 |
|
| 93 |
Goal |
| 94 |
forall f : forall a (H:a=a), Prop, |
| 95 |
(forall a (H:a = a :> nat), f a H -> True /\ True) -> |
| 96 |
True. |
| 97 |
intros. |
| 98 |
refine (@proj1 _ _ (H 0 _ _)). |
| 99 |
Abort. |
| 100 |
|
| 101 |
(* Use to fail because let-in with metas in the body where rejected |
| 102 |
because a priori considered as dependent *) |
| 103 |
|
| 104 |
Require Import TestSuite.arith. |
| 105 |
|
| 106 |
Definition fact_F : |
| 107 |
forall (n:nat), |
| 108 |
(forall m, m<n -> nat) -> |
| 109 |
nat. |
| 110 |
refine |
| 111 |
(fun n fact_rec => |
| 112 |
if eq_nat_dec n 0 then |
| 113 |
1 |
| 114 |
else |
| 115 |
let fn := fact_rec (n-1) _ in |
| 116 |
n * fn). |
| 117 |
Abort. |
| 118 |
|
| 119 |
(* Wish 1988: that fun forces unfold in refine *) |
| 120 |
|
| 121 |
Goal (forall A : Prop, A -> ~~A). |
| 122 |
Proof. refine(fun A a f => _). Abort. |
| 123 |
|
| 124 |
(* Checking beta-iota normalization of hypotheses in created evars *) |
| 125 |
|
| 126 |
Goal {x|x=0} -> True. |
| 127 |
refine (fun y => let (x,a) := y in _). |
| 128 |
match goal with a:_=0 |- _ => idtac end. |
| 129 |
Abort. |
| 130 |
|
| 131 |
Goal (forall P, {P 0}+{P 1}) -> True. |
| 132 |
refine (fun H => if H (fun x => x=x) then _ else _). |
| 133 |
match goal with _:0=0 |- _ => idtac end. |
| 134 |
Abort. |