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
gtn_decoden : all (ltn^~ n) (decode n). Proof. by rewrite -{1}[n]decodeK ltn_code. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
gtn_decode
seq_of_opt:= @oapp T _ (nseq 1) [::].
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
seq_of_opt
seq_of_optK: cancel seq_of_opt ohead. Proof. by case. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
seq_of_optK
tag_of_pair(p : T1 * T2) := @Tagged T1 p.1 (fun _ => T2) p.2.
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
tag_of_pair
pair_of_tag(u : {i : T1 & T2}) := (tag u, tagged u).
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
pair_of_tag
tag_of_pairK: cancel tag_of_pair pair_of_tag. Proof. by case. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
tag_of_pairK
pair_of_tagK: cancel pair_of_tag tag_of_pair. Proof. by case. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
pair_of_tagK
opair_of_sum(s : T1 + T2) := match s with inl x => (Some x, None) | inr y => (None, Some y) end.
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
opair_of_sum
sum_of_opairp := oapp (some \o @inr T1 T2) (omap (@inl _ T2) p.1) p.2.
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
sum_of_opair
opair_of_sumK: pcancel opair_of_sum sum_of_opair. Proof. by case. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
opair_of_sumK
bool_of_unitK: cancel (fun _ => true) (fun _ => tt). Proof. by case. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
bool_of_unitK
tree:= Leaf of T | Node of nat & seq tree.
Inductive
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
tree
tree_rectK IH_leaf IH_node := fix loop t : K t := match t with | Leaf x => IH_leaf x | Node n f0 => let fix iter_pair f : foldr (fun t => prod (K t)) unit f := if f is t :: f' then (loop t, iter_pair f') else tt in IH_node n f0 (iter_pair f0) end.
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
tree_rect
tree_rec(K : tree -> Set) := @tree_rect K.
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
tree_rec
tree_indK IH_leaf IH_node := fix loop t : K t : Prop := match t with | Leaf x => IH_leaf x | Node n f0 => let fix iter_conj f : foldr (fun t => and (K t)) True f := if f is t :: f' then conj (loop t) (iter_conj f') else Logic.I in IH_node n f0 (iter_conj f0) end.
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
tree_ind
encodet : seq (nat + T) := match t with | Leaf x => [:: inr _ x] | Node n f => inl _ n.+1 :: rcons (flatten (map encode f)) (inl _ 0) end.
Fixpoint
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
encode
decode_stepc fs := match c with | inr x => (Leaf x :: fs.1, fs.2) | inl 0 => ([::], fs.1 :: fs.2) | inl n.+1 => (Node n fs.1 :: head [::] fs.2, behead fs.2) end.
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
decode_step
decodec := ohead (foldr decode_step ([::], [::]) c).1.
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
decode
codeK: pcancel encode decode. Proof. move=> t; rewrite /decode; set fs := (_, _). suffices ->: foldr decode_step fs (encode t) = (t :: fs.1, fs.2) by []. elim: t => //= n f IHt in (fs) *; elim: f IHt => //= t f IHf []. by rewrite rcons_cat foldr_cat => -> /= /IHf[-> -> ->]. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
codeK
Definition_ (T : eqType) := Equality.copy (GenTree.tree T) (pcan_type (GenTree.codeK T)).
HB.instance
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
Definition
RecordhasChoice T := Mixin { find_subdef : pred T -> nat -> option T; choice_correct_subdef {P n x} : find_subdef P n = Some x -> P x; choice_complete_subdef {P : pred T} : (exists x, P x) -> exists n, find_subdef P n; choice_extensional_subdef {P Q : pred T} : P =1 Q -> find_subdef P =1 find_subdef Q }. #[short(type="choiceType")] HB.structure Definition Choice := { T of hasChoice T & hasDecEq T}.
HB.mixin
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
Record
find:= find_subdef.
Notation
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
find
correct:= choice_correct_subdef. Arguments correct {_ _ _ _}.
Notation
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
correct
complete:= choice_complete_subdef. Arguments complete {_ _}.
Notation
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
complete
extensional:= choice_extensional_subdef. Arguments extensional {_ _ _}.
Notation
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
extensional
xchooseP exP := sval (@xchoose_subproof T P exP).
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
xchoose
xchoosePP exP : P (@xchoose P exP). Proof. by rewrite /xchoose; case: (xchoose_subproof exP) => x /= /correct. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
xchooseP
eq_xchooseP Q exP exQ : P =1 Q -> @xchoose P exP = @xchoose Q exQ. Proof. rewrite /xchoose => eqPQ. case: (xchoose_subproof exP) => x; case: (xchoose_subproof exQ) => y /=. case: ex_minnP => n; rewrite -(extensional eqPQ) => Pn minQn. case: ex_minnP => m; rewrite !(extensional eqPQ) => Qm minPm. by case: (eqVneq m n) => [-> -> [] //|]; rewrite eqn_leq minQn ?minPm. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
eq_xchoose
sigWP : (exists x, P x) -> {x | P x}. Proof. by move=> exP; exists (xchoose exP); apply: xchooseP. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
sigW
sig2WP Q : (exists2 x, P x & Q x) -> {x | P x & Q x}. Proof. move=> exPQ; have [|x /andP[]] := @sigW (predI P Q); last by exists x. by have [x Px Qx] := exPQ; exists x; apply/andP. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
sig2W
sig_eqW(vT : eqType) (lhs rhs : T -> vT) : (exists x, lhs x = rhs x) -> {x | lhs x = rhs x}. Proof. move=> exP; suffices [x /eqP Ex]: {x | lhs x == rhs x} by exists x. by apply: sigW; have [x /eqP Ex] := exP; exists x. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
sig_eqW
sig2_eqW(vT : eqType) (P : pred T) (lhs rhs : T -> vT) : (exists2 x, P x & lhs x = rhs x) -> {x | P x & lhs x = rhs x}. Proof. move=> exP; suffices [x Px /eqP Ex]: {x | P x & lhs x == rhs x} by exists x. by apply: sig2W; have [x Px /eqP Ex] := exP; exists x. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
sig2_eqW
chooseP x0 := if insub x0 : {? x | P x} is Some (exist x Px) then xchoose (ex_intro [eta P] x Px) else x0.
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
choose
choosePP x0 : P x0 -> P (choose P x0). Proof. by move=> Px0; rewrite /choose insubT xchooseP. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
chooseP
choose_idP x0 y0 : P x0 -> P y0 -> choose P x0 = choose P y0. Proof. by move=> Px0 Py0; rewrite /choose !insubT /=; apply: eq_xchoose. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
choose_id
eq_chooseP Q : P =1 Q -> choose P =1 choose Q. Proof. rewrite /choose => eqPQ x0. do [case: insubP; rewrite eqPQ] => [[x Px] Qx0 _| ?]; last by rewrite insubN. by rewrite insubT; apply: eq_xchoose. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
eq_choose
PCanHasChoicef' : pcancel f f' -> hasChoice sT. Proof. move=> fK; pose liftP sP := [pred x | oapp sP false (f' x)]. pose sf sP := [fun n => obind f' (find (liftP sP) n)]. exists sf => [sP n x | sP [y sPy] | sP sQ eqPQ n] /=. - by case Df: (find _ n) => //= [?] Dx; have:= correct Df; rewrite /= Dx. - have [|n Pn] := @complete T (liftP sP); first by exists (f y); rewrite /= fK. exists n; case Df: (find _ n) Pn => //= [x] _. by have:= correct Df => /=; case: (f' x). by congr (obind _ _); apply: extensional => x /=; case: (f' x) => /=. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
PCanHasChoice
CanHasChoicef' (fK : cancel f f') := PCanHasChoice (can_pcan fK). HB.instance Definition _ f' (fK : pcancel f f') : hasChoice (pcan_type fK) := PCanHasChoice fK. HB.instance Definition _ f' (fK : cancel f f') : hasChoice (can_type fK) := PCanHasChoice (can_pcan fK).
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
CanHasChoice
Definition_ := seq_hasChoice.
HB.instance
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
Definition
Definition_ := tagged_hasChoice.
HB.instance
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
Definition
Definition_ := nat_hasChoice. HB.instance Definition _ := Choice.copy bool (can_type oddb). HB.instance Definition _ := Choice.on bitseq. HB.instance Definition _ := Choice.copy unit (can_type bool_of_unitK). HB.instance Definition _ := Choice.copy void (pcan_type (of_voidK unit)). HB.instance Definition _ T := Choice.copy (option T) (can_type (@seq_of_optK (Choice.sort T))). HB.instance Definition _ (T1 T2 : choiceType) := Choice.copy (T1 * T2)%type (can_type (@tag_of_pairK T1 T2)). HB.instance Definition _ (T1 T2 : choiceType) := Choice.copy (T1 + T2)%type (pcan_type (@opair_of_sumK T1 T2)). HB.instance Definition _ T := Choice.copy (GenTree.tree T) (pcan_type (GenTree.codeK T)).
HB.instance
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
Definition
DefinitionSubChoice T (P : pred T) := { sT of Choice sT & isSub T P sT }. Prenex Implicits xchoose choose.
HB.structure
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
Definition
Definition_ (T : choiceType) (P : pred T) := [Choice of {x | P x} by <:]. HB.mixin Record Choice_isCountable (T : Type) : Type := { pickle : T -> nat; unpickle : nat -> option T; pickleK : pcancel pickle unpickle }. Arguments Choice_isCountable.axioms_ T%_type_scope. #[short(type="countType")] HB.structure Definition Countable := { T of Choice T & Choice_isCountable T }. HB.factory Record isCountable (T : Type) : Type := { pickle : T -> nat; unpickle : nat -> option T; pickleK : pcancel pickle unpickle }. HB.builders Context T of isCountable T. HB.instance Definition _ := Equality.copy T (pcan_type pickleK). HB.instance Definition _ := PCanHasChoice pickleK. HB.instance Definition _ := Choice_isCountable.Build T pickleK. HB.end. Arguments isCountable.axioms_ T%_type_scope.
HB.instance
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
Definition
pickle_invn := obind (fun x : T => if pickle x == n then Some x else None) (unpickle n).
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
pickle_inv
pickle_invK: ocancel pickle_inv pickle. Proof. by rewrite /pickle_inv => n; case def_x: (unpickle n) => //= [x]; case: eqP. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
pickle_invK
pickleK_inv: pcancel pickle pickle_inv. Proof. by rewrite /pickle_inv => x; rewrite pickleK /= eqxx. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
pickleK_inv
pcan_pickleKsT f f' : @pcancel T sT f f' -> pcancel (pickle \o f) (pcomp f' unpickle). Proof. by move=> fK x; rewrite /pcomp pickleK /= fK. Qed.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
pcan_pickleK
PCanIsCountablesT (f : sT -> T) f' (fK : pcancel f f') := isCountable.Build sT (pcan_pickleK fK).
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
PCanIsCountable
CanIsCountablesT f f' (fK : cancel f f') := @PCanIsCountable sT _ _ (can_pcan fK). HB.instance Definition _ sT (f : sT -> T) f' (fK : pcancel f f') : isCountable (pcan_type fK) := PCanIsCountable fK. HB.instance Definition _ sT (f : sT -> T) f' (fK : cancel f f') : isCountable (can_type fK) := CanIsCountable fK. #[hnf] HB.instance Definition _ (P : pred T) (sT : subType P) := Countable.copy (sub_type sT) (pcan_type valK).
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
CanIsCountable
pickle_seqs := CodeSeq.code (map (@pickle T) s).
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
pickle_seq
unpickle_seqn := Some (pmap (@unpickle T) (CodeSeq.decode n)).
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
unpickle_seq
pickle_seqK: pcancel pickle_seq unpickle_seq. Proof. by move=> s; rewrite /unpickle_seq CodeSeq.codeK (map_pK pickleK). Qed. HB.instance Definition _ := isCountable.Build (seq T) pickle_seqK.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
pickle_seqK
DefinitionSubCountable T (P : pred T) := { sT of Countable sT & isSub T P sT}.
HB.structure
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
Definition
pickle_tagged(u : {i : I & T_ i}) := CodeSeq.code [:: pickle (tag u); pickle (tagged u)].
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
pickle_tagged
unpickle_taggeds := if CodeSeq.decode s is [:: ni; nx] then obind (fun i => omap (@Tagged I i T_) (unpickle nx)) (unpickle ni) else None.
Definition
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
unpickle_tagged
pickle_taggedK: pcancel pickle_tagged unpickle_tagged. Proof. by case=> i x; rewrite /unpickle_tagged CodeSeq.codeK /= pickleK /= pickleK. Qed. HB.instance Definition _ := Choice_isCountable.Build {i : I & T_ i} pickle_taggedK.
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
pickle_taggedK
nat_pickleK: pcancel id (@Some nat). Proof. by []. Qed. HB.instance Definition _ := Choice_isCountable.Build nat nat_pickleK. HB.instance Definition _ := Countable.copy bool (can_type oddb). HB.instance Definition _ := Countable.on bitseq. HB.instance Definition _ := Countable.copy unit (can_type bool_of_unitK). HB.instance Definition _ := Countable.copy void (pcan_type (of_voidK unit)). HB.instance Definition _ T := Countable.copy (option T) (can_type (@seq_of_optK T)). HB.instance Definition _ T (P : pred T) := [Countable of {x | P x} by <:]. HB.instance Definition _ T1 T2 := Countable.copy (T1 * T2)%type (can_type (@tag_of_pairK T1 T2)). HB.instance Definition _ (T1 T2 : countType) := Countable.copy (T1 + T2)%type (pcan_type (@opair_of_sumK T1 T2)). HB.instance Definition _ T := Countable.copy (GenTree.tree T) (pcan_type (GenTree.codeK T)).
Lemma
boot
[ "From HB Require Import structures", "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/choice.v
nat_pickleK
edivn_recd := fix loop m q := if m - d is m'.+1 then loop m' q.+1 else (q, m).
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
edivn_rec
edivnm d := if d > 0 then edivn_rec d.-1 m 0 else (0, m).
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
edivn
edivn_specm d : nat * nat -> Type := EdivnSpec q r of m = q * d + r & (d > 0) ==> (r < d) : edivn_spec m d (q, r).
Variant
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
edivn_spec
edivnPm d : edivn_spec m d (edivn m d). Proof. rewrite -[m in edivn_spec m]/(0 * d + m) /edivn; case: d => //= d. elim/ltn_ind: m 0 => -[|m] IHm q //=; rewrite subn_if_gt. case: ltnP => // le_dm; rewrite -[in m.+1](subnKC le_dm) -addSn. by rewrite addnA -mulSnr; apply/IHm/leq_subr. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
edivnP
edivn_eqd q r : r < d -> edivn (q * d + r) d = (q, r). Proof. move=> lt_rd; have d_gt0: 0 < d by apply: leq_trans lt_rd. case: edivnP lt_rd => q' r'; rewrite d_gt0 /=. wlog: q q' r r' / q <= q' by case/orP: (leq_total q q'); last symmetry; eauto. have [||-> _ /addnI ->] //= := ltngtP q q'. rewrite -(leq_pmul2r d_gt0) => /leq_add lt_qr _ eq_qr _ /lt_qr {lt_qr}. by rewrite addnS ltnNge mulSn -addnA eq_qr addnCA addnA leq_addr. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
edivn_eq
divnm d := (edivn m d).1.
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
divn
modn_recd := fix loop m := if m - d is m'.+1 then loop m' else m.
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
modn_rec
modnm d := if d > 0 then modn_rec d.-1 m else m.
Definition
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
modn
modn_defm d : m %% d = (edivn m d).2. Proof. case: d => //= d; rewrite /modn /edivn /=; elim/ltn_ind: m 0 => -[|m] IHm q //=. by rewrite !subn_if_gt; case: (d <= m) => //; apply/IHm/leq_subr. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
modn_def
edivn_defm d : edivn m d = (m %/ d, m %% d). Proof. by rewrite /divn modn_def; case: (edivn m d). Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
edivn_def
divn_eqm d : m = m %/ d * d + m %% d. Proof. by rewrite /divn modn_def; case: edivnP. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
divn_eq
div0nd : 0 %/ d = 0. Proof. by case: d. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
div0n
divn0m : m %/ 0 = 0. Proof. by []. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
divn0
mod0nd : 0 %% d = 0. Proof. by case: d. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
mod0n
modn0m : m %% 0 = m. Proof. by []. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
modn0
divn_smallm d : m < d -> m %/ d = 0. Proof. by move=> lt_md; rewrite /divn (edivn_eq 0). Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
divn_small
divnMDlq m d : 0 < d -> (q * d + m) %/ d = q + m %/ d. Proof. move=> d_gt0; rewrite [in LHS](divn_eq m d) addnA -mulnDl. by rewrite /divn edivn_eq // modn_def; case: edivnP; rewrite d_gt0. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
divnMDl
mulnKm d : 0 < d -> m * d %/ d = m. Proof. by move=> d_gt0; rewrite -[m * d]addn0 divnMDl // div0n addn0. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
mulnK
mulKnm d : 0 < d -> d * m %/ d = m. Proof. by move=> d_gt0; rewrite mulnC mulnK. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
mulKn
expnBp m n : p > 0 -> m >= n -> p ^ (m - n) = p ^ m %/ p ^ n. Proof. by move=> p_gt0 /subnK-Dm; rewrite -[in RHS]Dm expnD mulnK // expn_gt0 p_gt0. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
expnB
modn1m : m %% 1 = 0. Proof. by rewrite modn_def; case: edivnP => ? []. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
modn1
divn1m : m %/ 1 = m. Proof. by rewrite [RHS](@divn_eq m 1) // modn1 addn0 muln1. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
divn1
divnnd : d %/ d = (0 < d). Proof. by case: d => // d; rewrite -[n in n %/ _]muln1 mulKn. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
divnn
divnMlp m d : p > 0 -> p * m %/ (p * d) = m %/ d. Proof. move=> p_gt0; have [->|d_gt0] := posnP d; first by rewrite muln0. rewrite [RHS]/divn; case: edivnP; rewrite d_gt0 /= => q r ->{m} lt_rd. rewrite mulnDr mulnCA divnMDl; last by rewrite muln_gt0 p_gt0. by rewrite addnC divn_small // ltn_pmul2l. Qed. Arguments divnMl [p m d].
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
divnMl
divnMrp m d : p > 0 -> m * p %/ (d * p) = m %/ d. Proof. by move=> p_gt0; rewrite -!(mulnC p) divnMl. Qed. Arguments divnMr [p m d].
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
divnMr
ltn_modm d : (m %% d < d) = (0 < d). Proof. by case: d => // d; rewrite modn_def; case: edivnP. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
ltn_mod
ltn_pmodm d : 0 < d -> m %% d < d. Proof. by rewrite ltn_mod. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
ltn_pmod
leq_divMm d : m %/ d * d <= m. Proof. by rewrite [leqRHS](divn_eq m d) leq_addr. Qed. #[deprecated(since="mathcomp 2.4.0", note="Renamed to leq_divM.")]
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
leq_divM
leq_trunc_div:= leq_divM.
Notation
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
leq_trunc_div
leq_modm d : m %% d <= m. Proof. by rewrite [leqRHS](divn_eq m d) leq_addl. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
leq_mod
leq_divm d : m %/ d <= m. Proof. by case: d => // d; apply: leq_trans (leq_pmulr _ _) (leq_divM _ _). Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
leq_div
ltn_ceilm d : 0 < d -> m < (m %/ d).+1 * d. Proof. by move=> d_gt0; rewrite [in m.+1](divn_eq m d) -addnS mulSnr leq_add2l ltn_mod. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
ltn_ceil
ltn_divLRm n d : d > 0 -> (m %/ d < n) = (m < n * d). Proof. move=> d_gt0; apply/idP/idP. by rewrite -(leq_pmul2r d_gt0); apply: leq_trans (ltn_ceil _ _). rewrite !ltnNge -(@leq_pmul2r d n) //; apply: contra => le_nd_floor. exact: leq_trans le_nd_floor (leq_divM _ _). Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
ltn_divLR
leq_divRLm n d : d > 0 -> (m <= n %/ d) = (m * d <= n). Proof. by move=> d_gt0; rewrite leqNgt ltn_divLR // -leqNgt. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
leq_divRL
ltn_Pdivm d : 1 < d -> 0 < m -> m %/ d < m. Proof. by move=> d_gt1 m_gt0; rewrite ltn_divLR ?ltn_Pmulr // ltnW. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
ltn_Pdiv
divn_gt0d m : 0 < d -> (0 < m %/ d) = (d <= m). Proof. by move=> d_gt0; rewrite leq_divRL ?mul1n. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
divn_gt0
leq_div2rd m n : m <= n -> m %/ d <= n %/ d. Proof. have [-> //| d_gt0 le_mn] := posnP d. by rewrite leq_divRL // (leq_trans _ le_mn) -?leq_divRL. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
leq_div2r
leq_div2lm d e : 0 < d -> d <= e -> m %/ e <= m %/ d. Proof. move/leq_divRL=> -> le_de. by apply: leq_trans (leq_divM m e); apply: leq_mul. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
leq_div2l
edivnDm n d (offset := m %% d + n %% d >= d) : 0 < d -> edivn (m + n) d = (m %/ d + n %/ d + offset, m %% d + n %% d - offset * d). Proof. rewrite {}/offset; case: d => // d _; rewrite /divn !modn_def. case: (edivnP m d.+1) (edivnP n d.+1) => [/= q r -> r_lt] [/= p s -> s_lt]. rewrite addnACA -mulnDl; have [r_le s_le] := (ltnW r_lt, ltnW s_lt). have [d_ge|d_lt] := leqP; first by rewrite addn0 mul0n subn0 edivn_eq. rewrite addn1 mul1n -[in LHS](subnKC d_lt) addnA -mulSnr edivn_eq//. by rewrite ltn_subLR// -addnS leq_add. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
edivnD
divnDm n d : 0 < d -> (m + n) %/ d = (m %/ d) + (n %/ d) + (m %% d + n %% d >= d). Proof. by move=> /(@edivnD m n); rewrite edivn_def => -[]. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
divnD
modnDm n d : 0 < d -> (m + n) %% d = m %% d + n %% d - (m %% d + n %% d >= d) * d. Proof. by move=> /(@edivnD m n); rewrite edivn_def => -[]. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
modnD
leqDmodm n d : 0 < d -> (d <= m %% d + n %% d) = ((m + n) %% d < n %% d). Proof. move=> d_gt0; rewrite modnD//. have [d_le|_] := leqP d; last by rewrite subn0 ltnNge leq_addl. by rewrite -(ltn_add2r d) mul1n (subnK d_le) addnC ltn_add2l ltn_pmod. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
leqDmod
divnBn m d : 0 < d -> (m - n) %/ d = (m %/ d) - (n %/ d) - (m %% d < n %% d). Proof. move=> d_gt0; have [mn|/ltnW nm] := leqP m n. by rewrite (eqP mn) (eqP (leq_div2r _ _)) ?div0n. by rewrite -[in m %/ d](subnK nm) divnD// addnAC addnK leqDmod ?subnK ?addnK. Qed.
Lemma
boot
[ "From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq" ]
boot/div.v
divnB