Coq realization for theory seq.Seq (WIP)

parent 4312fc27
...@@ -140,31 +140,23 @@ Lemma cons_get : forall {a:Type} {a_WT:WhyType a}, forall (x:a) (s:(seq a)) ...@@ -140,31 +140,23 @@ Lemma cons_get : forall {a:Type} {a_WT:WhyType a}, forall (x:a) (s:(seq a))
(i:Z), ((0%Z <= i)%Z /\ (i <= (length s))%Z) -> (((i = 0%Z) -> (i:Z), ((0%Z <= i)%Z /\ (i <= (length s))%Z) -> (((i = 0%Z) ->
((mixfix_lbrb (cons x s) i) = x)) /\ ((~ (i = 0%Z)) -> ((mixfix_lbrb (cons x s) i) = x)) /\ ((~ (i = 0%Z)) ->
((mixfix_lbrb (cons x s) i) = (mixfix_lbrb s (i - 1%Z)%Z)))). ((mixfix_lbrb (cons x s) i) = (mixfix_lbrb s (i - 1%Z)%Z)))).
(*
intros a (d,eq) x s i hi. intros a (d,eq) x s i hi.
split; intros. split.
subst i. unfold mixfix_lbrb. auto. intro; subst i; now auto.
unfold mixfix_lbrb. simpl.
destruct s. destruct s.
unfold List.nth, default, elts; simpl; auto. simpl in hi. intro. absurd (i=0)%Z; omega.
destruct s; unfold mixfix_lbrb; simpl. intro h.
destruct (Z.abs_nat i) eqn:?. unfold mixfix_lbrb at 1.
(* i = 0 *) simpl ((fix nth (n : int) (l : list a) {struct l} : a :=
assert (i = 0)%Z. match l with
assert (O < Z.abs_nat i)%nat. | nil => d
rewrite <- Zabs2Nat.inj_0. | (h0 :: t)%list => if Zeq_bool n 0 then h0 else nth (n - 1)%Z t
apply Zabs_nat_lt. omega. omega. omega. end) i (cons x (a0 :: s)%list)).
(* i = S n *) destruct (Zeq_bool i 0) eqn:? in *.
replace (Z.abs_nat (i - 1)) with n. generalize (Zeq_bool_eq _ _ Heqb). now intuition.
reflexivity. auto.
assert (i = Zsucc (i-1))%Z by omega.
rewrite H0 in Heqn.
rewrite Zabs2Nat.inj_succ in Heqn.
injection Heqn; auto.
omega.
Qed. Qed.
*)
Admitted. (* TODO *)
(* Why3 goal *) (* Why3 goal *)
Definition snoc: forall {a:Type} {a_WT:WhyType a}, (seq a) -> a -> (seq a). Definition snoc: forall {a:Type} {a_WT:WhyType a}, (seq a) -> a -> (seq a).
...@@ -172,19 +164,26 @@ intros a aWT s x. ...@@ -172,19 +164,26 @@ intros a aWT s x.
exact (s ++ List.cons x nil)%list. exact (s ++ List.cons x nil)%list.
Defined. Defined.
Open Scope list_scope.
Open Scope Z_scope.
Lemma length_append:
forall {a:Type} {a_WT:WhyType a} s1 s2, length (s1 ++ s2) = length s1 + length s2.
induction s1.
auto.
intro s2. simpl ((a0 :: s1) ++ s2).
unfold length; fold length.
rewrite IHs1; omega.
Qed.
(* Why3 goal *) (* Why3 goal *)
Lemma snoc_length : forall {a:Type} {a_WT:WhyType a}, forall (s:(seq a)) Lemma snoc_length : forall {a:Type} {a_WT:WhyType a}, forall (s:(seq a))
(x:a), ((length (snoc s x)) = (1%Z + (length s))%Z). (x:a), ((length (snoc s x)) = (1%Z + (length s))%Z).
(* intros.
intros a a_WT (l, d) x. unfold snoc.
unfold length, snoc, elts. rewrite length_append.
rewrite List.app_length. simpl (length (x::nil)). omega.
simpl Datatypes.length.
rewrite Nat2Z.inj_add.
auto with *.
Qed. Qed.
*)
Admitted. (* TODO *)
(* Why3 goal *) (* Why3 goal *)
Lemma snoc_get : forall {a:Type} {a_WT:WhyType a}, forall (s:(seq a)) (x:a) Lemma snoc_get : forall {a:Type} {a_WT:WhyType a}, forall (s:(seq a)) (x:a)
...@@ -281,18 +280,43 @@ intros a a_WT s1 s2 i (h1,h2). ...@@ -281,18 +280,43 @@ intros a a_WT s1 s2 i (h1,h2).
Admitted. (* TODO *) Admitted. (* TODO *)
Fixpoint enum {a:Type} (f: Z -> a) (start: Z) (n: nat) : seq a :=
match n with
| O => nil
| S p => (f start :: enum f (start+1)%Z p)%list end.
(* Why3 goal *) (* Why3 goal *)
Definition create: forall {a:Type} {a_WT:WhyType a}, Z -> (Z -> a) -> (seq Definition create: forall {a:Type} {a_WT:WhyType a}, Z -> (Z -> a) -> (seq
a). a).
intros a a_WT n f.
exact (if Zlt_bool n 0 then nil else enum f 0%Z (Zabs_nat n)).
Defined.
Admitted. (* TODO *) Lemma enum_length:
forall {a:Type} {a_WT:WhyType a} (f: Z -> a) n start,
length (enum f start n) = Z.of_nat n.
induction n; intros.
now auto.
unfold enum. fold (enum f).
unfold length. fold length.
rewrite IHn.
rewrite Nat2Z.inj_succ. auto with *.
Qed.
(* Why3 goal *) (* Why3 goal *)
Lemma create_length : forall {a:Type} {a_WT:WhyType a}, forall (len:Z) Lemma create_length : forall {a:Type} {a_WT:WhyType a}, forall (len:Z)
(f:(Z -> a)), (0%Z <= len)%Z -> ((length (create len f)) = len). (f:(Z -> a)), (0%Z <= len)%Z -> ((length (create len f)) = len).
intros a a_WT len f h1. intros a a_WT len f h1.
unfold create.
Admitted. (* TODO *) generalize (Z.ltb_lt len 0).
destruct (Zlt_bool len 0) eqn:?.
intuition.
intros _. clear Heqb.
rewrite enum_length.
rewrite Zabs2Nat.abs_nat_nonneg.
apply Z2Nat.id; auto.
assumption.
Qed.
(* Why3 goal *) (* Why3 goal *)
Lemma create_get : forall {a:Type} {a_WT:WhyType a}, forall (len:Z) (f:(Z -> Lemma create_get : forall {a:Type} {a_WT:WhyType a}, forall (len:Z) (f:(Z ->
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment