Coq case analysis and rewrite with function returning subset types -
i working simple exercise writing certified function using subset types. idea first write predecessor function
pred : forall (n : {n : nat | n > 0}), {m : nat | s m = n.1}.
and using definition give funtion
pred2 : forall (n : {n : nat | n > 1}), {m : nat | s (s m) = n.1}.
i have no problem first one. here code
program definition pred (n : {n : nat | n > 0}) : {m : nat | s m = n.1} := match n | o => _ | s n' => n' end. next obligation. elimtype false. compute in h. inversion h. qed.
but cannot workout second definition. trying write these definition
program definition pred2 (n : {n : nat | n > 1}) : {m : nat | s (s m) = n.1} := pred (pred n).
i managed prove 2 first obligations
next obligation. apply (gt_trans n 1 0). assumption. auto. qed. next obligation. destruct pred. simpl. simpl in e. rewrite <- e in h. apply gt_s_n in h; assumption. qed.
but last obligation stuck because when try case analysis return type of pred new hypotesis not rewrited in goal.
i tried following tactics no results.
destruct (pred (n: pred2_obligation_1 (n ; h))). destruct (pred (n; pred2_obligation_1 (n ; h))) eqn:?. rewrite heqs.
i know can write pred2 directly, idea use , compose function pred.
the reason destruct
doesn't have effect because you're trying case analysis on doesn't occur in goal. implicit arguments of term don't match implicit arguments of term in goal. either way, can't case analysis on term without making goal ill-typed.
but can prove obligation case analysis on n
.
next obligation. destruct n. inversion h. destruct n. inversion h. subst. inversion h1. cbn. eauto. qed.
i able prove helper theorems, wasn't able use them because of type dependency.
theorem t1 : forall s1, s (` (pred s1)) = ` s1. proof. intros [[| n1] h1]. inversion h1. cbn. eauto. qed. theorem t2 : forall t1 (p1 : t1 -> prop) s1 h1, (forall x1 (h1 h2 : p1 x1), h1 = h2) -> exist p1 (` s1) h1 = s1. proof. intros ? ? [x1 h1] h2 h3. cbn in *. rewrite (h3 _ h1 h2). eauto. qed.
i had never seen destruct
used on function. i'm surprised coq doesn't complain that function isn't inductively defined.
Comments
Post a Comment