src/HOL/Number_Theory/Totient.thy
changeset 66888 930abfdf8727
parent 66803 dd8922885a68
child 67051 e7e54a0b9197
equal deleted inserted replaced
66887:72b78ee82f7b 66888:930abfdf8727
    91                        "x mod m1 = y mod m1" "x mod m2 = y mod m2"
    91                        "x mod m1 = y mod m1" "x mod m2 = y mod m2"
    92     have ex: "\<exists>!z. z < m1 * m2 \<and> [z = x] (mod m1) \<and> [z = x] (mod m2)"
    92     have ex: "\<exists>!z. z < m1 * m2 \<and> [z = x] (mod m1) \<and> [z = x] (mod m2)"
    93       by (rule binary_chinese_remainder_unique_nat) (insert assms, simp_all)
    93       by (rule binary_chinese_remainder_unique_nat) (insert assms, simp_all)
    94     have "x < m1 * m2 \<and> [x = x] (mod m1) \<and> [x = x] (mod m2)"
    94     have "x < m1 * m2 \<and> [x = x] (mod m1) \<and> [x = x] (mod m2)"
    95          "y < m1 * m2 \<and> [y = x] (mod m1) \<and> [y = x] (mod m2)"
    95          "y < m1 * m2 \<and> [y = x] (mod m1) \<and> [y = x] (mod m2)"
    96       using xy assms by (simp_all add: totatives_less one_less_mult cong_nat_def)
    96       using xy assms by (simp_all add: totatives_less one_less_mult cong_def)
    97     from this[THEN the1_equality[OF ex]] show "x = y" by simp
    97     from this[THEN the1_equality[OF ex]] show "x = y" by simp
    98   qed
    98   qed
    99 next
    99 next
   100   show "(\<lambda>x. (x mod m1, x mod m2)) ` totatives (m1 * m2) = totatives m1 \<times> totatives m2"
   100   show "(\<lambda>x. (x mod m1, x mod m2)) ` totatives (m1 * m2) = totatives m1 \<times> totatives m2"
   101   proof safe
   101   proof safe
   104       by (auto simp: totatives_def coprime_mul_eq not_le simp del: One_nat_def intro!: Nat.gr0I)
   104       by (auto simp: totatives_def coprime_mul_eq not_le simp del: One_nat_def intro!: Nat.gr0I)
   105   next
   105   next
   106     fix a b assume ab: "a \<in> totatives m1" "b \<in> totatives m2"
   106     fix a b assume ab: "a \<in> totatives m1" "b \<in> totatives m2"
   107     with assms have ab': "a < m1" "b < m2" by (auto simp: totatives_less)
   107     with assms have ab': "a < m1" "b < m2" by (auto simp: totatives_less)
   108     with binary_chinese_remainder_unique_nat[OF assms(3), of a b] obtain x
   108     with binary_chinese_remainder_unique_nat[OF assms(3), of a b] obtain x
   109       where x: "x < m1 * m2" "x mod m1 = a" "x mod m2 = b" by (auto simp: cong_nat_def)
   109       where x: "x < m1 * m2" "x mod m1 = a" "x mod m2 = b" by (auto simp: cong_def)
   110     from x ab assms(3) have "x \<in> totatives (m1 * m2)"
   110     from x ab assms(3) have "x \<in> totatives (m1 * m2)"
   111       by (auto simp: totatives_def coprime_mul_eq simp del: One_nat_def intro!: Nat.gr0I)
   111       by (auto simp: totatives_def coprime_mul_eq simp del: One_nat_def intro!: Nat.gr0I)
   112     with x show "(a, b) \<in> (\<lambda>x. (x mod m1, x mod m2)) ` totatives (m1*m2)" by blast
   112     with x show "(a, b) \<in> (\<lambda>x. (x mod m1, x mod m2)) ` totatives (m1*m2)" by blast
   113   qed
   113   qed
   114 qed
   114 qed