fact
stringlengths
8
1.54k
type
stringclasses
19 values
library
stringclasses
8 values
imports
listlengths
1
10
filename
stringclasses
98 values
symbolic_name
stringlengths
1
42
docstring
stringclasses
1 value
cycle_maps : cycle e' (map f s) = cycle (relpre f e') s. Proof. by case: s => //= ? ?; rewrite -map_rcons path_map. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
cycle_map
sorted_maps : sorted e' (map f s) = sorted (relpre f e') s. Proof. by case: s; last apply: path_map. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sorted_map
homo_path_inx s : {in P &, {homo f : x y / e x y >-> e' x y}} -> all P (x :: s) -> path e x s -> path e' (f x) (map f s). Proof. by move=> f_mono; rewrite path_map; apply: sub_in_path. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
homo_path_in
homo_cycle_ins : {in P &, {homo f : x y / e x y >-> e' x y}} -> all P s -> cycle e s -> cycle e' (map f s). Proof. by move=> f_mono; rewrite cycle_map; apply: sub_in_cycle. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
homo_cycle_in
homo_sorted_ins : {in P &, {homo f : x y / e x y >-> e' x y}} -> all P s -> sorted e s -> sorted e' (map f s). Proof. by move=> f_mono; rewrite sorted_map; apply: sub_in_sorted. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
homo_sorted_in
mono_path_inx s : {in P &, {mono f : x y / e x y >-> e' x y}} -> all P (x :: s) -> path e' (f x) (map f s) = path e x s. Proof. by move=> f_mono; rewrite path_map; apply: eq_in_path. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mono_path_in
mono_cycle_ins : {in P &, {mono f : x y / e x y >-> e' x y}} -> all P s -> cycle e' (map f s) = cycle e s. Proof. by move=> f_mono; rewrite cycle_map; apply: eq_in_cycle. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mono_cycle_in
mono_sorted_ins : {in P &, {mono f : x y / e x y >-> e' x y}} -> all P s -> sorted e' (map f s) = sorted e s. Proof. by case: s => // x s; apply: mono_path_in. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mono_sorted_in
homo_pathx s : {homo f : x y / e x y >-> e' x y} -> path e x s -> path e' (f x) (map f s). Proof. by move=> f_homo; rewrite path_map; apply: sub_path. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
homo_path
homo_cycle: {homo f : x y / e x y >-> e' x y} -> {homo map f : s / cycle e s >-> cycle e' s}. Proof. by move=> f_homo s hs; rewrite cycle_map (sub_cycle _ hs). Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
homo_cycle
homo_sorted: {homo f : x y / e x y >-> e' x y} -> {homo map f : s / sorted e s >-> sorted e' s}. Proof. by move/homo_path => ? []. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
homo_sorted
mono_pathx s : {mono f : x y / e x y >-> e' x y} -> path e' (f x) (map f s) = path e x s. Proof. by move=> f_mon; rewrite path_map; apply: eq_path. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mono_path
mono_cycle: {mono f : x y / e x y >-> e' x y} -> {mono map f : s / cycle e s >-> cycle e' s}. Proof. by move=> ? ?; rewrite cycle_map; apply: eq_cycle. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mono_cycle
mono_sorted: {mono f : x y / e x y >-> e' x y} -> {mono map f : s / sorted e s >-> sorted e' s}. Proof. by move=> f_mon [] //= x s; apply: mono_path. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mono_sorted
cycle_all2rel(T : Type) (leT : rel T) : transitive leT -> forall s, cycle leT s = all2rel leT s. Proof. move=> leT_tr; elim=> //= x s IHs. rewrite allrel_cons2 -{}IHs // (path_sortedE leT_tr) /= all_rcons -rev_sorted. rewrite rev_rcons /= (path_sortedE (rev_trans leT_tr)) all_rev !andbA. case: (boolP (leT x x && _ && _)) => //=. case: s => //= y s /and3P[/and3P[_ xy _] yx sx]. rewrite rev_sorted rcons_path /= (leT_tr _ _ _ _ xy) ?andbT //. by case: (lastP s) sx => //= {}s z; rewrite all_rcons last_rcons => /andP [->]. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
cycle_all2rel
cycle_all2rel_in(T : Type) (P : {pred T}) (leT : rel T) : {in P & &, transitive leT} -> forall s, all P s -> cycle leT s = all2rel leT s. Proof. move=> /in3_sig leT_tr _ /all_sigP [s ->]. by rewrite cycle_map allrel_mapl allrel_mapr; apply: cycle_all2rel. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
cycle_all2rel_in
prefix_pathx s1 s2 : prefix s1 s2 -> path x s2 -> path x s1. Proof. by rewrite prefixE => /eqP <-; exact: take_path. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
prefix_path
prefix_sorteds1 s2 : prefix s1 s2 -> sorted s2 -> sorted s1. Proof. by rewrite prefixE => /eqP <-; exact: take_sorted. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
prefix_sorted
infix_sorteds1 s2 : infix s1 s2 -> sorted s2 -> sorted s1. Proof. by rewrite infixE => /eqP <- ?; apply/take_sorted/drop_sorted. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
infix_sorted
suffix_sorteds1 s2 : suffix s1 s2 -> sorted s2 -> sorted s1. Proof. by rewrite suffixE => /eqP <-; exact: drop_sorted. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
suffix_sorted
subseq_path_inx s1 s2 : {in x :: s2 & &, transitive leT} -> subseq s1 s2 -> path x s2 -> path x s1. Proof. by move=> tr /subseqP [m _ ->]; apply/(path_mask_in tr). Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
subseq_path_in
subseq_sorted_ins1 s2 : {in s2 & &, transitive leT} -> subseq s1 s2 -> sorted s2 -> sorted s1. Proof. by move=> tr /subseqP [m _ ->]; apply/(sorted_mask_in tr). Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
subseq_sorted_in
sorted_ltn_index_ins : {in s & &, transitive leT} -> sorted s -> {in s &, forall x y, index x s < index y s -> leT x y}. Proof. case: s => // x0 s' leT_tr s_sorted x y xs ys. move/(sorted_ltn_nth_in leT_tr x0 (allss (_ :: _)) s_sorted). by rewrite ?nth_index ?[_ \in gtn _]index_mem //; apply. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sorted_ltn_index_in
sorted_leq_index_ins : {in s & &, transitive leT} -> {in s, reflexive leT} -> sorted s -> {in s &, forall x y, index x s <= index y s -> leT x y}. Proof. case: s => // x0 s' leT_tr leT_refl s_sorted x y xs ys. move/(sorted_leq_nth_in leT_tr leT_refl x0 (allss (_ :: _)) s_sorted). by rewrite ?nth_index ?[_ \in gtn _]index_mem //; apply. Qed. Hypothesis leT_tr : transitive leT.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sorted_leq_index_in
subseq_pathx s1 s2 : subseq s1 s2 -> path x s2 -> path x s1. Proof. by apply: subseq_path_in; apply: in3W. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
subseq_path
subseq_sorteds1 s2 : subseq s1 s2 -> sorted s2 -> sorted s1. Proof. by apply: subseq_sorted_in; apply: in3W. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
subseq_sorted
sorted_uniq: irreflexive leT -> forall s, sorted s -> uniq s. Proof. by move=> irr s; rewrite sorted_pairwise //; apply/pairwise_uniq. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sorted_uniq
sorted_eq: antisymmetric leT -> forall s1 s2, sorted s1 -> sorted s2 -> perm_eq s1 s2 -> s1 = s2. Proof. by move=> leT_asym s1 s2; rewrite !sorted_pairwise //; apply: pairwise_eq. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sorted_eq
irr_sorted_eq: irreflexive leT -> forall s1 s2, sorted s1 -> sorted s2 -> s1 =i s2 -> s1 = s2. Proof. move=> leT_irr s1 s2 s1_sort s2_sort eq_s12. have: antisymmetric leT. by move=> m n /andP[? ltnm]; case/idP: (leT_irr m); apply: leT_tr ltnm. by move/sorted_eq; apply=> //; apply: uniq_perm => //; apply: sorted_uniq. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
irr_sorted_eq
sorted_ltn_indexs : sorted s -> {in s &, forall x y, index x s < index y s -> leT x y}. Proof. case: s => // x0 s' s_sorted x y xs ys /(sorted_ltn_nth leT_tr x0 s_sorted). by rewrite ?nth_index ?[_ \in gtn _]index_mem //; apply. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sorted_ltn_index
undup_pathx s : path x s -> path x (undup s). Proof. exact/subseq_path/undup_subseq. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
undup_path
undup_sorteds : sorted s -> sorted (undup s). Proof. exact/subseq_sorted/undup_subseq. Qed. Hypothesis leT_refl : reflexive leT.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
undup_sorted
sorted_leq_indexs : sorted s -> {in s &, forall x y, index x s <= index y s -> leT x y}. Proof. case: s => // x0 s' s_sorted x y xs ys. move/(sorted_leq_nth leT_tr leT_refl x0 s_sorted). by rewrite ?nth_index ?[_ \in gtn _]index_mem //; apply. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sorted_leq_index
sorted_uniq_ins : {in s & &, transitive leT} -> {in s, irreflexive leT} -> sorted leT s -> uniq s. Proof. move=> /in3_sig leT_tr /in1_sig leT_irr; case/all_sigP: (allss s) => s' ->. by rewrite sorted_map (map_inj_uniq val_inj); exact: sorted_uniq. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sorted_uniq_in
sorted_eq_ins1 s2 : {in s1 & &, transitive leT} -> {in s1 &, antisymmetric leT} -> sorted leT s1 -> sorted leT s2 -> perm_eq s1 s2 -> s1 = s2. Proof. move=> /in3_sig leT_tr /in2_sig/(_ _ _ _)/val_inj leT_anti + + /[dup] s1s2. have /all_sigP[s1' ->] := allss s1. have /all_sigP[{s1s2}s2 ->] : all [in s1] s2 by rewrite -(perm_all _ s1s2). by rewrite !sorted_map => ss1' ss2 /(perm_map_inj val_inj)/(sorted_eq leT_tr)->. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sorted_eq_in
irr_sorted_eq_ins1 s2 : {in s1 & &, transitive leT} -> {in s1, irreflexive leT} -> sorted leT s1 -> sorted leT s2 -> s1 =i s2 -> s1 = s2. Proof. move=> /in3_sig leT_tr /in1_sig leT_irr + + /[dup] s1s2. have /all_sigP[s1' ->] := allss s1. have /all_sigP[s2' ->] : all [in s1] s2 by rewrite -(eq_all_r s1s2). rewrite !sorted_map => ss1' ss2' {}s1s2; congr map. by apply: (irr_sorted_eq leT_tr) => // x; rewrite -!(mem_map val_inj). Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
irr_sorted_eq_in
splitx : seq T -> seq T -> seq T -> Type := Split p1 p2 : split x (rcons p1 x ++ p2) p1 p2.
Variant
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
split
splitPp x (i := index x p) : x \in p -> split x p (take i p) (drop i.+1 p). Proof. by rewrite -has_pred1 => /split_find[? ? ? /eqP->]; constructor. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
splitP
splitlx1 x : seq T -> Type := Splitl p1 p2 of last x1 p1 = x : splitl x1 x (p1 ++ p2).
Variant
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
splitl
splitPlx1 p x : x \in x1 :: p -> splitl x1 x p. Proof. rewrite inE; case: eqP => [->| _ /splitP[]]; first by rewrite -(cat0s p). by split; apply: last_rcons. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
splitPl
splitrx : seq T -> Type := Splitr p1 p2 : splitr x (p1 ++ x :: p2).
Variant
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
splitr
splitPrp x : x \in p -> splitr x p. Proof. by case/splitP=> p1 p2; rewrite cat_rcons. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
splitPr
next_atx y0 y p := match p with | [::] => if x == y then y0 else x | y' :: p' => if x == y then y' else next_at x y0 y' p' end.
Fixpoint
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
next_at
nextp x := if p is y :: p' then next_at x y y p' else x.
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
next
prev_atx y0 y p := match p with | [::] => if x == y0 then y else x | y' :: p' => if x == y' then y else prev_at x y0 y' p' end.
Fixpoint
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
prev_at
prevp x := if p is y :: p' then prev_at x y y p' else x.
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
prev
next_nthp x : next p x = if x \in p then if p is y :: p' then nth y p' (index x p) else x else x. Proof. case: p => //= y0 p. elim: p {2 3 5}y0 => [|y' p IHp] y /=; rewrite (eq_sym y) inE; by case: ifP => // _; apply: IHp. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
next_nth
prev_nthp x : prev p x = if x \in p then if p is y :: p' then nth y p (index x p') else x else x. Proof. case: p => //= y0 p; rewrite inE orbC. elim: p {2 5}y0 => [|y' p IHp] y; rewrite /= ?inE // (eq_sym y'). by case: ifP => // _; apply: IHp. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
prev_nth
mem_nextp x : (next p x \in p) = (x \in p). Proof. rewrite next_nth; case p_x: (x \in p) => //. case: p (index x p) p_x => [|y0 p'] //= i _; rewrite inE. have [lt_ip | ge_ip] := ltnP i (size p'); first by rewrite orbC mem_nth. by rewrite nth_default ?eqxx. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem_next
mem_prevp x : (prev p x \in p) = (x \in p). Proof. rewrite prev_nth; case p_x: (x \in p) => //; case: p => [|y0 p] // in p_x *. by apply mem_nth; rewrite /= ltnS index_size. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem_prev
ucyclebp := cycle e p && uniq p.
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
ucycleb
ucyclep : Prop := cycle e p && uniq p.
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
ucycle
ucycle_cyclep : ucycle p -> cycle e p. Proof. by case/andP. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
ucycle_cycle
ucycle_uniqp : ucycle p -> uniq p. Proof. by case/andP. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
ucycle_uniq
next_cyclep x : cycle e p -> x \in p -> e x (next p x). Proof. case: p => //= y0 p; elim: p {1 3 5}y0 => [|z p IHp] y /=; rewrite inE. by rewrite andbT; case: (x =P y) => // ->. by case/andP=> eyz /IHp; case: (x =P y) => // ->. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
next_cycle
prev_cyclep x : cycle e p -> x \in p -> e (prev p x) x. Proof. case: p => //= y0 p; rewrite inE orbC. elim: p {1 5}y0 => [|z p IHp] y /=; rewrite ?inE. by rewrite andbT; case: (x =P y0) => // ->. by case/andP=> eyz /IHp; case: (x =P z) => // ->. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
prev_cycle
rot_ucyclep : ucycle (rot n0 p) = ucycle p. Proof. by rewrite /ucycle rot_uniq rot_cycle. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
rot_ucycle
rotr_ucyclep : ucycle (rotr n0 p) = ucycle p. Proof. by rewrite /ucycle rotr_uniq rotr_cycle. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
rotr_ucycle
mem2p x y := y \in drop (index x p) p.
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2
mem2lp x y : mem2 p x y -> x \in p. Proof. by rewrite /mem2 -!index_mem size_drop ltn_subRL; apply/leq_ltn_trans/leq_addr. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2l
mem2lf{p x y} : x \notin p -> mem2 p x y = false. Proof. exact/contraNF/mem2l. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2lf
mem2rp x y : mem2 p x y -> y \in p. Proof. by rewrite -[in y \in p](cat_take_drop (index x p) p) mem_cat orbC /mem2 => ->. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2r
mem2rf{p x y} : y \notin p -> mem2 p x y = false. Proof. exact/contraNF/mem2r. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2rf
mem2_catp1 p2 x y : mem2 (p1 ++ p2) x y = mem2 p1 x y || mem2 p2 x y || (x \in p1) && (y \in p2). Proof. rewrite [LHS]/mem2 index_cat fun_if if_arg !drop_cat addKn. case: ifPn => [p1x | /mem2lf->]; last by rewrite ltnNge leq_addr orbF. by rewrite index_mem p1x mem_cat -orbA (orb_idl (@mem2r _ _ _)). Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2_cat
mem2_splicep1 p3 x y p2 : mem2 (p1 ++ p3) x y -> mem2 (p1 ++ p2 ++ p3) x y. Proof. by rewrite !mem2_cat mem_cat andb_orr orbC => /or3P[]->; rewrite ?orbT. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2_splice
mem2_splice1p1 p3 x y z : mem2 (p1 ++ p3) x y -> mem2 (p1 ++ z :: p3) x y. Proof. exact: mem2_splice [::z]. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2_splice1
mem2_consx p y z : mem2 (x :: p) y z = (if x == y then z \in x :: p else mem2 p y z). Proof. by rewrite [LHS]/mem2 /=; case: ifP. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2_cons
mem2_seq1x y z : mem2 [:: x] y z = (y == x) && (z == x). Proof. by rewrite mem2_cons eq_sym inE. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2_seq1
mem2_lasty0 p x : mem2 p x (last y0 p) = (x \in p). Proof. apply/idP/idP; first exact: mem2l; rewrite -index_mem /mem2 => p_x. by rewrite -nth_last -(subnKC p_x) -nth_drop mem_nth // size_drop subnSK. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2_last
mem2l_cat{p1 p2 x} : x \notin p1 -> mem2 (p1 ++ p2) x =1 mem2 p2 x. Proof. by move=> p1'x y; rewrite mem2_cat (negPf p1'x) mem2lf ?orbF. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2l_cat
mem2r_cat{p1 p2 x y} : y \notin p2 -> mem2 (p1 ++ p2) x y = mem2 p1 x y. Proof. by move=> p2'y; rewrite mem2_cat (negPf p2'y) -orbA orbC andbF mem2rf. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2r_cat
mem2lr_splice{p1 p2 p3 x y} : x \notin p2 -> y \notin p2 -> mem2 (p1 ++ p2 ++ p3) x y = mem2 (p1 ++ p3) x y. Proof. move=> p2'x p2'y; rewrite catA !mem2_cat !mem_cat. by rewrite (negPf p2'x) (negPf p2'y) (mem2lf p2'x) andbF !orbF. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2lr_splice
mem2Es x y : mem2 s x y = subseq (if x == y then [:: x] else [:: x; y]) s. Proof. elim: s => [| h s]; first by case: ifP. rewrite mem2_cons => ->. do 2 rewrite inE (fun_if subseq) !if_arg !sub1seq /=. by have [->|] := eqVneq; case: eqVneq. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2E
split2rx y : seq T -> Type := Split2r p1 p2 of y \in x :: p2 : split2r x y (p1 ++ x :: p2).
Variant
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
split2r
splitP2rp x y : mem2 p x y -> split2r x y p. Proof. move=> pxy; have px := mem2l pxy. have:= pxy; rewrite /mem2 (drop_nth x) ?index_mem ?nth_index //. by case/splitP: px => p1 p2; rewrite cat_rcons. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
splitP2r
shortenx p := if p is y :: p' then if x \in p then shorten x p' else y :: shorten y p' else [::].
Fixpoint
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
shorten
shorten_specx p : T -> seq T -> Type := ShortenSpec p' of path e x p' & uniq (x :: p') & {subset p' <= p} : shorten_spec x p (last x p') p'.
Variant
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
shorten_spec
shortenPx p : path e x p -> shorten_spec x p (last x p) (shorten x p). Proof. move=> e_p; have: x \in x :: p by apply: mem_head. elim: p x {1 3 5}x e_p => [|y2 p IHp] x y1. by rewrite mem_seq1 => _ /eqP->. rewrite inE orbC /= => /andP[ey12 {}/IHp IHp]. case: ifPn => [y2p_x _ | not_y2p_x /eqP def_x]. have [p' e_p' Up' p'p] := IHp _ y2p_x. by split=> // y /p'p; apply: predU1r. have [p' e_p' Up' p'p] := IHp y2 (mem_head y2 p). have{} p'p z: z \in y2 :: p' -> z \in y2 :: p. by rewrite !inE; case: (z == y2) => // /p'p. rewrite -(last_cons y1) def_x; split=> //=; first by rewrite ey12. by rewrite (contra (p'p y1)) -?def_x. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
shortenP
merges1 := if s1 is x1 :: s1' then let fix merge_s1 s2 := if s2 is x2 :: s2' then if leT x1 x2 then x1 :: merge s1' s2 else x2 :: merge_s1 s2' else s1 in merge_s1 else id. Arguments merge !s1 !s2 : rename.
Fixpoint
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
merge
merge_sort_pushs1 ss := match ss with | [::] :: ss' | [::] as ss' => s1 :: ss' | s2 :: ss' => [::] :: merge_sort_push (merge s2 s1) ss' end.
Fixpoint
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
merge_sort_push
merge_sort_pops1 ss := if ss is s2 :: ss' then merge_sort_pop (merge s2 s1) ss' else s1.
Fixpoint
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
merge_sort_pop
merge_sort_recss s := if s is [:: x1, x2 & s'] then let s1 := if leT x1 x2 then [:: x1; x2] else [:: x2; x1] in merge_sort_rec (merge_sort_push s1 ss) s' else merge_sort_pop s ss.
Fixpoint
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
merge_sort_rec
sort:= merge_sort_rec [::].
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sort
sort_rec1ss s := if s is x :: s then sort_rec1 (merge_sort_push [:: x] ss) s else merge_sort_pop [::] ss.
Fixpoint
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sort_rec1
sortEs : sort s = sort_rec1 [::] s. Proof. transitivity (sort_rec1 [:: nil] s); last by case: s. rewrite /sort; move: [::] {2}_.+1 (ltnSn (size s)./2) => ss n. by elim: n => // n IHn in ss s *; case: s => [|x [|y s]] //= /IHn->. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sortE
count_merge(p : pred T) s1 s2 : count p (merge s1 s2) = count p (s1 ++ s2). Proof. rewrite count_cat; elim: s1 s2 => // x s1 IH1. elim=> //= [|y s2 IH2]; first by rewrite addn0. by case: leT; rewrite /= ?IH1 ?IH2 !addnA [_ + p y]addnAC [p x + p y]addnC. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
count_merge
size_merges1 s2 : size (merge s1 s2) = size (s1 ++ s2). Proof. exact: (count_merge predT). Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
size_merge
allrel_merges1 s2 : allrel leT s1 s2 -> merge s1 s2 = s1 ++ s2. Proof. elim: s1 s2 => [|x s1 IHs1] [|y s2]; rewrite ?cats0 //=. by rewrite allrel_consl /= -andbA => /and3P [-> _ /IHs1->]. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
allrel_merge
count_sort(p : pred T) s : count p (sort s) = count p s. Proof. rewrite sortE -[RHS]/(sumn [seq count p x | x <- [::]] + count p s). elim: s [::] => [|x s ihs] ss. rewrite [LHS]/=; elim: ss [::] => //= s ss ihss t. by rewrite ihss count_merge count_cat addnCA addnA. rewrite {}ihs -[in RHS]cat1s count_cat addnA; congr addn; rewrite addnC. elim: {x s} ss [:: x] => [|[|x s] ss ihss] t //. by rewrite [LHS]/= add0n ihss count_merge count_cat -addnA addnCA. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
count_sort
pairwise_sorts : pairwise leT s -> sort s = s. Proof. pose catss := foldr (fun x => cat ^~ x) (Nil T). rewrite -{1 3}[s]/(catss [::] ++ s) sortE; elim: s [::] => /= [|x s ihs] ss. elim: ss [::] => //= s ss ihss t; rewrite -catA => ssst. rewrite -ihss ?allrel_merge //; move: ssst; rewrite !pairwise_cat. by case/and4P. rewrite (catA _ [:: _]) => ssxs. suff x_ss_E: catss (merge_sort_push [:: x] ss) = catss ([:: x] :: ss). by rewrite -[catss _ ++ _]/(catss ([:: x] :: ss)) -x_ss_E ihs // x_ss_E. move: ssxs; rewrite pairwise_cat => /and3P [_ + _]. elim: ss [:: x] => {x s ihs} //= -[|x s] ss ihss t h_pairwise; rewrite /= cats0 // allrel_merge ?ihss ?catA //. by move: h_pairwise; rewrite -catA !pairwise_cat => /and4P []. Qed. Remark size_merge_sort_push s1 : let graded ss := forall i, size (nth [::] ss i) \in pred2 0 (2 ^ (i + 1)) in size s1 = 2 -> {homo merge_sort_push s1 : ss / graded ss}. Proof. set n := {2}1; rewrite -[RHS]/(2 ^ n) => graded sz_s1 ss. elim: ss => [|s2 ss IHss] in (n) graded s1 sz_s1 * => sz_ss i //=. by case: i => [|[]] //; rewrite sz_s1 inE eqxx orbT. case: s2 i => [|x s2] [|i] //= in sz_ss *; first by rewrite sz_s1 inE eqxx orbT. exact: (sz_ss i.+1). rewrite addSnnS; apply: IHss i => [|i]; last by rewrite -addSnnS (sz_ss i.+1). by rewrite size_merge size_cat sz_s1 (eqP (sz_ss 0)) addnn expnS mul2n. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
pairwise_sort
merge_stable_pathx s1 s2 : allrel leT' s1 s2 -> path leT_lex x s1 -> path leT_lex x s2 -> path leT_lex x (merge s1 s2). Proof. elim: s1 s2 x => //= x s1 ih1; elim => //= y s2 ih2 h. rewrite allrel_cons2 => /and4P [xy' xs2 ys1 s1s2] /andP [hx xs1] /andP [hy ys2]. case: ifP => xy /=; rewrite (hx, hy) /=. - by apply: ih1; rewrite ?allrel_consr ?ys1 //= xy xy' implybT. - by apply: ih2; have:= leT_total x y; rewrite ?allrel_consl ?xs2 ?xy //= => ->. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
merge_stable_path
merge_stable_sorteds1 s2 : allrel leT' s1 s2 -> sorted leT_lex s1 -> sorted leT_lex s2 -> sorted leT_lex (merge s1 s2). Proof. case: s1 s2 => [|x s1] [|y s2] //=; rewrite allrel_consl allrel_consr /= -andbA. case/and4P => [xy' xs2 ys1 s1s2] xs1 ys2; rewrite -/(merge (_ :: _)). by case: ifP (leT_total x y) => /= xy yx; apply/merge_stable_path; rewrite /= ?(allrel_consl, allrel_consr, xs2, ys1, xy, yx, xy', implybT). Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
merge_stable_sorted
merge_pathx s1 s2 : path leT x s1 -> path leT x s2 -> path leT x (merge s1 s2). Proof. by rewrite !(eq_path leElex); apply/merge_stable_path/allrelT. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
merge_path
merge_sorteds1 s2 : sorted leT s1 -> sorted leT s2 -> sorted leT (merge s1 s2). Proof. by rewrite !(eq_sorted leElex); apply/merge_stable_sorted/allrelT. Qed. Hypothesis leT_tr : transitive leT.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
merge_sorted
sorted_merges t : sorted leT (s ++ t) -> merge s t = s ++ t. Proof. by rewrite sorted_pairwise // pairwise_cat => /and3P[/allrel_merge]. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sorted_merge
sorted_sorts : sorted leT s -> sort s = s. Proof. by rewrite sorted_pairwise //; apply/pairwise_sort. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sorted_sort
mergeA: associative merge. Proof. elim=> // x xs IHxs; elim=> // y ys IHys; elim=> [|z zs IHzs] /=. by case: ifP. case: ifP; case: ifP => /= lexy leyz. - by rewrite lexy (leT_tr lexy leyz) -IHxs /= leyz. - by rewrite lexy leyz -IHys. - case: ifP => lexz; first by rewrite -IHxs //= leyz. by rewrite -!/(merge (_ :: _)) IHzs /= lexy. - suff->: leT x z = false by rewrite leyz // -!/(merge (_ :: _)) IHzs /= lexy. by apply/contraFF/leT_tr: leyz; have := leT_total x y; rewrite lexy. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mergeA
map_merge: {morph map f : s1 s2 / merge leT' s1 s2 >-> merge leT s1 s2}. Proof. elim=> //= x s1 IHs1; elim => [|y s2 IHs2] //=; rewrite f_mono. by case: leT'; rewrite /= ?IHs1 ?IHs2. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
map_merge
map_sort: {morph map f : s1 / sort leT' s1 >-> sort leT s1}. Proof. move=> s; rewrite !sortE -[[::] in RHS]/(map (map f) [::]). elim: s [::] => /= [|x s ihs] ss; rewrite -/(map f [::]) -/(map f [:: _]); first by elim: ss [::] => //= x ss ihss ?; rewrite ihss map_merge. rewrite ihs -/(map f [:: x]); congr sort_rec1. by elim: ss [:: x] => {x s ihs} [|[|x s] ss ihss] //= ?; rewrite ihss map_merge. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
map_sort
merge_maps1 s2 : merge leT (map f s1) (map f s2) = map f (merge (relpre f leT) s1 s2). Proof. exact/esym/map_merge. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
merge_map