src/HOL/Parity.thy
author haftmann
Sun, 08 Oct 2017 22:28:22 +0200
changeset 66817 0b12755ccbb2
parent 66816 212a3334e7da
child 66839 909ba5ed93dd
permissions -rw-r--r--
euclidean rings need no normalization
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41959
b460124855b8 tuned headers;
wenzelm
parents: 36840
diff changeset
     1
(*  Title:      HOL/Parity.thy
b460124855b8 tuned headers;
wenzelm
parents: 36840
diff changeset
     2
    Author:     Jeremy Avigad
b460124855b8 tuned headers;
wenzelm
parents: 36840
diff changeset
     3
    Author:     Jacques D. Fleuriot
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     4
*)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     5
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60562
diff changeset
     6
section \<open>Parity in rings and semirings\<close>
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     7
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     8
theory Parity
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
     9
  imports Euclidean_Division
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    10
begin
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    11
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61531
diff changeset
    12
subsection \<open>Ring structures with parity and \<open>even\<close>/\<open>odd\<close> predicates\<close>
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    13
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    14
class semiring_parity = linordered_semidom + unique_euclidean_semiring +
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    15
  assumes of_nat_div: "of_nat (m div n) = of_nat m div of_nat n"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    16
    and odd_imp_mod_2_eq_1: "\<not> 2 dvd a \<Longrightarrow> a mod 2 = 1"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    17
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    18
context semiring_parity
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
    19
begin
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    20
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    21
lemma of_nat_dvd_iff:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    22
  "of_nat m dvd of_nat n \<longleftrightarrow> m dvd n" (is "?P \<longleftrightarrow> ?Q")
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    23
proof (cases "m = 0")
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    24
  case True
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    25
  then show ?thesis
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    26
    by simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    27
next
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    28
  case False
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    29
  show ?thesis
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    30
  proof
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    31
    assume ?Q
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    32
    then show ?P
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    33
      by (auto elim: dvd_class.dvdE)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    34
  next
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    35
    assume ?P
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    36
    with False have "of_nat n = of_nat n div of_nat m * of_nat m"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    37
      by simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    38
    then have "of_nat n = of_nat (n div m * m)"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    39
      by (simp add: of_nat_div)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    40
    then have "n = n div m * m"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    41
      by (simp only: of_nat_eq_iff)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    42
    then have "n = m * (n div m)"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    43
      by (simp add: ac_simps)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    44
    then show ?Q ..
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    45
  qed
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    46
qed
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    47
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    48
lemma of_nat_mod:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    49
  "of_nat (m mod n) = of_nat m mod of_nat n"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    50
proof -
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    51
  have "of_nat m div of_nat n * of_nat n + of_nat m mod of_nat n = of_nat m"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    52
    by (simp add: div_mult_mod_eq)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    53
  also have "of_nat m = of_nat (m div n * n + m mod n)"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    54
    by simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    55
  finally show ?thesis
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    56
    by (simp only: of_nat_div of_nat_mult of_nat_add) simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    57
qed
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    58
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    59
lemma one_div_two_eq_zero [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    60
  "1 div 2 = 0"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    61
proof -
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    62
  from of_nat_div [symmetric] have "of_nat 1 div of_nat 2 = of_nat 0"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    63
    by (simp only:) simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    64
  then show ?thesis
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    65
    by simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    66
qed
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    67
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    68
lemma one_mod_two_eq_one [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    69
  "1 mod 2 = 1"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    70
proof -
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    71
  from of_nat_mod [symmetric] have "of_nat 1 mod of_nat 2 = of_nat 1"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    72
    by (simp only:) simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    73
  then show ?thesis
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    74
    by simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    75
qed
59816
034b13f4efae distributivity of partial minus establishes desired properties of dvd in semirings
haftmann
parents: 58889
diff changeset
    76
58740
cb9d84d3e7f2 turn even into an abbreviation
haftmann
parents: 58718
diff changeset
    77
abbreviation even :: "'a \<Rightarrow> bool"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    78
  where "even a \<equiv> 2 dvd a"
54228
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    79
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    80
abbreviation odd :: "'a \<Rightarrow> bool"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    81
  where "odd a \<equiv> \<not> 2 dvd a"
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    82
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    83
lemma even_iff_mod_2_eq_zero:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    84
  "even a \<longleftrightarrow> a mod 2 = 0"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    85
  by (fact dvd_eq_mod_eq_0)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    86
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    87
lemma odd_iff_mod_2_eq_one:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    88
  "odd a \<longleftrightarrow> a mod 2 = 1"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    89
  by (auto dest: odd_imp_mod_2_eq_1)
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    90
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    91
lemma parity_cases [case_names even odd]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    92
  assumes "even a \<Longrightarrow> a mod 2 = 0 \<Longrightarrow> P"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    93
  assumes "odd a \<Longrightarrow> a mod 2 = 1 \<Longrightarrow> P"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    94
  shows P
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    95
  using assms by (cases "even a") (simp_all add: odd_iff_mod_2_eq_one)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    96
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    97
lemma not_mod_2_eq_1_eq_0 [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    98
  "a mod 2 \<noteq> 1 \<longleftrightarrow> a mod 2 = 0"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
    99
  by (cases a rule: parity_cases) simp_all
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   100
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   101
lemma not_mod_2_eq_0_eq_1 [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   102
  "a mod 2 \<noteq> 0 \<longleftrightarrow> a mod 2 = 1"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   103
  by (cases a rule: parity_cases) simp_all
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   104
58690
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   105
lemma evenE [elim?]:
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   106
  assumes "even a"
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   107
  obtains b where "a = 2 * b"
58740
cb9d84d3e7f2 turn even into an abbreviation
haftmann
parents: 58718
diff changeset
   108
  using assms by (rule dvdE)
58690
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   109
58681
a478a0742a8e legacy cleanup
haftmann
parents: 58680
diff changeset
   110
lemma oddE [elim?]:
58680
6b2fa479945f more algebraic deductions for facts on even/odd
haftmann
parents: 58679
diff changeset
   111
  assumes "odd a"
6b2fa479945f more algebraic deductions for facts on even/odd
haftmann
parents: 58679
diff changeset
   112
  obtains b where "a = 2 * b + 1"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   113
proof -
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   114
  have "a = 2 * (a div 2) + a mod 2"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   115
    by (simp add: mult_div_mod_eq)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   116
  with assms have "a = 2 * (a div 2) + 1"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   117
    by (simp add: odd_iff_mod_2_eq_one)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   118
  then show ?thesis ..
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   119
qed
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   120
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   121
lemma mod_2_eq_odd:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   122
  "a mod 2 = of_bool (odd a)"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   123
  by (auto elim: oddE)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   124
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   125
lemma one_mod_2_pow_eq [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   126
  "1 mod (2 ^ n) = of_bool (n > 0)"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   127
proof -
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   128
  have "1 mod (2 ^ n) = (of_bool (n > 0) :: nat)"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   129
    by (induct n) (simp_all add: mod_mult2_eq)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   130
  then have "of_nat (1 mod (2 ^ n)) = of_bool (n > 0)"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   131
    by simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   132
  then show ?thesis
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   133
    by (simp add: of_nat_mod)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   134
qed
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   135
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   136
lemma even_of_nat [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   137
  "even (of_nat a) \<longleftrightarrow> even a"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   138
proof -
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   139
  have "even (of_nat a) \<longleftrightarrow> of_nat 2 dvd of_nat a"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   140
    by simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   141
  also have "\<dots> \<longleftrightarrow> even a"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   142
    by (simp only: of_nat_dvd_iff)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   143
  finally show ?thesis .
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   144
qed
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   145
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   146
lemma even_zero [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   147
  "even 0"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   148
  by (fact dvd_0_right)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   149
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   150
lemma odd_one [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   151
  "odd 1"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   152
proof -
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   153
  have "\<not> (2 :: nat) dvd 1"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   154
    by simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   155
  then have "\<not> of_nat 2 dvd of_nat 1"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   156
    unfolding of_nat_dvd_iff by simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   157
  then show ?thesis
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   158
    by simp
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   159
qed
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   160
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   161
lemma odd_even_add:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   162
  "even (a + b)" if "odd a" and "odd b"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   163
proof -
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   164
  from that obtain c d where "a = 2 * c + 1" and "b = 2 * d + 1"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   165
    by (blast elim: oddE)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   166
  then have "a + b = 2 * c + 2 * d + (1 + 1)"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   167
    by (simp only: ac_simps)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   168
  also have "\<dots> = 2 * (c + d + 1)"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   169
    by (simp add: algebra_simps)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   170
  finally show ?thesis ..
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   171
qed
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   172
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   173
lemma even_add [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   174
  "even (a + b) \<longleftrightarrow> (even a \<longleftrightarrow> even b)"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   175
  by (auto simp add: dvd_add_right_iff dvd_add_left_iff odd_even_add)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   176
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   177
lemma odd_add [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   178
  "odd (a + b) \<longleftrightarrow> \<not> (odd a \<longleftrightarrow> odd b)"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   179
  by simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   180
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   181
lemma even_plus_one_iff [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   182
  "even (a + 1) \<longleftrightarrow> odd a"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   183
  by (auto simp add: dvd_add_right_iff intro: odd_even_add)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   184
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   185
lemma even_mult_iff [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   186
  "even (a * b) \<longleftrightarrow> even a \<or> even b" (is "?P \<longleftrightarrow> ?Q")
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   187
proof
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   188
  assume ?Q
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   189
  then show ?P
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   190
    by auto
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   191
next
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   192
  assume ?P
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   193
  show ?Q
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   194
  proof (rule ccontr)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   195
    assume "\<not> (even a \<or> even b)"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   196
    then have "odd a" and "odd b"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   197
      by auto
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   198
    then obtain r s where "a = 2 * r + 1" and "b = 2 * s + 1"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   199
      by (blast elim: oddE)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   200
    then have "a * b = (2 * r + 1) * (2 * s + 1)"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   201
      by simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   202
    also have "\<dots> = 2 * (2 * r * s + r + s) + 1"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   203
      by (simp add: algebra_simps)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   204
    finally have "odd (a * b)"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   205
      by simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   206
    with \<open>?P\<close> show False
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   207
      by auto
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   208
  qed
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   209
qed
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   210
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   211
lemma even_numeral [simp]: "even (numeral (Num.Bit0 n))"
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   212
proof -
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   213
  have "even (2 * numeral n)"
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   214
    unfolding even_mult_iff by simp
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   215
  then have "even (numeral n + numeral n)"
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   216
    unfolding mult_2 .
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   217
  then show ?thesis
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   218
    unfolding numeral.simps .
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   219
qed
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   220
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   221
lemma odd_numeral [simp]: "odd (numeral (Num.Bit1 n))"
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   222
proof
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   223
  assume "even (numeral (num.Bit1 n))"
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   224
  then have "even (numeral n + numeral n + 1)"
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   225
    unfolding numeral.simps .
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   226
  then have "even (2 * numeral n + 1)"
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   227
    unfolding mult_2 .
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   228
  then have "2 dvd numeral n * 2 + 1"
58740
cb9d84d3e7f2 turn even into an abbreviation
haftmann
parents: 58718
diff changeset
   229
    by (simp add: ac_simps)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   230
  then have "2 dvd 1"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   231
    using dvd_add_times_triv_left_iff [of 2 "numeral n" 1] by simp
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   232
  then show False by simp
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   233
qed
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   234
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   235
lemma even_power [simp]: "even (a ^ n) \<longleftrightarrow> even a \<and> n > 0"
58680
6b2fa479945f more algebraic deductions for facts on even/odd
haftmann
parents: 58679
diff changeset
   236
  by (induct n) auto
6b2fa479945f more algebraic deductions for facts on even/odd
haftmann
parents: 58679
diff changeset
   237
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   238
lemma even_succ_div_two [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   239
  "even a \<Longrightarrow> (a + 1) div 2 = a div 2"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   240
  by (cases "a = 0") (auto elim!: evenE dest: mult_not_zero)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   241
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   242
lemma odd_succ_div_two [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   243
  "odd a \<Longrightarrow> (a + 1) div 2 = a div 2 + 1"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   244
  by (auto elim!: oddE simp add: add.assoc)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   245
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   246
lemma even_two_times_div_two:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   247
  "even a \<Longrightarrow> 2 * (a div 2) = a"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   248
  by (fact dvd_mult_div_cancel)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   249
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   250
lemma odd_two_times_div_two_succ [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   251
  "odd a \<Longrightarrow> 2 * (a div 2) + 1 = a"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   252
  using mult_div_mod_eq [of 2 a]
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   253
  by (simp add: even_iff_mod_2_eq_zero)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   254
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   255
end
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
   256
59816
034b13f4efae distributivity of partial minus establishes desired properties of dvd in semirings
haftmann
parents: 58889
diff changeset
   257
class ring_parity = ring + semiring_parity
58679
33c90658448a more algebraic deductions for facts on even/odd
haftmann
parents: 58678
diff changeset
   258
begin
33c90658448a more algebraic deductions for facts on even/odd
haftmann
parents: 58678
diff changeset
   259
59816
034b13f4efae distributivity of partial minus establishes desired properties of dvd in semirings
haftmann
parents: 58889
diff changeset
   260
subclass comm_ring_1 ..
034b13f4efae distributivity of partial minus establishes desired properties of dvd in semirings
haftmann
parents: 58889
diff changeset
   261
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   262
lemma even_minus [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   263
  "even (- a) \<longleftrightarrow> even a"
58740
cb9d84d3e7f2 turn even into an abbreviation
haftmann
parents: 58718
diff changeset
   264
  by (fact dvd_minus_iff)
58679
33c90658448a more algebraic deductions for facts on even/odd
haftmann
parents: 58678
diff changeset
   265
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   266
lemma even_diff [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   267
  "even (a - b) \<longleftrightarrow> even (a + b)"
58680
6b2fa479945f more algebraic deductions for facts on even/odd
haftmann
parents: 58679
diff changeset
   268
  using even_add [of a "- b"] by simp
6b2fa479945f more algebraic deductions for facts on even/odd
haftmann
parents: 58679
diff changeset
   269
58679
33c90658448a more algebraic deductions for facts on even/odd
haftmann
parents: 58678
diff changeset
   270
end
33c90658448a more algebraic deductions for facts on even/odd
haftmann
parents: 58678
diff changeset
   271
66808
1907167b6038 elementary definition of division on natural numbers
haftmann
parents: 66582
diff changeset
   272
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   273
subsection \<open>Instance for @{typ nat}\<close>
66808
1907167b6038 elementary definition of division on natural numbers
haftmann
parents: 66582
diff changeset
   274
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   275
instance nat :: semiring_parity
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   276
  by standard (simp_all add: dvd_eq_mod_eq_0)
66808
1907167b6038 elementary definition of division on natural numbers
haftmann
parents: 66582
diff changeset
   277
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   278
lemma even_Suc_Suc_iff [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   279
  "even (Suc (Suc n)) \<longleftrightarrow> even n"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   280
  using dvd_add_triv_right_iff [of 2 n] by simp
58687
5469874b0228 even more cleanup
haftmann
parents: 58681
diff changeset
   281
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   282
lemma even_Suc [simp]: "even (Suc n) \<longleftrightarrow> odd n"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   283
  using even_plus_one_iff [of n] by simp
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   284
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   285
lemma even_diff_nat [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   286
  "even (m - n) \<longleftrightarrow> m < n \<or> even (m + n)" for m n :: nat
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   287
proof (cases "n \<le> m")
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   288
  case True
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   289
  then have "m - n + n * 2 = m + n" by (simp add: mult_2_right)
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   290
  moreover have "even (m - n) \<longleftrightarrow> even (m - n + n * 2)" by simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   291
  ultimately have "even (m - n) \<longleftrightarrow> even (m + n)" by (simp only:)
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   292
  then show ?thesis by auto
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   293
next
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   294
  case False
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   295
  then show ?thesis by simp
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   296
qed
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   297
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   298
lemma odd_pos:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   299
  "odd n \<Longrightarrow> 0 < n" for n :: nat
58690
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   300
  by (auto elim: oddE)
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   301
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   302
lemma Suc_double_not_eq_double:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   303
  "Suc (2 * m) \<noteq> 2 * n"
62597
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   304
proof
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   305
  assume "Suc (2 * m) = 2 * n"
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   306
  moreover have "odd (Suc (2 * m))" and "even (2 * n)"
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   307
    by simp_all
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   308
  ultimately show False by simp
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   309
qed
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   310
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   311
lemma double_not_eq_Suc_double:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   312
  "2 * m \<noteq> Suc (2 * n)"
62597
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   313
  using Suc_double_not_eq_double [of n m] by simp
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   314
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   315
lemma odd_Suc_minus_one [simp]: "odd n \<Longrightarrow> Suc (n - Suc 0) = n"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   316
  by (auto elim: oddE)
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   317
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   318
lemma even_Suc_div_two [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   319
  "even n \<Longrightarrow> Suc n div 2 = n div 2"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   320
  using even_succ_div_two [of n] by simp
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   321
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   322
lemma odd_Suc_div_two [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   323
  "odd n \<Longrightarrow> Suc n div 2 = Suc (n div 2)"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   324
  using odd_succ_div_two [of n] by simp
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   325
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   326
lemma odd_two_times_div_two_nat [simp]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   327
  assumes "odd n"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   328
  shows "2 * (n div 2) = n - (1 :: nat)"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   329
proof -
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   330
  from assms have "2 * (n div 2) + 1 = n"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   331
    by (rule odd_two_times_div_two_succ)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   332
  then have "Suc (2 * (n div 2)) - 1 = n - 1"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   333
    by simp
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   334
  then show ?thesis
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   335
    by simp
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   336
qed
58680
6b2fa479945f more algebraic deductions for facts on even/odd
haftmann
parents: 58679
diff changeset
   337
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   338
lemma parity_induct [case_names zero even odd]:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   339
  assumes zero: "P 0"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   340
  assumes even: "\<And>n. P n \<Longrightarrow> P (2 * n)"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   341
  assumes odd: "\<And>n. P n \<Longrightarrow> P (Suc (2 * n))"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   342
  shows "P n"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   343
proof (induct n rule: less_induct)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   344
  case (less n)
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   345
  show "P n"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   346
  proof (cases "n = 0")
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   347
    case True with zero show ?thesis by simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   348
  next
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   349
    case False
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   350
    with less have hyp: "P (n div 2)" by simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   351
    show ?thesis
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   352
    proof (cases "even n")
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   353
      case True
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   354
      with hyp even [of "n div 2"] show ?thesis
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   355
        by simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   356
    next
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   357
      case False
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   358
      with hyp odd [of "n div 2"] show ?thesis
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   359
        by simp
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   360
    qed
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   361
  qed
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   362
qed
58687
5469874b0228 even more cleanup
haftmann
parents: 58681
diff changeset
   363
5469874b0228 even more cleanup
haftmann
parents: 58681
diff changeset
   364
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60562
diff changeset
   365
subsection \<open>Parity and powers\<close>
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   366
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 60867
diff changeset
   367
context ring_1
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   368
begin
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   369
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   370
lemma power_minus_even [simp]: "even n \<Longrightarrow> (- a) ^ n = a ^ n"
58690
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   371
  by (auto elim: evenE)
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   372
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   373
lemma power_minus_odd [simp]: "odd n \<Longrightarrow> (- a) ^ n = - (a ^ n)"
58690
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   374
  by (auto elim: oddE)
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   375
66815
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   376
lemma uminus_power_if:
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   377
  "(- a) ^ n = (if even n then a ^ n else - (a ^ n))"
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   378
  by auto
93c6632ddf44 one uniform type class for parity structures
haftmann
parents: 66808
diff changeset
   379
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   380
lemma neg_one_even_power [simp]: "even n \<Longrightarrow> (- 1) ^ n = 1"
58690
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   381
  by simp
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   382
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   383
lemma neg_one_odd_power [simp]: "odd n \<Longrightarrow> (- 1) ^ n = - 1"
58690
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   384
  by simp
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   385
66582
2b49d4888cb8 another fact on (- 1) ^ _
bulwahn
parents: 64785
diff changeset
   386
lemma neg_one_power_add_eq_neg_one_power_diff: "k \<le> n \<Longrightarrow> (- 1) ^ (n + k) = (- 1) ^ (n - k)"
2b49d4888cb8 another fact on (- 1) ^ _
bulwahn
parents: 64785
diff changeset
   387
  by (cases "even (n + k)") auto
2b49d4888cb8 another fact on (- 1) ^ _
bulwahn
parents: 64785
diff changeset
   388
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   389
end
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   390
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   391
context linordered_idom
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   392
begin
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   393
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   394
lemma zero_le_even_power: "even n \<Longrightarrow> 0 \<le> a ^ n"
58690
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   395
  by (auto elim: evenE)
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   396
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   397
lemma zero_le_odd_power: "odd n \<Longrightarrow> 0 \<le> a ^ n \<longleftrightarrow> 0 \<le> a"
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   398
  by (auto simp add: power_even_eq zero_le_mult_iff elim: oddE)
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   399
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   400
lemma zero_le_power_eq: "0 \<le> a ^ n \<longleftrightarrow> even n \<or> odd n \<and> 0 \<le> a"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   401
  by (auto simp add: zero_le_even_power zero_le_odd_power)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   402
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   403
lemma zero_less_power_eq: "0 < a ^ n \<longleftrightarrow> n = 0 \<or> even n \<and> a \<noteq> 0 \<or> odd n \<and> 0 < a"
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   404
proof -
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   405
  have [simp]: "0 = a ^ n \<longleftrightarrow> a = 0 \<and> n > 0"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   406
    unfolding power_eq_0_iff [of a n, symmetric] by blast
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   407
  show ?thesis
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   408
    unfolding less_le zero_le_power_eq by auto
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   409
qed
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   410
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   411
lemma power_less_zero_eq [simp]: "a ^ n < 0 \<longleftrightarrow> odd n \<and> a < 0"
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   412
  unfolding not_le [symmetric] zero_le_power_eq by auto
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   413
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   414
lemma power_le_zero_eq: "a ^ n \<le> 0 \<longleftrightarrow> n > 0 \<and> (odd n \<and> a \<le> 0 \<or> even n \<and> a = 0)"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   415
  unfolding not_less [symmetric] zero_less_power_eq by auto
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   416
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   417
lemma power_even_abs: "even n \<Longrightarrow> \<bar>a\<bar> ^ n = a ^ n"
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   418
  using power_abs [of a n] by (simp add: zero_le_even_power)
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   419
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   420
lemma power_mono_even:
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   421
  assumes "even n" and "\<bar>a\<bar> \<le> \<bar>b\<bar>"
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   422
  shows "a ^ n \<le> b ^ n"
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   423
proof -
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   424
  have "0 \<le> \<bar>a\<bar>" by auto
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   425
  with \<open>\<bar>a\<bar> \<le> \<bar>b\<bar>\<close> have "\<bar>a\<bar> ^ n \<le> \<bar>b\<bar> ^ n"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   426
    by (rule power_mono)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   427
  with \<open>even n\<close> show ?thesis
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   428
    by (simp add: power_even_abs)
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   429
qed
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   430
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   431
lemma power_mono_odd:
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   432
  assumes "odd n" and "a \<le> b"
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   433
  shows "a ^ n \<le> b ^ n"
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   434
proof (cases "b < 0")
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   435
  case True
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   436
  with \<open>a \<le> b\<close> have "- b \<le> - a" and "0 \<le> - b" by auto
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   437
  then have "(- b) ^ n \<le> (- a) ^ n" by (rule power_mono)
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60562
diff changeset
   438
  with \<open>odd n\<close> show ?thesis by simp
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   439
next
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   440
  case False
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   441
  then have "0 \<le> b" by auto
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   442
  show ?thesis
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   443
  proof (cases "a < 0")
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   444
    case True
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   445
    then have "n \<noteq> 0" and "a \<le> 0" using \<open>odd n\<close> [THEN odd_pos] by auto
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60562
diff changeset
   446
    then have "a ^ n \<le> 0" unfolding power_le_zero_eq using \<open>odd n\<close> by auto
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   447
    moreover from \<open>0 \<le> b\<close> have "0 \<le> b ^ n" by auto
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   448
    ultimately show ?thesis by auto
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   449
  next
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   450
    case False
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   451
    then have "0 \<le> a" by auto
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   452
    with \<open>a \<le> b\<close> show ?thesis
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   453
      using power_mono by auto
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   454
  qed
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   455
qed
62083
7582b39f51ed add the proof of the central limit theorem
hoelzl
parents: 61799
diff changeset
   456
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60562
diff changeset
   457
text \<open>Simplify, when the exponent is a numeral\<close>
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   458
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   459
lemma zero_le_power_eq_numeral [simp]:
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   460
  "0 \<le> a ^ numeral w \<longleftrightarrow> even (numeral w :: nat) \<or> odd (numeral w :: nat) \<and> 0 \<le> a"
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   461
  by (fact zero_le_power_eq)
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   462
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   463
lemma zero_less_power_eq_numeral [simp]:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   464
  "0 < a ^ numeral w \<longleftrightarrow>
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   465
    numeral w = (0 :: nat) \<or>
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   466
    even (numeral w :: nat) \<and> a \<noteq> 0 \<or>
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   467
    odd (numeral w :: nat) \<and> 0 < a"
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   468
  by (fact zero_less_power_eq)
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   469
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   470
lemma power_le_zero_eq_numeral [simp]:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   471
  "a ^ numeral w \<le> 0 \<longleftrightarrow>
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   472
    (0 :: nat) < numeral w \<and>
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   473
    (odd (numeral w :: nat) \<and> a \<le> 0 \<or> even (numeral w :: nat) \<and> a = 0)"
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   474
  by (fact power_le_zero_eq)
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   475
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   476
lemma power_less_zero_eq_numeral [simp]:
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   477
  "a ^ numeral w < 0 \<longleftrightarrow> odd (numeral w :: nat) \<and> a < 0"
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   478
  by (fact power_less_zero_eq)
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   479
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   480
lemma power_even_abs_numeral [simp]:
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   481
  "even (numeral w :: nat) \<Longrightarrow> \<bar>a\<bar> ^ numeral w = a ^ numeral w"
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   482
  by (fact power_even_abs)
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   483
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   484
end
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   485
66816
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   486
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   487
subsection \<open>Instance for @{typ int}\<close>
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   488
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   489
instance int :: ring_parity
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   490
proof
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   491
  fix k l :: int
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   492
  show "k mod 2 = 1" if "\<not> 2 dvd k"
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   493
  proof (rule order_antisym)
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   494
    have "0 \<le> k mod 2" and "k mod 2 < 2"
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   495
      by auto
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   496
    moreover have "k mod 2 \<noteq> 0"
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   497
      using that by (simp add: dvd_eq_mod_eq_0)
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   498
    ultimately have "0 < k mod 2"
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   499
      by (simp only: less_le) simp
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   500
    then show "1 \<le> k mod 2"
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   501
      by simp
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   502
    from \<open>k mod 2 < 2\<close> show "k mod 2 \<le> 1"
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   503
      by (simp only: less_le) simp
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   504
  qed
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   505
qed (simp_all add: dvd_eq_mod_eq_0 divide_int_def)
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   506
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   507
lemma even_diff_iff [simp]:
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   508
  "even (k - l) \<longleftrightarrow> even (k + l)" for k l :: int
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   509
  using dvd_add_times_triv_right_iff [of 2 "k - l" l] by (simp add: mult_2_right)
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   510
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   511
lemma even_abs_add_iff [simp]:
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   512
  "even (\<bar>k\<bar> + l) \<longleftrightarrow> even (k + l)" for k l :: int
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   513
  by (cases "k \<ge> 0") (simp_all add: ac_simps)
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   514
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   515
lemma even_add_abs_iff [simp]:
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   516
  "even (k + \<bar>l\<bar>) \<longleftrightarrow> even (k + l)" for k l :: int
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   517
  using even_abs_add_iff [of l k] by (simp add: ac_simps)
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   518
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   519
lemma even_nat_iff: "0 \<le> k \<Longrightarrow> even (nat k) \<longleftrightarrow> even k"
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   520
  by (simp add: even_of_nat [of "nat k", where ?'a = int, symmetric])
212a3334e7da more fundamental definition of div and mod on int
haftmann
parents: 66815
diff changeset
   521
58770
ae5e9b4f8daf downshift of theory Parity in the hierarchy
haftmann
parents: 58769
diff changeset
   522
end