@@ -52,32 +52,32 @@ move=> n_pos b_gt1 d_digit.
5252rewrite /sum_fact ndigitsMD // big_ord_recl; congr (_ + _).
5353 by rewrite digitn0 mulnC modnMDl modn_small.
5454apply: eq_bigr => /= i _.
55- by rewrite digitn_mulD // ltnW.
55+ by rewrite digitnMD // ltnW.
5656Qed .
5757
5858Lemma sum_factM b n :
5959 0 < n -> 1 < b -> sum_fact b (b * n) = (sum_fact b n).+1.
6060Proof . by move=> ? ?; rewrite -[b * n]addn0 sum_factMD // ltnW. Qed .
6161
62- Definition factorion (n : nat) := sum_fact 10 n == n.
62+ Definition factorion := [qualify a n | sum_fact 10 n == n] .
6363
64- Lemma factorion0 : ~ factorion 0 .
65- Proof . by rewrite /factorion /sum_fact !big_ord_recr /= big_ord0. Qed .
64+ Lemma factorion0 : 0 \isn't a factorion .
65+ Proof . by rewrite qualifE /sum_fact !big_ord_recr /= big_ord0. Qed .
6666
67- Lemma factorion1 : factorion 1 .
68- Proof . by rewrite /factorion /sum_fact !big_ord_recr /= big_ord0. Qed .
67+ Lemma factorion1 : 1 \is a factorion .
68+ Proof . by rewrite qualifE /sum_fact !big_ord_recr /= big_ord0. Qed .
6969
70- Lemma factorion2 : factorion 2 .
71- Proof . by rewrite /factorion /sum_fact !big_ord_recr /= big_ord0. Qed .
70+ Lemma factorion2 : 2 \is a factorion .
71+ Proof . by rewrite qualifE /sum_fact !big_ord_recr /= big_ord0. Qed .
7272
73- Lemma factorion145 : factorion 145.
73+ Lemma factorion145 : 145 \is a factorion .
7474Proof .
75- by rewrite /factorion /sum_fact -[ndigits 10 145]/3 !big_ord_recr big_ord0.
75+ by rewrite qualifE /sum_fact -[ndigits 10 145]/3 !big_ord_recr big_ord0.
7676Qed .
7777
78- Lemma factorion40585 : factorion v40585.
78+ Lemma factorion40585 : v40585 \is a factorion .
7979Proof .
80- by rewrite /factorion /sum_fact -[ndigits 10 v40585]/5 !big_ord_recr big_ord0.
80+ by rewrite qualifE /sum_fact -[ndigits 10 v40585]/5 !big_ord_recr big_ord0.
8181Qed .
8282
8383Lemma sum_fact_bound b n : 1 < b -> sum_fact b n <= ndigits b n * b.-1 `!.
@@ -87,12 +87,12 @@ rewrite -[X in _ <= X * _]subn0 -[X in _ <= X]sum_nat_const_nat big_mkord.
8787elim: ndigits => [|k IH]; first by rewrite !big_ord0.
8888rewrite !big_ord_recr /= leq_add //.
8989case: (b) b_pos => // [] [|b1] // _.
90- case: digitn (ltn_pdigit n k (isT : 0 < b1.+2))=> [_ |d dLb] //.
90+ case: digitn (ltn_digitn n k (isT : 0 < b1.+2))=> [_ |d dLb] //.
9191 by rewrite -[0 `!]/(1 `!) leq_pfact.
9292by rewrite leq_pfact.
9393Qed .
9494
95- Lemma sum_fact10_increasing n : 7 < ndigits 10 n -> sum_fact 10 n < n.
95+ Lemma ltn_sum_fact10 n : 7 < ndigits 10 n -> sum_fact 10 n < n.
9696Proof .
9797move=> nL7.
9898have n_pos : 0 < n by case: n nL7.
@@ -109,9 +109,9 @@ rewrite leq_pmul2r // -subSS subSn // -[X in X <= _](subnK nL7).
109109by elim: (_ - _) => // k IH; rewrite (leq_ltn_trans IH _) // ltn_exp2l.
110110Qed .
111111
112- Lemma factorion_upperbound n : factorion n -> ndigits 10 n <= 7.
112+ Lemma factorion_upperbound n : n \is a factorion -> ndigits 10 n <= 7.
113113Proof .
114- by move=> Hf; case: leqP => // /sum_fact10_increasing ; rewrite (eqP Hf) ltnn.
114+ by move=> Hf; case: leqP => // /ltn_sum_fact10 ; rewrite (eqP Hf) ltnn.
115115Qed .
116116
117117Fixpoint fact_look_up1 (r : rel N) (k : nat) (n p : N) (l : seq N) : seq N :=
@@ -279,7 +279,7 @@ case=> [d9E|].
279279 by congr ((_ * (_ * (_ * _)%coq_nat)%coq_nat)%coq_nat + _)%coq_nat.
280280move=> d d1E.
281281suff : d1 < 10 by rewrite d1E.
282- by apply: ltn_pdigit .
282+ by apply: ltn_digitn .
283283Qed .
284284
285285Definition fact_look_up r k : seq N :=
@@ -351,10 +351,10 @@ case => [d9E mE|].
351351 by congr (_ * (_ * _)%coq_nat)%coq_nat.
352352move=> d d1E.
353353suff : d1 < 10 by rewrite d1E.
354- by apply: ltn_pdigit .
354+ by apply: ltn_digitn .
355355Qed .
356356
357- Lemma factorionE m : factorion m = (m \in [::1; 2; 145; v40585]).
357+ Lemma factorionE m : m \is a factorion = (m \in [::1; 2; 145; v40585]).
358358Proof .
359359apply/idP/idP; last first.
360360 rewrite !inE; case/or4P => /eqP->.
@@ -377,7 +377,7 @@ have := ndigits_gt0 10 m.
377377pose get_factorion d := fact_look_up [rel m n | (m =? n)%num] d.
378378have : N.of_nat m \in get_factorion (ndigits 10 m).-1.
379379 apply: fact_look_up_spec => /=.
380- by case: (m) mF factorion0 => // [].
380+ by case: (m) mF factorion0 => // ? /negP [].
381381 by rewrite (eqP mF); case: N.eqb_spec.
382382case: ndigits => //.
383383case.
@@ -549,7 +549,7 @@ by rewrite -[169 in LHS]Nat2N.id -Nsum_fact10_spec.
549549Qed .
550550
551551(* *)
552- Lemma sum_fact10_iter_increase n :
552+ Lemma leq_sum_fact10_iter n :
553553 exists k, let v := iter k (sum_fact 10) n in v <= (sum_fact 10 v).
554554Proof .
555555have [k nLk]:= ubnP n; elim: k n nLk => [[]//|k IH n nLk].
590590Definition cend_in_cycle n m :=
591591 if (n <? m)%num then ~~ check_loop m 60 else false.
592592
593- Check fact_look_up_spec .
594593Lemma cend_in_cycleN_spec n m :
595594 ~~ cend_in_cycle n m -> (n <? m)%num -> m = Nsum_fact10 n ->
596595 exists k,
613612Lemma factorion_no_large_cycle n :
614613 exists k, iter k (sum_fact 10) n \in [:: 1; 2; 145; v40585; 871; 872; 169].
615614Proof .
616- case: (sum_fact10_iter_increase n) => k.
615+ case: (leq_sum_fact10_iter n) => k.
617616set v := iter k (sum_fact 10) n => /=.
618617rewrite leq_eqVlt => /orP[/eqP vE| vLs].
619618 exists k; rewrite -/v.
@@ -626,7 +625,7 @@ suff [k1 Hk1] : exists k,
626625have [|v_pos] := leqP v 0.
627626 by rewrite leqn0 => /eqP->; exists 1; rewrite /= sum_fact0 !inE.
628627have nL7 : ndigits 10 v <= 7.
629- by case: leqP => // /sum_fact10_increasing ; rewrite ltnNge leq_eqVlt vLs orbT.
628+ by case: leqP => // /ltn_sum_fact10 ; rewrite ltnNge leq_eqVlt vLs orbT.
630629pose get_list := fact_look_up cend_in_cycle.
631630suff g_nil : get_list (ndigits 10 v).-1 = [::].
632631 have Hv := @fact_look_up_spec cend_in_cycle _ v_pos.
0 commit comments