# HG changeset patch # User haftmann # Date 1663072237 0 # Node ID e7497a1de8b97eb9ac888a5120fa9915d01cb68f # Parent 19837257fd895a68be454b56b3041451f70cd890 more concise instance-specific rules on euclidean relation diff -r 19837257fd89 -r e7497a1de8b9 src/HOL/Divides.thy --- a/src/HOL/Divides.thy Tue Sep 13 18:56:48 2022 +0100 +++ b/src/HOL/Divides.thy Tue Sep 13 12:30:37 2022 +0000 @@ -262,8 +262,8 @@ \a mod b = r\ (is ?R) proof - from assms have \(a div b, a mod b) = (q, r)\ - by (cases b q r a rule: euclidean_relationI) - (auto simp add: division_segment_int_def ac_simps dvd_add_left_iff dest: zdvd_imp_le) + by (cases b q r a rule: euclidean_relation_intI) + (auto simp add: ac_simps dvd_add_left_iff sgn_1_pos le_less dest: zdvd_imp_le) then show ?Q and ?R by simp_all qed @@ -400,34 +400,6 @@ qed -subsubsection \Uniqueness rules\ - -lemma euclidean_relation_intI [case_names by0 divides euclidean_relation]: - \(k div l, k mod l) = (q, r)\ - if by0': \l = 0 \ q = 0 \ r = k\ - and divides': \l \ 0 \ l dvd k \ r = 0 \ k = q * l\ - and euclidean_relation': \l \ 0 \ \ l dvd k \ sgn r = sgn l - \ \r\ < \l\ \ k = q * l + r\ for k l :: int -proof (cases l q r k rule: euclidean_relationI) - case by0 - then show ?case - by (rule by0') -next - case divides - then show ?case - by (rule divides') -next - case euclidean_relation - with euclidean_relation' have \sgn r = sgn l\ \\r\ < \l\\ \k = q * l + r\ - by simp_all - from \sgn r = sgn l\ \l \ 0\ have \division_segment r = division_segment l\ - by (simp add: division_segment_int_def sgn_if split: if_splits) - with \\r\ < \l\\ \k = q * l + r\ - show ?case - by simp -qed - - subsubsection \Computing \div\ and \mod\ with shifting\ lemma div_pos_geq: diff -r 19837257fd89 -r e7497a1de8b9 src/HOL/Euclidean_Division.thy --- a/src/HOL/Euclidean_Division.thy Tue Sep 13 18:56:48 2022 +0100 +++ b/src/HOL/Euclidean_Division.thy Tue Sep 13 12:30:37 2022 +0000 @@ -967,20 +967,27 @@ end +lemma euclidean_relation_natI [case_names by0 divides euclidean_relation]: + \(m div n, m mod n) = (q, r)\ + if by0: \n = 0 \ q = 0 \ r = m\ + and divides: \n > 0 \ n dvd m \ r = 0 \ m = q * n\ + and euclidean_relation: \n > 0 \ \ n dvd m \ r < n \ m = q * n + r\ for m n q r :: nat + by (rule euclidean_relationI) (use that in simp_all) + lemma div_nat_eqI: \m div n = q\ if \n * q \ m\ and \m < n * Suc q\ for m n q :: nat proof - have \(m div n, m mod n) = (q, m - n * q)\ - proof (cases n q \m - n * q\ m rule: euclidean_relationI) + proof (cases n q \m - n * q\ m rule: euclidean_relation_natI) case by0 with that show ?case by simp next case divides from \n dvd m\ obtain s where \m = n * s\ .. - with \n \ 0\ that have \s < Suc q\ + with \n > 0\ that have \s < Suc q\ by (simp only: mult_less_cancel1) - with \m = n * s\ \n \ 0\ that have \q = s\ + with \m = n * s\ \n > 0\ that have \q = s\ by simp with \m = n * s\ show ?case by (simp add: ac_simps) @@ -997,7 +1004,7 @@ \m mod n = r\ if \r < n\ and \r \ m\ and \n dvd m - r\ for m n r :: nat proof - have \(m div n, m mod n) = ((m - r) div n, r)\ - proof (cases n \(m - r) div n\ r m rule: euclidean_relationI) + proof (cases n \(m - r) div n\ r m rule: euclidean_relation_natI) case by0 with that show ?case by simp @@ -1010,9 +1017,9 @@ by (simp add: dvd_add_right_iff) then have \n \ n - r\ by (rule dvd_imp_le) (use \r < n\ in simp) - with \n \ 0\ have \r = 0\ + with \n > 0\ have \r = 0\ by simp - with \n \ 0\ that show ?case + with \n > 0\ that show ?case by simp next case euclidean_relation @@ -1261,14 +1268,14 @@ for m n q :: nat proof - have \(m div (n * q), m mod (n * q)) = ((m div n) div q, n * (m div n mod q) + m mod n)\ - proof (cases \n * q\ \(m div n) div q\ \n * (m div n mod q) + m mod n\ m rule: euclidean_relationI) + proof (cases \n * q\ \(m div n) div q\ \n * (m div n mod q) + m mod n\ m rule: euclidean_relation_natI) case by0 then show ?case by auto next case divides from \n * q dvd m\ obtain t where \m = n * q * t\ .. - with \n * q \ 0\ show ?case + with \n * q > 0\ show ?case by (simp add: algebra_simps) next case euclidean_relation @@ -1812,6 +1819,31 @@ end +lemma euclidean_relation_intI [case_names by0 divides euclidean_relation]: + \(k div l, k mod l) = (q, r)\ + if by0': \l = 0 \ q = 0 \ r = k\ + and divides': \l \ 0 \ l dvd k \ r = 0 \ k = q * l\ + and euclidean_relation': \l \ 0 \ \ l dvd k \ sgn r = sgn l + \ \r\ < \l\ \ k = q * l + r\ for k l :: int +proof (cases l q r k rule: euclidean_relationI) + case by0 + then show ?case + by (rule by0') +next + case divides + then show ?case + by (rule divides') +next + case euclidean_relation + with euclidean_relation' have \sgn r = sgn l\ \\r\ < \l\\ \k = q * l + r\ + by simp_all + from \sgn r = sgn l\ \l \ 0\ have \division_segment r = division_segment l\ + by (simp add: division_segment_int_def sgn_if split: if_splits) + with \\r\ < \l\\ \k = q * l + r\ + show ?case + by simp +qed + subsection \Special case: euclidean rings containing the natural numbers\