Advertisement
Guest User

Some junk

a guest
Jun 14th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. From iris.algebra Require Import excl auth list gmap agree csum.
  2. From iris.heap_lang Require Export lifting notation.
  3. From iris.base_logic.lib Require Export invariants proph_map.
  4. From iris.program_logic Require Export atomic.
  5. From iris.proofmode Require Import tactics.
  6. From iris.heap_lang Require Import proofmode notation par.
  7. From iris.bi.lib Require Import fractional.
  8. Set Default Proof Using "Type".
  9.  
  10. Lemma replicate_map {A B} (f : A → B) (n : nat) (e : A) :
  11. map f (replicate n e) = replicate n (f e).
  12. Proof. induction n as [|n IH]; simpl; [ done | by rewrite IH ]. Qed.
  13.  
  14. Lemma replicate_vec {A} n (e : A) :
  15. vec_to_list (vreplicate n e) = replicate n e.
  16. Proof. induction n as [|n IH]; first done. by rewrite /= IH. Qed.
  17.  
  18. Lemma vreplicate_get {A} n (e : A) (i : fin n) :
  19. vreplicate n e !!! i = e.
  20. Proof. induction i as [|n i IH]; [ done | by apply IH ]. Qed.
  21.  
  22. Lemma vreplicate_map {A B} (f : A → B) (n : nat) (e : A) :
  23. Vector.map f (vreplicate n e) = vreplicate n (f e).
  24. Proof. induction n as [|n IH]; simpl; [ done | by rewrite IH ]. Qed.
  25.  
  26. Lemma vinsert_map {A B} (f : A → B) (n : nat) (i : fin n) e (v : vec A n) :
  27. vmap f (vinsert i e v) = vinsert i (f e) (vmap f v).
  28. Proof.
  29. induction v as [|e' n v IH].
  30. - inversion i.
  31. - inv_fin i; first done. intros i. by rewrite /= (IH i).
  32. Qed.
  33.  
  34. Lemma take_map {A B} (n : nat) (f : A → B) (l : list A) :
  35. take n (map f l) = map f (take n l).
  36. Proof.
  37. revert n. induction l as [|e l IH]; intro n; first by destruct n.
  38. destruct n as [|n]; simpl; first done. by rewrite IH.
  39. Qed.
  40.  
  41. Definition vtake {A} {s : nat} (n : fin s) (v : vec A s) : vec A n.
  42. Proof.
  43. induction n as [|s' n IH]; first constructor. inv_vec v. intros e v.
  44. constructor. exact e. rewrite -/fin_to_nat. apply IH, v.
  45. Defined.
  46.  
  47. Definition vdrop {A} {s : nat} (n : fin s) (v : vec A s) : vec A (s - n).
  48. Proof.
  49. induction n as [|s' n IH]; first exact v. inv_vec v. intros e v.
  50. apply IH, v.
  51. Defined.
  52.  
  53. Lemma vtake_vdrop {A} (s : nat) (n : fin s) (v : vec A s) :
  54. vtake n v ++ vdrop n v = v.
  55. Proof.
  56. induction n as [|s' n IH]; first done. inv_vec v. intros e v.
  57. rewrite vec_to_list_cons.
  58. assert (vec_to_list (vtake (FS n) (e ::: v)) = e :: vtake n v) as -> by done.
  59. assert (vdrop (FS n) (e ::: v) = vdrop n v) as -> by done. simpl. by rewrite IH.
  60. Qed.
  61.  
  62. Lemma drop_map {A B} (n : nat) (f : A → B) (l : list A) :
  63. drop n (map f l) = map f (drop n l).
  64. Proof.
  65. revert n. induction l as [|e l IH]; intro n; first by destruct n.
  66. destruct n as [|n]; simpl; first done. by rewrite IH.
  67. Qed.
  68.  
  69. Lemma lookup_map {A B} (f : A → B) (l : list A) (n : nat) (e : A) :
  70. l !! n = Some e → map f l !! n = Some (f e).
  71. Proof.
  72. revert l. induction n as [|n IH]; intros l H.
  73. - destruct l; by inversion_clear H.
  74. - destruct l; first by inversion H. apply IH, H.
  75. Qed.
  76.  
  77. Lemma drop_cons {A} (e : A) (l l' : list A) (n : nat) :
  78. e :: l' = drop n l → l' = drop (S n) l.
  79. Proof.
  80. revert l.
  81. induction n as [|n IH]; intros l H; destruct l as [|e' l]; try done.
  82. - simpl in *. inversion_clear H. by rewrite drop_0.
  83. - simpl in *. apply IH, H.
  84. Qed.
  85.  
  86. Lemma min_lt_left (m n : nat) : (m `min` n < n ↔ m < n)%nat.
  87. Proof.
  88. split; intro H.
  89. - apply Nat.min_lt_iff in H.
  90. destruct H as [H|H]; [ done | by apply Nat.lt_irrefl in H ].
  91. - apply Nat.min_lt_iff. by left.
  92. Qed.
  93.  
  94. Lemma drop_tail {A} (n : nat) (e : A) (l1 l2 : list A) :
  95. drop n l1 = e :: l2 → drop (S n) l1 = l2.
  96. Proof.
  97. revert e l1 l2. induction n; intros e l1 l2 H.
  98. - rewrite drop_0 in H. by subst l1.
  99. - destruct l1 as [|f l1]; first by inversion H. by apply IHn in H.
  100. Qed.
  101.  
  102. Lemma drop_absurd {A} (off : nat) (l : list A) :
  103. (off < length l)%nat → ¬ (drop off l = []).
  104. Proof.
  105. revert off. induction l as [|e l IH]; intros off H1 H2.
  106. - inversion H1.
  107. - destruct off as [|off]; first by inversion H2.
  108. simpl in H2. refine (IH off _ H2). simpl in H1. omega.
  109. Qed.
  110.  
  111. Lemma back_drop_insert {A} (off : nat) (l : list A) (v : A) :
  112. (off < length l)%nat → take off l ++ v :: drop (S off) l = <[off:=v]> l.
  113. Proof.
  114. intro H. rewrite -[in X in _ = X](take_drop off l).
  115. assert (off = length (take off l) + 0)%nat as Hoff.
  116. { rewrite take_length. rewrite min_l; first done. omega. }
  117. rewrite [in X in <[X:=_]> _]Hoff insert_app_r. clear Hoff.
  118. assert (v :: drop (S off) l = <[0%nat:=v]> (drop off l)) as ->; last done.
  119. destruct (drop off l) eqn:HEq; simpl.
  120. - by apply drop_absurd in HEq.
  121. - apply drop_tail in HEq. by subst.
  122. Qed.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement