src/HOL/Number_Theory/Cong.thy
changeset 62348 9a5f43dac883
parent 61954 1d43f86f48be
child 62349 7c23469b5118
equal deleted inserted replaced
62347:2230b7047376 62348:9a5f43dac883
   555   done
   555   done
   556 
   556 
   557 lemma cong_cong_lcm_nat: "[(x::nat) = y] (mod a) \<Longrightarrow>
   557 lemma cong_cong_lcm_nat: "[(x::nat) = y] (mod a) \<Longrightarrow>
   558     [x = y] (mod b) \<Longrightarrow> [x = y] (mod lcm a b)"
   558     [x = y] (mod b) \<Longrightarrow> [x = y] (mod lcm a b)"
   559   apply (cases "y \<le> x")
   559   apply (cases "y \<le> x")
   560   apply (metis cong_altdef_nat lcm_least_nat)
   560   apply (metis cong_altdef_nat lcm_least)
   561   apply (metis cong_altdef_nat cong_diff_cong_0'_nat lcm_semilattice_nat.sup.bounded_iff le0 minus_nat.diff_0)
   561   apply (metis cong_altdef_nat cong_diff_cong_0'_nat lcm_semilattice_nat.sup.bounded_iff le0 minus_nat.diff_0)
   562   done
   562   done
   563 
   563 
   564 lemma cong_cong_lcm_int: "[(x::int) = y] (mod a) \<Longrightarrow>
   564 lemma cong_cong_lcm_int: "[(x::int) = y] (mod a) \<Longrightarrow>
   565     [x = y] (mod b) \<Longrightarrow> [x = y] (mod lcm a b)"
   565     [x = y] (mod b) \<Longrightarrow> [x = y] (mod lcm a b)"
   566   by (auto simp add: cong_altdef_int lcm_least_int) [1]
   566   by (auto simp add: cong_altdef_int lcm_least) [1]
   567 
   567 
   568 lemma cong_cong_setprod_coprime_nat [rule_format]: "finite A \<Longrightarrow>
   568 lemma cong_cong_setprod_coprime_nat [rule_format]: "finite A \<Longrightarrow>
   569     (\<forall>i\<in>A. (\<forall>j\<in>A. i \<noteq> j \<longrightarrow> coprime (m i) (m j))) \<longrightarrow>
   569     (\<forall>i\<in>A. (\<forall>j\<in>A. i \<noteq> j \<longrightarrow> coprime (m i) (m j))) \<longrightarrow>
   570     (\<forall>i\<in>A. [(x::nat) = y] (mod m i)) \<longrightarrow>
   570     (\<forall>i\<in>A. [(x::nat) = y] (mod m i)) \<longrightarrow>
   571       [x = y] (mod (\<Prod>i\<in>A. m i))"
   571       [x = y] (mod (\<Prod>i\<in>A. m i))"
   589     [b2 = 0] (mod m1) \<and> [b2 = 1] (mod m2)"
   589     [b2 = 0] (mod m1) \<and> [b2 = 1] (mod m2)"
   590 proof -
   590 proof -
   591   from cong_solve_coprime_nat [OF a] obtain x1 where one: "[m1 * x1 = 1] (mod m2)"
   591   from cong_solve_coprime_nat [OF a] obtain x1 where one: "[m1 * x1 = 1] (mod m2)"
   592     by auto
   592     by auto
   593   from a have b: "coprime m2 m1"
   593   from a have b: "coprime m2 m1"
   594     by (subst gcd_commute_nat)
   594     by (subst gcd.commute)
   595   from cong_solve_coprime_nat [OF b] obtain x2 where two: "[m2 * x2 = 1] (mod m1)"
   595   from cong_solve_coprime_nat [OF b] obtain x2 where two: "[m2 * x2 = 1] (mod m1)"
   596     by auto
   596     by auto
   597   have "[m1 * x1 = 0] (mod m1)"
   597   have "[m1 * x1 = 0] (mod m1)"
   598     by (subst mult.commute, rule cong_mult_self_nat)
   598     by (subst mult.commute, rule cong_mult_self_nat)
   599   moreover have "[m2 * x2 = 0] (mod m2)"
   599   moreover have "[m2 * x2 = 0] (mod m2)"
   608     [b2 = 0] (mod m1) \<and> [b2 = 1] (mod m2)"
   608     [b2 = 0] (mod m1) \<and> [b2 = 1] (mod m2)"
   609 proof -
   609 proof -
   610   from cong_solve_coprime_int [OF a] obtain x1 where one: "[m1 * x1 = 1] (mod m2)"
   610   from cong_solve_coprime_int [OF a] obtain x1 where one: "[m1 * x1 = 1] (mod m2)"
   611     by auto
   611     by auto
   612   from a have b: "coprime m2 m1"
   612   from a have b: "coprime m2 m1"
   613     by (subst gcd_commute_int)
   613     by (subst gcd.commute)
   614   from cong_solve_coprime_int [OF b] obtain x2 where two: "[m2 * x2 = 1] (mod m1)"
   614   from cong_solve_coprime_int [OF b] obtain x2 where two: "[m2 * x2 = 1] (mod m1)"
   615     by auto
   615     by auto
   616   have "[m1 * x1 = 0] (mod m1)"
   616   have "[m1 * x1 = 0] (mod m1)"
   617     by (subst mult.commute, rule cong_mult_self_int)
   617     by (subst mult.commute, rule cong_mult_self_int)
   618   moreover have "[m2 * x2 = 0] (mod m2)"
   618   moreover have "[m2 * x2 = 0] (mod m2)"