1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| A.Asperti, C.Sacerdoti Coen, *)
8 (* ||A|| E.Tassi, S.Zacchiroli *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU Lesser General Public License Version 2.1 *)
13 (**************************************************************************)
15 set "baseuri" "cic:/matita/nat/totient".
17 include "nat/count.ma".
18 include "nat/chinese_reminder.ma".
20 definition totient : nat \to nat \def
21 \lambda n. count n (\lambda m. eqb (gcd m n) (S O)).
23 theorem totient3: totient (S(S(S O))) = (S(S O)).
27 theorem totient6: totient (S(S(S(S(S(S O)))))) = (S(S O)).
31 theorem totient_times: \forall n,m:nat. (gcd m n) = (S O) \to
32 totient (n*m) = (totient n)*(totient m).
35 intro.simplify.intro.reflexivity.
36 intros 2.apply (nat_case m1).
38 rewrite < (sym_times (totient O)).
39 simplify.intro.reflexivity.
42 apply (count_times m m2 ? ? ?
43 (\lambda b,a. cr_pair (S m) (S m2) a b) (\lambda x. x \mod (S m)) (\lambda x. x \mod (S m2))).
44 intros.unfold cr_pair.
45 apply (le_to_lt_to_lt ? (pred ((S m)*(S m2)))).
48 change with ((S (pred ((S m)*(S m2)))) \le ((S m)*(S m2))).
49 apply (nat_case ((S m)*(S m2))).apply le_n.
52 generalize in match (mod_cr_pair (S m) (S m2) a b H1 H2 H).
56 generalize in match (mod_cr_pair (S m) (S m2) a b H1 H2 H).
60 generalize in match (mod_cr_pair (S m) (S m2) a b H1 H2 H).
64 rewrite > eq_to_eqb_true.
65 rewrite > eq_to_eqb_true.
70 apply (gcd_times_SO_to_gcd_SO ? ? (S m2)).
71 unfold lt.apply le_S_S.apply le_O_n.
72 unfold lt.apply le_S_S.apply le_O_n.
74 unfold lt.apply le_S_S.apply le_O_n.
78 apply (gcd_times_SO_to_gcd_SO ? ? (S m)).
79 unfold lt.apply le_S_S.apply le_O_n.
80 unfold lt.apply le_S_S.apply le_O_n.
83 unfold lt.apply le_S_S.apply le_O_n.
87 intro.apply False_ind.
89 apply eq_gcd_times_SO.
90 unfold lt.apply le_S_S.apply le_O_n.
91 unfold lt.apply le_S_S.apply le_O_n.
94 rewrite > sym_gcd.assumption.
95 unfold lt.apply le_S_S.apply le_O_n.
98 rewrite > sym_gcd.assumption.
99 unfold lt.apply le_S_S.apply le_O_n.