Debian Codegraph @

src/Util/ListUtil/SetoidListRev.v

raw
1 From Coq Require Import Lia.
2 From Coq Require Import Basics.
3 From Coq Require Import Sorted.
4 From Coq Require Import List.
5 From Coq Require Import SetoidList.
6 Import ListNotations.
7 Local Open Scope list_scope.
8
9 Lemma SortA_rev A R ls
10 : @Sorted A (flip R) ls -> @Sorted A R (List.rev ls).
11 Proof.
12 induction 1; cbn; [ constructor 1 | ].
13 let H := match goal with H : HdRel _ _ _ |- _ => H end in
14 destruct H; cbn in *; try solve [ repeat constructor ].
15 let l := match goal with |- Sorted _ ((rev ?l ++ _) ++ _) => l end in
16 induction (List.rev l) as [|x xs IH]; [ repeat constructor; assumption | ].
17 cbn in *.
18 invlist Sorted.
19 constructor; eauto.
20 set (ls := xs ++ _) in *.
21 assert (List.length ls > 0)
22 by (subst ls; rewrite app_length; cbn; lia).
23 let H := match goal with H : HdRel _ _ ls |- HdRel _ _ (ls ++ _) => H end in
24 destruct H; cbn in *; try solve [ repeat constructor; assumption ]; try lia.
25 Qed.
26
27 Lemma SortA_rev_iff A R ls
28 : @Sorted A R (List.rev ls) <-> @Sorted A (flip R) ls.
29 Proof.
30 rewrite <- (rev_involutive ls);
31 split; intro; apply SortA_rev; rewrite ?rev_involutive in *;
32 assumption.
33 Qed.