author | haftmann |
Mon, 13 Sep 2021 14:18:24 +0000 | |
changeset 74309 | 42523fbf643b |
parent 72990 | db8f94656024 |
permissions | -rw-r--r-- |
1476 | 1 |
(* Title: HOL/Hoare/Arith2.thy |
2 |
Author: Norbert Galm |
|
1335 | 3 |
Copyright 1995 TUM |
4 |
*) |
|
5 |
||
72990 | 6 |
section \<open>More arithmetic\<close> |
7 |
||
17278 | 8 |
theory Arith2 |
72990 | 9 |
imports Main |
17278 | 10 |
begin |
1335 | 11 |
|
67613 | 12 |
definition cd :: "[nat, nat, nat] \<Rightarrow> bool" |
13 |
where "cd x m n \<longleftrightarrow> x dvd m \<and> x dvd n" |
|
1335 | 14 |
|
67613 | 15 |
definition gcd :: "[nat, nat] \<Rightarrow> nat" |
16 |
where "gcd m n = (SOME x. cd x m n & (\<forall>y.(cd y m n) \<longrightarrow> y\<le>x))" |
|
5183 | 17 |
|
67613 | 18 |
primrec fac :: "nat \<Rightarrow> nat" |
38353 | 19 |
where |
5183 | 20 |
"fac 0 = Suc 0" |
38353 | 21 |
| "fac (Suc n) = Suc n * fac n" |
1335 | 22 |
|
19802 | 23 |
|
72990 | 24 |
subsection \<open>cd\<close> |
19802 | 25 |
|
67613 | 26 |
lemma cd_nnn: "0<n \<Longrightarrow> cd n n n" |
19802 | 27 |
apply (simp add: cd_def) |
28 |
done |
|
29 |
||
30 |
lemma cd_le: "[| cd x m n; 0<m; 0<n |] ==> x<=m & x<=n" |
|
31 |
apply (unfold cd_def) |
|
32 |
apply (blast intro: dvd_imp_le) |
|
33 |
done |
|
34 |
||
35 |
lemma cd_swap: "cd x m n = cd x n m" |
|
36 |
apply (unfold cd_def) |
|
37 |
apply blast |
|
38 |
done |
|
39 |
||
67613 | 40 |
lemma cd_diff_l: "n\<le>m \<Longrightarrow> cd x m n = cd x (m-n) n" |
19802 | 41 |
apply (unfold cd_def) |
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
38353
diff
changeset
|
42 |
apply (fastforce dest: dvd_diffD) |
19802 | 43 |
done |
44 |
||
67613 | 45 |
lemma cd_diff_r: "m\<le>n \<Longrightarrow> cd x m n = cd x m (n-m)" |
19802 | 46 |
apply (unfold cd_def) |
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
38353
diff
changeset
|
47 |
apply (fastforce dest: dvd_diffD) |
19802 | 48 |
done |
49 |
||
50 |
||
72990 | 51 |
subsection \<open>gcd\<close> |
19802 | 52 |
|
67613 | 53 |
lemma gcd_nnn: "0<n \<Longrightarrow> n = gcd n n" |
19802 | 54 |
apply (unfold gcd_def) |
55 |
apply (frule cd_nnn) |
|
56 |
apply (rule some_equality [symmetric]) |
|
57 |
apply (blast dest: cd_le) |
|
33657 | 58 |
apply (blast intro: le_antisym dest: cd_le) |
19802 | 59 |
done |
60 |
||
61 |
lemma gcd_swap: "gcd m n = gcd n m" |
|
62 |
apply (simp add: gcd_def cd_swap) |
|
63 |
done |
|
64 |
||
67613 | 65 |
lemma gcd_diff_l: "n\<le>m \<Longrightarrow> gcd m n = gcd (m-n) n" |
19802 | 66 |
apply (unfold gcd_def) |
67613 | 67 |
apply (subgoal_tac "n\<le>m \<Longrightarrow> \<forall>x. cd x m n = cd x (m-n) n") |
19802 | 68 |
apply simp |
69 |
apply (rule allI) |
|
70 |
apply (erule cd_diff_l) |
|
71 |
done |
|
72 |
||
67613 | 73 |
lemma gcd_diff_r: "m\<le>n \<Longrightarrow> gcd m n = gcd m (n-m)" |
19802 | 74 |
apply (unfold gcd_def) |
67613 | 75 |
apply (subgoal_tac "m\<le>n \<Longrightarrow> \<forall>x. cd x m n = cd x m (n-m) ") |
19802 | 76 |
apply simp |
77 |
apply (rule allI) |
|
78 |
apply (erule cd_diff_r) |
|
79 |
done |
|
80 |
||
81 |
||
72990 | 82 |
subsection \<open>pow\<close> |
19802 | 83 |
|
84 |
lemma sq_pow_div2 [simp]: |
|
67613 | 85 |
"m mod 2 = 0 \<Longrightarrow> ((n::nat)*n)^(m div 2) = n^m" |
64246 | 86 |
apply (simp add: power2_eq_square [symmetric] power_mult [symmetric] minus_mod_eq_mult_div [symmetric]) |
19802 | 87 |
done |
17278 | 88 |
|
1335 | 89 |
end |