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
sort_maps : sort leT (map f s) = map f (sort (relpre f leT) s). Proof. exact/esym/map_sort. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sort_map
sorted_sort_inT (P : {pred T}) (leT : rel T) : {in P & &, transitive leT} -> forall s : seq T, all P s -> sorted leT s -> sort leT s = s. Proof. move=> /in3_sig ? _ /all_sigP[s ->]. by rewrite sort_map sorted_map => /sorted_sort->. Qed. Arguments sorted_sort_in {T P leT} leT_tr {s}.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sorted_sort_in
perm_merges1 s2 : perm_eql (merge leT s1 s2) (s1 ++ s2). Proof. by apply/permPl/permP => ?; rewrite count_merge. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
perm_merge
mem_merges1 s2 : merge leT s1 s2 =i s1 ++ s2. Proof. by apply: perm_mem; rewrite perm_merge. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem_merge
merge_uniqs1 s2 : uniq (merge leT s1 s2) = uniq (s1 ++ s2). Proof. by apply: perm_uniq; rewrite perm_merge. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
merge_uniq
perm_sorts : perm_eql (sort leT s) s. Proof. by apply/permPl/permP => ?; rewrite count_sort. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
perm_sort
mem_sorts : sort leT s =i s. Proof. exact/perm_mem/permPl/perm_sort. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem_sort
sort_uniqs : uniq (sort leT s) = uniq s. Proof. exact/perm_uniq/permPl/perm_sort. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sort_uniq
eq_count_merge(p : pred T) s1 s1' s2 s2' : count p s1 = count p s1' -> count p s2 = count p s2' -> count p (merge leT s1 s2) = count p (merge leT s1' s2'). Proof. by rewrite !count_merge !count_cat => -> ->. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
eq_count_merge
perm_iota_sort(T : Type) (leT : rel T) x0 s : {i_s : seq nat | perm_eq i_s (iota 0 (size s)) & sort leT s = map (nth x0 s) i_s}. Proof. exists (sort (relpre (nth x0 s) leT) (iota 0 (size s))). by rewrite perm_sort. by rewrite -[s in LHS](mkseq_nth x0) sort_map. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
perm_iota_sort
all_merge(T : Type) (P : {pred T}) (leT : rel T) s1 s2 : all P (merge leT s1 s2) = all P s1 && all P s2. Proof. elim: s1 s2 => //= x s1 IHs1; elim=> [|y s2 IHs2]; rewrite ?andbT //=. by case: ifP => _; rewrite /= ?IHs1 ?IHs2 //=; bool_congr. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
all_merge
all_sort(T : Type) (P : {pred T}) (leT : rel T) s : all P (sort leT s) = all P s. Proof. case: s => // x s; move: (x :: s) => {}s. by rewrite -(mkseq_nth x s) sort_map !all_map; apply/perm_all/permPl/perm_sort. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
all_sort
size_sort(T : Type) (leT : rel T) s : size (sort leT s) = size s. Proof. exact: (count_sort _ predT). Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
size_sort
ltn_sorted_uniq_leqs : sorted ltn s = uniq s && sorted leq s. Proof. rewrite (sorted_pairwise leq_trans) (sorted_pairwise ltn_trans) uniq_pairwise. by rewrite -pairwise_relI; apply/eq_pairwise => ? ?; rewrite ltn_neqAle. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
ltn_sorted_uniq_leq
gtn_sorted_uniq_geqs : sorted gtn s = uniq s && sorted geq s. Proof. by rewrite -rev_sorted ltn_sorted_uniq_leq rev_sorted rev_uniq. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
gtn_sorted_uniq_geq
iota_sortedi n : sorted leq (iota i n). Proof. by elim: n i => // [[|n] //= IHn] i; rewrite IHn leqW. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
iota_sorted
iota_ltn_sortedi n : sorted ltn (iota i n). Proof. by rewrite ltn_sorted_uniq_leq iota_sorted iota_uniq. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
iota_ltn_sorted
sort_iota_stablen : sorted lt_lex (sort leN (iota 0 n)). Proof. rewrite sortE. have/andP[]: all (gtn 0) (flatten [::]) && push_invariant [::] by []. elim: n 0 [::] => [|n ihn] m ss hss1 hss2; first exact: pop_stable. apply/ihn/push_stable; last by rewrite /= allrel1l hss1. have: all (gtn m.+1) (flatten ([:: m] :: ss)). by rewrite /= leqnn; apply: sub_all hss1 => ? /leqW. elim: ss [:: _] {hss1 hss2} => [|[|? ?] ? ihss] //= ? ?. by rewrite ihss //= all_cat all_merge -andbA andbCA -!all_cat. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sort_iota_stable
sort_pairwise_stableT (leT leT' : rel T) : total leT -> forall s : seq T, pairwise leT' s -> sorted [rel x y | leT x y && (leT y x ==> leT' x y)] (sort leT s). Proof. move=> leT_total s pairwise_s; case Ds: s => // [x s1]. rewrite -{s1}Ds -(mkseq_nth x s) sort_map. apply/homo_sorted_in/sort_iota_stable/(fun _ _ => leT_total _ _)/allss => y z. rewrite !mem_sort !mem_iota !leq0n add0n /= => ys zs /andP [->] /=. by case: (leT _ _); first apply: pairwiseP. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sort_pairwise_stable
sort_stableT (leT leT' : rel T) : total leT -> transitive leT' -> forall s : seq T, sorted leT' s -> sorted [rel x y | leT x y && (leT y x ==> leT' x y)] (sort leT s). Proof. move=> leT_total leT'_tr s; rewrite sorted_pairwise //. exact: sort_pairwise_stable. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sort_stable
sort_stable_inT (P : {pred T}) (leT leT' : rel T) : {in P &, total leT} -> {in P & &, transitive leT'} -> forall s : seq T, all P s -> sorted leT' s -> sorted [rel x y | leT x y && (leT y x ==> leT' x y)] (sort leT s). Proof. move=> /in2_sig leT_total /in3_sig leT_tr _ /all_sigP[s ->]. by rewrite sort_map !sorted_map; apply: sort_stable. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sort_stable_in
filter_sortT (leT : rel T) : total leT -> transitive leT -> forall p s, filter p (sort leT s) = sort leT (filter p s). Proof. move=> leT_total leT_tr p s; case Ds: s => // [x s1]. pose leN := relpre (nth x s) leT. pose lt_lex := [rel n m | leN n m && (leN m n ==> (n < m))]. have lt_lex_tr: transitive lt_lex. rewrite /lt_lex /leN => ? ? ? /= /andP [xy xy'] /andP [yz yz']. rewrite (leT_tr _ _ _ xy yz); apply/implyP => zx; move: xy' yz'. by rewrite (leT_tr _ _ _ yz zx) (leT_tr _ _ _ zx xy); apply: ltn_trans. rewrite -{s1}Ds -(mkseq_nth x s) !(filter_map, sort_map); congr map. apply/(@irr_sorted_eq _ lt_lex); rewrite /lt_lex /leN //=. - by move=> ?; rewrite /= ltnn implybF andbN. - exact/sorted_filter/sort_iota_stable. - exact/sort_stable/sorted_filter/iota_ltn_sorted/ltn_trans/ltn_trans. - by move=> ?; rewrite !(mem_filter, mem_sort). Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
filter_sort
filter_sort_inT (P : {pred T}) (leT : rel T) : {in P &, total leT} -> {in P & &, transitive leT} -> forall p s, all P s -> filter p (sort leT s) = sort leT (filter p s). Proof. move=> /in2_sig leT_total /in3_sig leT_tr p _ /all_sigP[s ->]. by rewrite !(sort_map, filter_map) filter_sort. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
filter_sort_in
mask_sorts m : {m_s : bitseq | mask m_s (sort leT s) = sort leT (mask m s)}. Proof. case Ds: {-}s => [|x s1]; [by rewrite Ds; case: m; exists [::] | clear s1 Ds]. rewrite -(mkseq_nth x s) -map_mask !sort_map. exists [seq i \in mask m (iota 0 (size s)) | i <- sort (xrelpre (nth x s) leT) (iota 0 (size s))]. rewrite -map_mask -filter_mask [in RHS]mask_filter ?iota_uniq ?filter_sort //. by move=> ? ? ?; exact: leT_tr. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mask_sort
sorted_mask_sorts m : sorted leT (mask m s) -> {m_s | mask m_s (sort leT s) = mask m s}. Proof. by move/(sorted_sort leT_tr) <-; exact: mask_sort. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sorted_mask_sort
mask_sort_ins m : all P s -> {m_s : bitseq | mask m_s (sort leT s) = sort leT (mask m s)}. Proof. move=> /all_sigP [{}s ->]; case: (mask_sort (leT := le_sT) _ _ s m) => //. by move=> m' m'E; exists m'; rewrite -map_mask !sort_map -map_mask m'E. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mask_sort_in
sorted_mask_sort_ins m : all P s -> sorted leT (mask m s) -> {m_s | mask m_s (sort leT s) = mask m s}. Proof. move=> ? /(sorted_sort_in leT_tr _) <-; [exact: mask_sort_in | exact: all_mask]. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sorted_mask_sort_in
subseq_sort: {homo sort leT : t s / subseq t s}. Proof. move=> _ s /subseqP [m _ ->]; have [m' <-] := mask_sort leT_total leT_tr s m. exact: mask_subseq. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
subseq_sort
sorted_subseq_sortt s : subseq t s -> sorted leT t -> subseq t (sort leT s). Proof. by move=> subseq_ts /(sorted_sort leT_tr) <-; exact: subseq_sort. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sorted_subseq_sort
mem2_sorts x y : leT x y -> mem2 s x y -> mem2 (sort leT s) x y. Proof. move=> lexy /[!mem2E] /subseq_sort. by case: eqP => // _; rewrite {1}/sort /= lexy /=. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2_sort
subseq_sort_int s : {in s &, total leT} -> {in s & &, transitive leT} -> subseq t s -> subseq (sort leT t) (sort leT s). Proof. move=> leT_total leT_tr /subseqP [m _ ->]. have [m' <-] := mask_sort_in leT_total leT_tr m (allss _). exact: mask_subseq. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
subseq_sort_in
sorted_subseq_sort_int s : {in s &, total leT} -> {in s & &, transitive leT} -> subseq t s -> sorted leT t -> subseq t (sort leT s). Proof. move=> ? leT_tr ? /(sorted_sort_in leT_tr) <-; last exact/allP/mem_subseq. exact: subseq_sort_in. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sorted_subseq_sort_in
mem2_sort_ins : {in s &, total leT} -> {in s & &, transitive leT} -> forall x y, leT x y -> mem2 s x y -> mem2 (sort leT s) x y. Proof. move=> leT_total leT_tr x y lexy; rewrite !mem2E. by move/subseq_sort_in; case: (_ == _); rewrite /sort /= ?lexy; apply. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2_sort_in
sort_sortedT (leT : rel T) : total leT -> forall s, sorted leT (sort leT s). Proof. move=> leT_total s; apply/sub_sorted/sort_stable => //= [? ? /andP[] //|]. by case: s => // x s; elim: s x => /=. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sort_sorted
sort_sorted_inT (P : {pred T}) (leT : rel T) : {in P &, total leT} -> forall s : seq T, all P s -> sorted leT (sort leT s). Proof. by move=> /in2_sig ? _ /all_sigP[s ->]; rewrite sort_map sorted_map sort_sorted. Qed. Arguments sort_sorted {T leT} leT_total s. Arguments sort_sorted_in {T P leT} leT_total {s}.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
sort_sorted_in
perm_sortP(T : eqType) (leT : rel T) : total leT -> transitive leT -> antisymmetric leT -> forall s1 s2, reflect (sort leT s1 = sort leT s2) (perm_eq s1 s2). Proof. move=> leT_total leT_tr leT_asym s1 s2. apply: (iffP idP) => eq12; last by rewrite -(perm_sort leT) eq12 perm_sort. apply: (sorted_eq leT_tr leT_asym); rewrite ?sort_sorted //. by rewrite perm_sort (permPl eq12) -(perm_sort leT). Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
perm_sortP
perm_sort_inP(T : eqType) (leT : rel T) (s1 s2 : seq T) : {in s1 &, total leT} -> {in s1 & &, transitive leT} -> {in s1 &, antisymmetric leT} -> reflect (sort leT s1 = sort leT s2) (perm_eq s1 s2). Proof. move=> /in2_sig leT_total /in3_sig leT_tr /in2_sig/(_ _ _ _)/val_inj leT_asym. apply: (iffP idP) => s1s2; last by rewrite -(perm_sort leT) s1s2 perm_sort. move: (s1s2); have /all_sigP[s1' ->] := allss s1. have /all_sigP[{s1s2}s2 ->] : all [in s1] s2 by rewrite -(perm_all _ s1s2). by rewrite !sort_map => /(perm_map_inj val_inj) /(perm_sortP leT_total)->. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
perm_sort_inP
homo_sort_map(T : Type) (T' : eqType) (f : T -> T') leT leT' : antisymmetric (relpre f leT') -> transitive (relpre f leT') -> total leT -> {homo f : x y / leT x y >-> leT' x y} -> forall s : seq T, sort leT' (map f s) = map f (sort leT s). Proof. move=> leT'_asym leT'_trans leT_total f_homo s; case Ds: s => // [x s']. rewrite -{}Ds -(mkseq_nth x s) [in RHS]sort_map -!map_comp /comp. apply: (@sorted_eq_in _ leT') => [? ? ?|? ?|||]; rewrite ?mem_sort. - by move=> /mapP[? _ ->] /mapP[? _ ->] /mapP[? _ ->]; apply/leT'_trans. - by move=> /mapP[? _ ->] /mapP[? _ ->] /leT'_asym ->. - apply: (sort_sorted_in _ (allss _)) => _ _ /mapP[y _ ->] /mapP[z _ ->]. by case/orP: (leT_total (nth x s y) (nth x s z)) => /f_homo ->; rewrite ?orbT. - by rewrite map_comp -sort_map; exact/homo_sorted/sort_sorted. - by rewrite perm_sort perm_map // perm_sym perm_sort. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
homo_sort_map
homo_sort_map_in(T : Type) (T' : eqType) (P : {pred T}) (f : T -> T') leT leT' : {in P &, antisymmetric (relpre f leT')} -> {in P & &, transitive (relpre f leT')} -> {in P &, total leT} -> {in P &, {homo f : x y / leT x y >-> leT' x y}} -> forall s : seq T, all P s -> sort leT' [seq f x | x <- s] = [seq f x | x <- sort leT s]. Proof. move=> /in2_sig leT'_asym /in3_sig leT'_trans /in2_sig leT_total. move=> /in2_sig f_homo _ /all_sigP[s ->]. rewrite [in RHS]sort_map -!map_comp /comp. by apply: homo_sort_map => // ? ? /leT'_asym /val_inj. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
homo_sort_map_in
fpathf := (path (coerced_frel f)).
Notation
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
fpath
fcyclef := (cycle (coerced_frel f)).
Notation
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
fcycle
ufcyclef := (ucycle (coerced_frel f)). Prenex Implicits path next prev cycle ucycle mem2.
Notation
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
ufcycle
trajectx n := if n is n'.+1 then x :: traject (f x) n' else [::].
Fixpoint
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
traject
trajectSx n : traject x n.+1 = x :: traject (f x) n. Proof. by []. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
trajectS
trajectSrx n : traject x n.+1 = rcons (traject x n) (iter n f x). Proof. by elim: n x => //= n IHn x; rewrite IHn -iterSr. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
trajectSr
last_trajectx n : last x (traject (f x) n) = iter n f x. Proof. by case: n => // n; rewrite iterSr trajectSr last_rcons. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
last_traject
traject_iterix n : traject x n = iteri n (fun i => rcons^~ (iter i f x)) [::]. Proof. by elim: n => //= n <-; rewrite -trajectSr. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
traject_iteri
size_trajectx n : size (traject x n) = n. Proof. by elim: n x => //= n IHn x //=; rewrite IHn. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
size_traject
nth_trajecti n : i < n -> forall x, nth x (traject x n) i = iter i f x. Proof. elim: n => // n IHn; rewrite ltnS => le_i_n x. rewrite trajectSr nth_rcons size_traject. by case: ltngtP le_i_n => [? _||->] //; apply: IHn. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
nth_traject
trajectDm n x : traject x (m + n) = traject x m ++ traject (iter m f x) n. Proof. by elim: m => //m IHm in x *; rewrite addSn !trajectS IHm -iterSr. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
trajectD
take_trajectn k x : k <= n -> take k (traject x n) = traject x k. Proof. by move=> /subnKC<-; rewrite trajectD take_size_cat ?size_traject. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
take_traject
eq_fpathf' : f =1 f' -> fpath f =2 fpath f'. Proof. by move/eq_frel/eq_path. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
eq_fpath
eq_fcyclef' : f =1 f' -> fcycle f =1 fcycle f'. Proof. by move/eq_frel/eq_cycle. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
eq_fcycle
fpathEx p : fpath f x p -> p = traject f (f x) (size p). Proof. by elim: p => //= y p IHp in x * => /andP[/eqP{y}<- /IHp<-]. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
fpathE
fpathPx p : reflect (exists n, p = traject f (f x) n) (fpath f x p). Proof. apply: (iffP idP) => [/fpathE->|[n->]]; first by exists (size p). by elim: n => //= n IHn in x *; rewrite eqxx IHn. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
fpathP
fpath_trajectx n : fpath f x (traject f (f x) n). Proof. by apply/(fpathP x); exists n. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
fpath_traject
loopingx n := iter n f x \in traject f x n.
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
looping
loopingPx n : reflect (forall m, iter m f x \in traject f x n) (looping x n). Proof. apply: (iffP idP) => loop_n; last exact: loop_n. case: n => // n in loop_n *; elim=> [|m /= IHm]; first exact: mem_head. move: (fpath_traject x n) loop_n; rewrite /looping !iterS -last_traject /=. move: (iter m f x) IHm => y /splitPl[p1 p2 def_y]. rewrite cat_path last_cat def_y; case: p2 => // z p2 /and3P[_ /eqP-> _] _. by rewrite inE mem_cat mem_head !orbT. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
loopingP
trajectPx n y : reflect (exists2 i, i < n & y = iter i f x) (y \in traject f x n). Proof. elim: n x => [|n IHn] x /=; first by right; case. rewrite inE; have [-> | /= neq_xy] := eqP; first by left; exists 0. apply: {IHn}(iffP (IHn _)) => [[i] | [[|i]]] // lt_i_n ->. by exists i.+1; rewrite ?iterSr. by exists i; rewrite ?iterSr. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
trajectP
looping_uniqx n : uniq (traject f x n.+1) = ~~ looping x n. Proof. rewrite /looping; elim: n x => [|n IHn] x //. rewrite [n.+1 in LHS]lock [iter]lock /= -!lock {}IHn -iterSr -negb_or inE. congr (~~ _); apply: orb_id2r => /trajectP no_loop. apply/idP/eqP => [/trajectP[m le_m_n def_x] | {1}<-]; last first. by rewrite iterSr -last_traject mem_last. have loop_m: looping x m.+1 by rewrite /looping iterSr -def_x mem_head. have/trajectP[[|i] // le_i_m def_fn1x] := loopingP _ _ loop_m n.+1. by case: no_loop; exists i; rewrite -?iterSr // -ltnS (leq_trans le_i_m). Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
looping_uniq
nextE(x : T) (p_x : x \in p) : next p x = f x. Proof. exact/esym/eqP/(next_cycle f_p). Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
nextE
mem_fcycle: {homo f : x / x \in p}. Proof. by move=> x xp; rewrite -nextE// mem_next. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem_fcycle
inj_cycle: {in p &, injective f}. Proof. apply: can_in_inj (iter (size p).-1 f) _ => x /rot_to[i q rip]. have /fpathE qxE : fcycle f (x :: q) by rewrite -rip rot_cycle. have -> : size p = size (rcons q x) by rewrite size_rcons -(size_rot i) rip. by rewrite -iterSr -last_traject prednK -?qxE ?size_rcons// last_rcons. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
inj_cycle
prev_next: cancel (next p) (prev p). Proof. move=> x; rewrite prev_nth mem_next next_nth; case p_x: (x \in p) => //. case Dp: p Up p_x => // [y q]; rewrite [uniq _]/= -Dp => /andP[q'y Uq] p_x. rewrite -[RHS](nth_index y p_x); congr (nth y _ _); set i := index x p. have: i <= size q by rewrite -index_mem -/i Dp in p_x. case: ltngtP => // [lt_i_q|->] _; first by rewrite index_uniq. by apply/eqP; rewrite nth_default // eqn_leq index_size leqNgt index_mem. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
prev_next
next_prev: cancel (prev p) (next p). Proof. move=> x; rewrite next_nth mem_prev prev_nth; case p_x: (x \in p) => //. case def_p: p p_x => // [y q]; rewrite -def_p => p_x. rewrite index_uniq //; last by rewrite def_p ltnS index_size. case q_x: (x \in q); first exact: nth_index. rewrite nth_default; last by rewrite leqNgt index_mem q_x. by apply/eqP; rewrite def_p inE q_x orbF eq_sym in p_x. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
next_prev
cycle_next: fcycle (next p) p. Proof. case def_p: p Up => [|x q] Uq //; rewrite -[in next _]def_p. apply/(pathP x)=> i; rewrite size_rcons => le_i_q. rewrite -cats1 -cat_cons nth_cat le_i_q /= next_nth {}def_p mem_nth //. rewrite index_uniq // nth_cat /= ltn_neqAle andbC -ltnS le_i_q. by case: (i =P _) => //= ->; rewrite subnn nth_default. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
cycle_next
cycle_prev: cycle (fun x y => x == prev p y) p. Proof. apply: etrans cycle_next; symmetry; case def_p: p => [|x q] //. by apply: eq_path; rewrite -def_p; apply: (can2_eq prev_next next_prev). Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
cycle_prev
cycle_from_next: (forall x, x \in p -> e x (next p x)) -> cycle e p. Proof. case: p (next p) cycle_next => //= [x q] n; rewrite -(belast_rcons x q x). move: {q}(rcons q x) => q n_q /allP. by elim: q x n_q => //= _ q IHq x /andP[/eqP <- n_q] /andP[-> /IHq->]. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
cycle_from_next
cycle_from_prev: (forall x, x \in p -> e (prev p x) x) -> cycle e p. Proof. move=> e_p; apply: cycle_from_next => x. by rewrite -mem_next => /e_p; rewrite prev_next. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
cycle_from_prev
next_rot: next (rot n0 p) =1 next p. Proof. move=> x; have n_p := cycle_next; rewrite -(rot_cycle n0) in n_p. case p_x: (x \in p); last by rewrite !next_nth mem_rot p_x. by rewrite (eqP (next_cycle n_p _)) ?mem_rot. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
next_rot
prev_rot: prev (rot n0 p) =1 prev p. Proof. move=> x; have p_p := cycle_prev; rewrite -(rot_cycle n0) in p_p. case p_x: (x \in p); last by rewrite !prev_nth mem_rot p_x. by rewrite (eqP (prev_cycle p_p _)) ?mem_rot. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
prev_rot
next_rotr: next (rotr n0 p) =1 next p. Proof. exact: next_rot. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
next_rotr
prev_rotr: prev (rotr n0 p) =1 prev p. Proof. exact: prev_rot. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
prev_rotr
prev_revp : uniq p -> prev (rev p) =1 next p. Proof. move=> Up x; case p_x: (x \in p); last first. by rewrite next_nth prev_nth mem_rev p_x. case/rot_to: p_x (Up) => [i q def_p] Urp; rewrite -rev_uniq in Urp. rewrite -(prev_rotr i Urp); do 2 rewrite -(prev_rotr 1) ?rotr_uniq //. rewrite -rev_rot -(next_rot i Up) {i p Up Urp}def_p. by case: q => // y q; rewrite !rev_cons !(=^~ rcons_cons, rotr1_rcons) /= eqxx. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
prev_rev
next_revp : uniq p -> next (rev p) =1 prev p. Proof. by move=> Up x; rewrite -[p in RHS]revK prev_rev // rev_uniq. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
next_rev
rel_base(b : pred T) := forall x' y', ~~ b (h x') -> e (h x') (h y') = e' x' y'.
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
rel_base
map_pathb x' p' (Bb : rel_base b) : ~~ has (preim h b) (belast x' p') -> path e (h x') (map h p') = path e' x' p'. Proof. by elim: p' x' => [|y' p' IHp'] x' //= /norP[/Bb-> /IHp'->]. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
map_path
mem2_mapx' y' p' : mem2 (map h p') (h x') (h y') = mem2 p' x' y'. Proof. by rewrite [LHS]/mem2 (index_map Ih) -map_drop mem_map. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
mem2_map
next_mapp : uniq p -> forall x, next (map h p) (h x) = h (next p x). Proof. move=> Up x; case p_x: (x \in p); last by rewrite !next_nth (mem_map Ih) p_x. case/rot_to: p_x => i p' def_p. rewrite -(next_rot i Up); rewrite -(map_inj_uniq Ih) in Up. rewrite -(next_rot i Up) -map_rot {i p Up}def_p /=. by case: p' => [|y p''] //=; rewrite !eqxx. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
next_map
prev_mapp : uniq p -> forall x, prev (map h p) (h x) = h (prev p x). Proof. move=> Up x; rewrite -[x in LHS](next_prev Up) -(next_map Up). by rewrite prev_next ?map_inj_uniq. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
prev_map
fun_base(T T' : eqType) (h : T' -> T) f f' := rel_base h (frel f) (frel f').
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
fun_base
arcp x y := let px := rot (index x p) p in take (index y px) px.
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
arc
arc_roti p : uniq p -> {in p, arc (rot i p) =2 arc p}. Proof. move=> Up x p_x y; congr (fun q => take (index y q) q); move: Up p_x {y}. rewrite -{1 2 5 6}(cat_take_drop i p) /rot cat_uniq => /and3P[_ Up12 _]. rewrite !drop_cat !take_cat !index_cat mem_cat orbC. case p2x: (x \in drop i p) => /= => [_ | p1x]. rewrite index_mem p2x [x \in _](negbTE (hasPn Up12 _ p2x)) /= addKn. by rewrite ltnNge leq_addr catA. by rewrite p1x index_mem p1x addKn ltnNge leq_addr /= catA. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
arc_rot
left_arcx y p1 p2 (p := x :: p1 ++ y :: p2) : uniq p -> arc p x y = x :: p1. Proof. rewrite /arc /p [index x _]/= eqxx rot0 -cat_cons cat_uniq index_cat. move: (x :: p1) => xp1 /and3P[_ /norP[/= /negbTE-> _] _]. by rewrite eqxx addn0 take_size_cat. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
left_arc
right_arcx y p1 p2 (p := x :: p1 ++ y :: p2) : uniq p -> arc p y x = y :: p2. Proof. rewrite -[p]cat_cons -rot_size_cat rot_uniq => Up. by rewrite arc_rot ?left_arc ?mem_head. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
right_arc
rot_to_arc_specp x y := RotToArcSpec i p1 p2 of x :: p1 = arc p x y & y :: p2 = arc p y x & rot i p = x :: p1 ++ y :: p2 : rot_to_arc_spec p x y.
Variant
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
rot_to_arc_spec
rot_to_arcp x y : uniq p -> x \in p -> y \in p -> x != y -> rot_to_arc_spec p x y. Proof. move=> Up p_x p_y ne_xy; case: (rot_to p_x) (p_y) (Up) => [i q def_p] q_y. rewrite -(mem_rot i) def_p inE eq_sym (negbTE ne_xy) in q_y. rewrite -(rot_uniq i) def_p. case/splitPr: q / q_y def_p => q1 q2 def_p Uq12; exists i q1 q2 => //. by rewrite -(arc_rot i Up p_x) def_p left_arc. by rewrite -(arc_rot i Up p_y) def_p right_arc. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/path.v
rot_to_arc
edivn2q r := if r is r'.+2 then edivn2 q.+1 r' else (q, r).
Fixpoint
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path", "From mathcomp Require Import choice fintype div bigop" ]
boot/prime.v
edivn2
edivn2Pn : edivn_spec n 2 (edivn2 0 n). Proof. rewrite -[n]odd_double_half addnC -{1}[n./2]addn0 -{1}mul2n mulnC. elim: n./2 {1 4}0 => [|r IHr] q; first by case (odd n) => /=. by rewrite addSnnS; apply: IHr. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path", "From mathcomp Require Import choice fintype div bigop" ]
boot/prime.v
edivn2P
elogn2e q r {struct q} := match q, r with | 0, _ | _, 0 => (e, q) | q'.+1, 1 => elogn2 e.+1 q' q' | q'.+1, r'.+2 => elogn2 e q' r' end. Arguments elogn2 : simpl nomatch.
Fixpoint
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path", "From mathcomp Require Import choice fintype div bigop" ]
boot/prime.v
elogn2
elogn2_specn : nat * nat -> Type := Elogn2Spec e m of n = 2 ^ e * m.*2.+1 : elogn2_spec n (e, m).
Variant
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path", "From mathcomp Require Import choice fintype div bigop" ]
boot/prime.v
elogn2_spec
elogn2Pn : elogn2_spec n.+1 (elogn2 0 n n). Proof. rewrite -[n.+1]mul1n -[1]/(2 ^ 0) -[n in _ * n.+1](addKn n n) addnn. elim: n {1 4 6}n {2 3}0 (leqnn n) => [|q IHq] [|[|r]] e //=; last first. by move/ltnW; apply: IHq. rewrite subn1 prednK // -mul2n mulnA -expnSr. by rewrite -[q in _ * q.+1](addKn q q) addnn => _; apply: IHq. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path", "From mathcomp Require Import choice fintype div bigop" ]
boot/prime.v
elogn2P
ifnzT n (x y : T) := if n is 0 then y else x.
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path", "From mathcomp Require Import choice fintype div bigop" ]
boot/prime.v
ifnz
ifnz_specT n (x y : T) : T -> Type := | IfnzPos of n > 0 : ifnz_spec n x y x | IfnzZero of n = 0 : ifnz_spec n x y y.
Variant
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path", "From mathcomp Require Import choice fintype div bigop" ]
boot/prime.v
ifnz_spec
ifnzPT n (x y : T) : ifnz_spec n x y (ifnz n x y). Proof. by case: n => [|n]; [right | left]. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path", "From mathcomp Require Import choice fintype div bigop" ]
boot/prime.v
ifnzP
add_divisorsf divs := let: (p, e) := f in let add1 divs' := merge leq (map (NatTrec.mul p) divs') divs in iter e add1 divs. Import NatTrec.
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path", "From mathcomp Require Import choice fintype div bigop" ]
boot/prime.v
add_divisors
add_totient_factorf m := let: (p, e) := f in p.-1 * p ^ e.-1 * m.
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path", "From mathcomp Require Import choice fintype div bigop" ]
boot/prime.v
add_totient_factor
cons_pfactor(p e : nat) pd := ifnz e ((p, e) :: pd) pd.
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path", "From mathcomp Require Import choice fintype div bigop" ]
boot/prime.v
cons_pfactor
NumFactor(f : nat * nat) := ([Num of f.1], f.2).
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path", "From mathcomp Require Import choice fintype div bigop" ]
boot/prime.v
NumFactor
pfactorp e := p ^ e.
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path", "From mathcomp Require Import choice fintype div bigop" ]
boot/prime.v
pfactor