src/HOL/Num.thy
author wenzelm
Wed, 12 Mar 2025 11:39:00 +0100
changeset 82265 4b875a4c83b0
parent 81980 13b5aa1b3fb4
permissions -rw-r--r--
update for release;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
     1
(*  Title:      HOL/Num.thy
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
     2
    Author:     Florian Haftmann
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
     3
    Author:     Brian Huffman
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
     4
*)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
     5
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
     6
section \<open>Binary Numerals\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
     7
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
     8
theory Num
64178
12e6c3bbb488 transfer lifting rule for numeral
haftmann
parents: 63913
diff changeset
     9
  imports BNF_Least_Fixpoint Transfer
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    10
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    11
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
    12
subsection \<open>The \<open>num\<close> type\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    13
58310
91ea607a34d8 updated news
blanchet
parents: 58154
diff changeset
    14
datatype num = One | Bit0 num | Bit1 num
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    15
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
    16
text \<open>Increment function for type \<^typ>\<open>num\<close>\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    17
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    18
primrec inc :: \<open>num \<Rightarrow> num\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    19
  where
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    20
    \<open>inc One = Bit0 One\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    21
  | \<open>inc (Bit0 x) = Bit1 x\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    22
  | \<open>inc (Bit1 x) = Bit0 (inc x)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    23
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
    24
text \<open>Converting between type \<^typ>\<open>num\<close> and type \<^typ>\<open>nat\<close>\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    25
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    26
primrec nat_of_num :: \<open>num \<Rightarrow> nat\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    27
  where
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    28
    \<open>nat_of_num One = Suc 0\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    29
  | \<open>nat_of_num (Bit0 x) = nat_of_num x + nat_of_num x\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    30
  | \<open>nat_of_num (Bit1 x) = Suc (nat_of_num x + nat_of_num x)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    31
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    32
primrec num_of_nat :: \<open>nat \<Rightarrow> num\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    33
  where
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    34
    \<open>num_of_nat 0 = One\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    35
  | \<open>num_of_nat (Suc n) = (if 0 < n then inc (num_of_nat n) else One)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    36
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    37
lemma nat_of_num_pos: \<open>0 < nat_of_num x\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    38
  by (induct x) simp_all
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    39
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    40
lemma nat_of_num_neq_0: \<open> nat_of_num x \<noteq> 0\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    41
  by (induct x) simp_all
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    42
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    43
lemma nat_of_num_inc: \<open>nat_of_num (inc x) = Suc (nat_of_num x)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    44
  by (induct x) simp_all
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    45
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    46
lemma num_of_nat_double: \<open>0 < n \<Longrightarrow> num_of_nat (n + n) = Bit0 (num_of_nat n)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    47
  by (induct n) simp_all
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    48
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
    49
text \<open>Type \<^typ>\<open>num\<close> is isomorphic to the strictly positive natural numbers.\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    50
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    51
lemma nat_of_num_inverse: \<open>num_of_nat (nat_of_num x) = x\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    52
  by (induct x) (simp_all add: num_of_nat_double nat_of_num_pos)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    53
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    54
lemma num_of_nat_inverse: \<open>0 < n \<Longrightarrow> nat_of_num (num_of_nat n) = n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    55
  by (induct n) (simp_all add: nat_of_num_inc)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    56
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    57
lemma num_eq_iff: \<open>x = y \<longleftrightarrow> nat_of_num x = nat_of_num y\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    58
  apply safe
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    59
  apply (drule arg_cong [where f=num_of_nat])
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    60
  apply (simp add: nat_of_num_inverse)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    61
  done
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    62
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    63
lemma num_induct [case_names One inc]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    64
  fixes P :: \<open>num \<Rightarrow> bool\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    65
  assumes One: \<open>P One\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    66
    and inc: \<open>\<And>x. P x \<Longrightarrow> P (inc x)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    67
  shows \<open>P x\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    68
proof -
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    69
  obtain n where n: \<open>Suc n = nat_of_num x\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    70
    by (cases \<open>nat_of_num x\<close>) (simp_all add: nat_of_num_neq_0)
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    71
  have \<open>P (num_of_nat (Suc n))\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    72
  proof (induct n)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    73
    case 0
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    74
    from One show ?case by simp
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    75
  next
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    76
    case (Suc n)
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    77
    then have \<open>P (inc (num_of_nat (Suc n)))\<close> by (rule inc)
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    78
    then show \<open>P (num_of_nat (Suc (Suc n)))\<close> by simp
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    79
  qed
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    80
  with n show \<open>P x\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    81
    by (simp add: nat_of_num_inverse)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    82
qed
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    83
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
    84
text \<open>
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
    85
  From now on, there are two possible models for \<^typ>\<open>num\<close>: as positive
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    86
  naturals (rule \<open>num_induct\<close>) and as digit representation (rules
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    87
  \<open>num.induct\<close>, \<open>num.cases\<close>).
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
    88
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    89
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    90
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
    91
subsection \<open>Numeral operations\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    92
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    93
instantiation num :: \<open>{plus,times,linorder}\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    94
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    95
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    96
definition [code del]: \<open>m + n = num_of_nat (nat_of_num m + nat_of_num n)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    97
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
    98
definition [code del]: \<open>m * n = num_of_nat (nat_of_num m * nat_of_num n)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    99
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   100
definition [code del]: \<open>m \<le> n \<longleftrightarrow> nat_of_num m \<le> nat_of_num n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   101
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   102
definition [code del]: \<open>m < n \<longleftrightarrow> nat_of_num m < nat_of_num n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   103
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   104
instance
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 60758
diff changeset
   105
  by standard (auto simp add: less_num_def less_eq_num_def num_eq_iff)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   106
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   107
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   108
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   109
lemma nat_of_num_add: \<open>nat_of_num (x + y) = nat_of_num x + nat_of_num y\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   110
  unfolding plus_num_def
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   111
  by (intro num_of_nat_inverse add_pos_pos nat_of_num_pos)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   112
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   113
lemma nat_of_num_mult: \<open>nat_of_num (x * y) = nat_of_num x * nat_of_num y\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   114
  unfolding times_num_def
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   115
  by (intro num_of_nat_inverse mult_pos_pos nat_of_num_pos)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   116
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   117
lemma add_num_simps [simp, code]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   118
  \<open>One + One = Bit0 One\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   119
  \<open>One + Bit0 n = Bit1 n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   120
  \<open>One + Bit1 n = Bit0 (n + One)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   121
  \<open>Bit0 m + One = Bit1 m\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   122
  \<open>Bit0 m + Bit0 n = Bit0 (m + n)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   123
  \<open>Bit0 m + Bit1 n = Bit1 (m + n)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   124
  \<open>Bit1 m + One = Bit0 (m + One)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   125
  \<open>Bit1 m + Bit0 n = Bit1 (m + n)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   126
  \<open>Bit1 m + Bit1 n = Bit0 (m + n + One)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   127
  by (simp_all add: num_eq_iff nat_of_num_add)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   128
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   129
lemma mult_num_simps [simp, code]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   130
  \<open>m * One = m\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   131
  \<open>One * n = n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   132
  \<open>Bit0 m * Bit0 n = Bit0 (Bit0 (m * n))\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   133
  \<open>Bit0 m * Bit1 n = Bit0 (m * Bit1 n)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   134
  \<open>Bit1 m * Bit0 n = Bit0 (Bit1 m * n)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   135
  \<open>Bit1 m * Bit1 n = Bit1 (m + n + Bit0 (m * n))\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   136
  by (simp_all add: num_eq_iff nat_of_num_add nat_of_num_mult distrib_right distrib_left)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   137
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   138
lemma eq_num_simps:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   139
  \<open>One = One \<longleftrightarrow> True\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   140
  \<open>One = Bit0 n \<longleftrightarrow> False\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   141
  \<open>One = Bit1 n \<longleftrightarrow> False\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   142
  \<open>Bit0 m = One \<longleftrightarrow> False\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   143
  \<open>Bit1 m = One \<longleftrightarrow> False\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   144
  \<open>Bit0 m = Bit0 n \<longleftrightarrow> m = n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   145
  \<open>Bit0 m = Bit1 n \<longleftrightarrow> False\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   146
  \<open>Bit1 m = Bit0 n \<longleftrightarrow> False\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   147
  \<open>Bit1 m = Bit1 n \<longleftrightarrow> m = n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   148
  by simp_all
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   149
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   150
lemma le_num_simps [simp, code]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   151
  \<open>One \<le> n \<longleftrightarrow> True\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   152
  \<open>Bit0 m \<le> One \<longleftrightarrow> False\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   153
  \<open>Bit1 m \<le> One \<longleftrightarrow> False\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   154
  \<open>Bit0 m \<le> Bit0 n \<longleftrightarrow> m \<le> n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   155
  \<open>Bit0 m \<le> Bit1 n \<longleftrightarrow> m \<le> n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   156
  \<open>Bit1 m \<le> Bit1 n \<longleftrightarrow> m \<le> n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   157
  \<open>Bit1 m \<le> Bit0 n \<longleftrightarrow> m < n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   158
  using nat_of_num_pos [of n] nat_of_num_pos [of m]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   159
  by (auto simp add: less_eq_num_def less_num_def)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   160
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   161
lemma less_num_simps [simp, code]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   162
  \<open>m < One \<longleftrightarrow> False\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   163
  \<open>One < Bit0 n \<longleftrightarrow> True\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   164
  \<open>One < Bit1 n \<longleftrightarrow> True\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   165
  \<open>Bit0 m < Bit0 n \<longleftrightarrow> m < n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   166
  \<open>Bit0 m < Bit1 n \<longleftrightarrow> m \<le> n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   167
  \<open>Bit1 m < Bit1 n \<longleftrightarrow> m < n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   168
  \<open>Bit1 m < Bit0 n \<longleftrightarrow> m < n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   169
  using nat_of_num_pos [of n] nat_of_num_pos [of m]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   170
  by (auto simp add: less_eq_num_def less_num_def)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   171
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   172
lemma le_num_One_iff: \<open>x \<le> One \<longleftrightarrow> x = One\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   173
  by (simp add: antisym_conv)
61630
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   174
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   175
text \<open>Rules using \<open>One\<close> and \<open>inc\<close> as constructors.\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   176
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   177
lemma add_One: \<open>x + One = inc x\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   178
  by (simp add: num_eq_iff nat_of_num_add nat_of_num_inc)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   179
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   180
lemma add_One_commute: \<open>One + n = n + One\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   181
  by (induct n) simp_all
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   182
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   183
lemma add_inc: \<open>x + inc y = inc (x + y)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   184
  by (simp add: num_eq_iff nat_of_num_add nat_of_num_inc)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   185
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   186
lemma mult_inc: \<open>x * inc y = x * y + x\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   187
  by (simp add: num_eq_iff nat_of_num_mult nat_of_num_add nat_of_num_inc)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   188
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
   189
text \<open>The \<^const>\<open>num_of_nat\<close> conversion.\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   190
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   191
lemma num_of_nat_One: \<open>n \<le> 1 \<Longrightarrow> num_of_nat n = One\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   192
  by (cases n) simp_all
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   193
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   194
lemma num_of_nat_plus_distrib:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   195
  \<open>0 < m \<Longrightarrow> 0 < n \<Longrightarrow> num_of_nat (m + n) = num_of_nat m + num_of_nat n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   196
  by (induct n) (auto simp add: add_One add_One_commute add_inc)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   197
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   198
text \<open>A double-and-decrement function.\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   199
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   200
primrec BitM :: \<open>num \<Rightarrow> num\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   201
  where
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   202
    \<open>BitM One = One\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   203
  | \<open>BitM (Bit0 n) = Bit1 (BitM n)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   204
  | \<open>BitM (Bit1 n) = Bit1 (Bit0 n)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   205
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   206
lemma BitM_plus_one: \<open>BitM n + One = Bit0 n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   207
  by (induct n) simp_all
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   208
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   209
lemma one_plus_BitM: \<open>One + BitM n = Bit0 n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   210
  unfolding add_One_commute BitM_plus_one ..
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   211
71991
8bff286878bf misc lemma tuning
haftmann
parents: 71760
diff changeset
   212
lemma BitM_inc_eq:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   213
  \<open>BitM (inc n) = Bit1 n\<close>
71991
8bff286878bf misc lemma tuning
haftmann
parents: 71760
diff changeset
   214
  by (induction n) simp_all
8bff286878bf misc lemma tuning
haftmann
parents: 71760
diff changeset
   215
8bff286878bf misc lemma tuning
haftmann
parents: 71760
diff changeset
   216
lemma inc_BitM_eq:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   217
  \<open>inc (BitM n) = Bit0 n\<close>
71991
8bff286878bf misc lemma tuning
haftmann
parents: 71760
diff changeset
   218
  by (simp add: BitM_plus_one[symmetric] add_One)
8bff286878bf misc lemma tuning
haftmann
parents: 71760
diff changeset
   219
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   220
text \<open>Squaring and exponentiation.\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   221
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   222
primrec sqr :: \<open>num \<Rightarrow> num\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   223
  where
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   224
    \<open>sqr One = One\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   225
  | \<open>sqr (Bit0 n) = Bit0 (Bit0 (sqr n))\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   226
  | \<open>sqr (Bit1 n) = Bit1 (Bit0 (sqr n + n))\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   227
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   228
primrec pow :: \<open>num \<Rightarrow> num \<Rightarrow> num\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   229
  where
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   230
    \<open>pow x One = x\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   231
  | \<open>pow x (Bit0 y) = sqr (pow x y)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   232
  | \<open>pow x (Bit1 y) = sqr (pow x y) * x\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   233
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   234
lemma nat_of_num_sqr: \<open>nat_of_num (sqr x) = nat_of_num x * nat_of_num x\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   235
  by (induct x) (simp_all add: algebra_simps nat_of_num_add)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   236
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   237
lemma sqr_conv_mult: \<open>sqr x = x * x\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   238
  by (simp add: num_eq_iff nat_of_num_sqr nat_of_num_mult)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   239
70226
accbd801fefa more lemmas
haftmann
parents: 69605
diff changeset
   240
lemma num_double [simp]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   241
  \<open>Bit0 num.One * n = Bit0 n\<close>
70226
accbd801fefa more lemmas
haftmann
parents: 69605
diff changeset
   242
  by (simp add: num_eq_iff nat_of_num_mult)
accbd801fefa more lemmas
haftmann
parents: 69605
diff changeset
   243
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   244
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   245
subsection \<open>Binary numerals\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   246
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   247
text \<open>
47211
e1b0c8236ae4 fix search-and-replace errors
huffman
parents: 47209
diff changeset
   248
  We embed binary representations into a generic algebraic
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   249
  structure using \<open>numeral\<close>.
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   250
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   251
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   252
class numeral = one + semigroup_add
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   253
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   254
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   255
primrec numeral :: \<open>num \<Rightarrow> 'a\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   256
  where
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   257
    numeral_One: \<open>numeral One = 1\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   258
  | numeral_Bit0: \<open>numeral (Bit0 n) = numeral n + numeral n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   259
  | numeral_Bit1: \<open>numeral (Bit1 n) = numeral n + numeral n + 1\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   260
50817
652731d92061 sharing of recursive results on evaluation
haftmann
parents: 49962
diff changeset
   261
lemma numeral_code [code]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   262
  \<open>numeral One = 1\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   263
  \<open>numeral (Bit0 n) = (let m = numeral n in m + m)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   264
  \<open>numeral (Bit1 n) = (let m = numeral n in m + m + 1)\<close>
50817
652731d92061 sharing of recursive results on evaluation
haftmann
parents: 49962
diff changeset
   265
  by (simp_all add: Let_def)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   266
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   267
lemma one_plus_numeral_commute: \<open>1 + numeral x = numeral x + 1\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   268
proof (induct x)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   269
  case One
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   270
  then show ?case by simp
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   271
next
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   272
  case Bit0
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   273
  then show ?case by (simp add: add.assoc [symmetric]) (simp add: add.assoc)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   274
next
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   275
  case Bit1
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   276
  then show ?case by (simp add: add.assoc [symmetric]) (simp add: add.assoc)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   277
qed
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   278
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   279
lemma numeral_inc: \<open>numeral (inc x) = numeral x + 1\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   280
proof (induct x)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   281
  case One
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   282
  then show ?case by simp
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   283
next
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   284
  case Bit0
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   285
  then show ?case by simp
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   286
next
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   287
  case (Bit1 x)
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   288
  have \<open>numeral x + (1 + numeral x) + 1 = numeral x + (numeral x + 1) + 1\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   289
    by (simp only: one_plus_numeral_commute)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   290
  with Bit1 show ?case
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
   291
    by (simp add: add.assoc)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   292
qed
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   293
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   294
declare numeral.simps [simp del]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   295
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   296
abbreviation \<open>Numeral1 \<equiv> numeral One\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   297
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   298
declare numeral_One [code_post]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   299
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   300
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   301
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   302
text \<open>Numeral syntax.\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   303
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   304
syntax
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   305
  "_Numeral" :: \<open>num_const \<Rightarrow> 'a\<close>  (\<open>(\<open>open_block notation=\<open>literal number\<close>\<close>_)\<close>)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   306
69605
a96320074298 isabelle update -u path_cartouches;
wenzelm
parents: 69593
diff changeset
   307
ML_file \<open>Tools/numeral.ML\<close>
58410
6d46ad54a2ab explicit separation of signed and unsigned numerals using existing lexical categories num and xnum
haftmann
parents: 58310
diff changeset
   308
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   309
parse_translation \<open>
52143
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   310
  let
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
   311
    fun numeral_tr [(c as Const (\<^syntax_const>\<open>_constrain\<close>, _)) $ t $ u] =
52143
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   312
          c $ numeral_tr [t] $ u
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   313
      | numeral_tr [Const (num, _)] =
58421
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58410
diff changeset
   314
          (Numeral.mk_number_syntax o #value o Lexicon.read_num) num
52143
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   315
      | numeral_tr ts = raise TERM ("numeral_tr", ts);
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
   316
  in [(\<^syntax_const>\<open>_Numeral\<close>, K numeral_tr)] end
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   317
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   318
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   319
typed_print_translation \<open>
52143
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   320
  let
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   321
    fun num_tr' ctxt T [n] =
52143
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   322
      let
62597
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62481
diff changeset
   323
        val k = Numeral.dest_num_syntax n;
52187
wenzelm
parents: 52143
diff changeset
   324
        val t' =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
   325
          Syntax.const \<^syntax_const>\<open>_Numeral\<close> $
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   326
            Syntax.free (string_of_int k);
52143
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   327
      in
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   328
        (case T of
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
   329
          Type (\<^type_name>\<open>fun\<close>, [_, T']) =>
52210
0226035df99d more explicit Printer.type_emphasis, depending on show_type_emphasis;
wenzelm
parents: 52187
diff changeset
   330
            if Printer.type_emphasis ctxt T' then
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
   331
              Syntax.const \<^syntax_const>\<open>_constrain\<close> $ t' $
52210
0226035df99d more explicit Printer.type_emphasis, depending on show_type_emphasis;
wenzelm
parents: 52187
diff changeset
   332
                Syntax_Phases.term_of_typ ctxt T'
0226035df99d more explicit Printer.type_emphasis, depending on show_type_emphasis;
wenzelm
parents: 52187
diff changeset
   333
            else t'
52187
wenzelm
parents: 52143
diff changeset
   334
        | _ => if T = dummyT then t' else raise Match)
52143
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   335
      end;
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   336
  in
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
   337
   [(\<^const_syntax>\<open>numeral\<close>, num_tr')]
52143
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   338
  end
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   339
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   340
47228
4f4d85c3516f load Tools/numeral.ML in Num.thy
huffman
parents: 47227
diff changeset
   341
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   342
subsection \<open>Class-specific numeral rules\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   343
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
   344
text \<open>\<^const>\<open>numeral\<close> is a morphism.\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   345
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   346
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   347
subsubsection \<open>Structures with addition: class \<open>numeral\<close>\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   348
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   349
context numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   350
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   351
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   352
lemma numeral_add: \<open>numeral (m + n) = numeral m + numeral n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   353
  by (induct n rule: num_induct)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   354
    (simp_all only: numeral_One add_One add_inc numeral_inc add.assoc)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   355
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   356
lemma numeral_plus_numeral: \<open>numeral m + numeral n = numeral (m + n)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   357
  by (rule numeral_add [symmetric])
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   358
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   359
lemma numeral_plus_one: \<open>numeral n + 1 = numeral (n + One)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   360
  using numeral_add [of n One] by (simp add: numeral_One)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   361
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   362
lemma one_plus_numeral: \<open>1 + numeral n = numeral (One + n)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   363
  using numeral_add [of One n] by (simp add: numeral_One)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   364
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   365
lemma one_add_one: \<open>1 + 1 = 2\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   366
  using numeral_add [of One One] by (simp add: numeral_One)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   367
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   368
lemmas add_numeral_special =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   369
  numeral_plus_one one_plus_numeral one_add_one
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   370
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   371
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   372
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   373
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   374
subsubsection \<open>Structures with negation: class \<open>neg_numeral\<close>\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   375
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   376
class neg_numeral = numeral + group_add
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   377
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   378
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   379
lemma uminus_numeral_One: \<open>- Numeral1 = - 1\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   380
  by (simp add: numeral_One)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   381
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   382
text \<open>Numerals form an abelian subgroup.\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   383
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   384
inductive is_num :: \<open>'a \<Rightarrow> bool\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   385
  where
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   386
    \<open>is_num 1\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   387
  | \<open>is_num x \<Longrightarrow> is_num (- x)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   388
  | \<open>is_num x \<Longrightarrow> is_num y \<Longrightarrow> is_num (x + y)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   389
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   390
lemma is_num_numeral: \<open>is_num (numeral k)\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   391
  by (induct k) (simp_all add: numeral.simps is_num.intros)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   392
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   393
lemma is_num_add_commute: \<open>is_num x \<Longrightarrow> is_num y \<Longrightarrow> x + y = y + x\<close>
75669
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   394
proof(induction x rule: is_num.induct)
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   395
  case 1
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   396
  then show ?case
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   397
  proof (induction y rule: is_num.induct)
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   398
    case 1
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   399
    then show ?case by simp
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   400
  next
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   401
    case (2 y)
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   402
    then have \<open>y + (1 + - y) + y = y + (- y + 1) + y\<close>
75669
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   403
      by (simp add: add.assoc)
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   404
    then have \<open>y + (1 + - y) = y + (- y + 1)\<close>
75669
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   405
      by simp
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   406
    then show ?case
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   407
      by (rule add_left_imp_eq[of y])
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   408
  next
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   409
    case (3 x y)
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   410
    then have \<open>1 + (x + y) = x + 1 + y\<close>
75669
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   411
      by (simp add: add.assoc [symmetric])
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   412
    then show ?case using 3
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   413
      by (simp add: add.assoc)
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   414
  qed
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   415
next
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   416
  case (2 x)
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   417
  then have \<open>x + (- x + y) + x = x + (y + - x) + x\<close>
75669
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   418
    by (simp add: add.assoc)
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   419
  then have \<open>x + (- x + y) = x + (y + - x)\<close>
75669
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   420
    by simp
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   421
  then show ?case
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   422
    by (rule add_left_imp_eq[of x])
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   423
next
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   424
  case (3 x z)
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   425
  moreover have \<open>x + (y + z) = (x + y) + z\<close>
75669
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   426
    by (simp add: add.assoc[symmetric])
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   427
  ultimately show ?case 
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   428
    by (simp add: add.assoc)
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 74592
diff changeset
   429
qed
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   430
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   431
lemma is_num_add_left_commute: \<open>is_num x \<Longrightarrow> is_num y \<Longrightarrow> x + (y + z) = y + (x + z)\<close>
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
   432
  by (simp only: add.assoc [symmetric] is_num_add_commute)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   433
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   434
lemmas is_num_normalize =
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
   435
  add.assoc is_num_add_commute is_num_add_left_commute
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   436
  is_num.intros is_num_numeral
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 53064
diff changeset
   437
  minus_add
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   438
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   439
definition dbl :: \<open>'a \<Rightarrow> 'a\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   440
  where \<open>dbl x = x + x\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   441
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   442
definition dbl_inc :: \<open>'a \<Rightarrow> 'a\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   443
  where \<open>dbl_inc x = x + x + 1\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   444
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   445
definition dbl_dec :: \<open>'a \<Rightarrow> 'a\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   446
  where \<open>dbl_dec x = x + x - 1\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   447
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   448
definition sub :: \<open>num \<Rightarrow> num \<Rightarrow> 'a\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   449
  where \<open>sub k l = numeral k - numeral l\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   450
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   451
lemma numeral_BitM: \<open>numeral (BitM n) = numeral (Bit0 n) - 1\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   452
  by (simp only: BitM_plus_one [symmetric] numeral_add numeral_One eq_diff_eq)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   453
71991
8bff286878bf misc lemma tuning
haftmann
parents: 71760
diff changeset
   454
lemma sub_inc_One_eq:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   455
  \<open>sub (inc n) num.One = numeral n\<close>
71991
8bff286878bf misc lemma tuning
haftmann
parents: 71760
diff changeset
   456
  by (simp_all add: sub_def diff_eq_eq numeral_inc numeral.numeral_One)
8bff286878bf misc lemma tuning
haftmann
parents: 71760
diff changeset
   457
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   458
lemma dbl_simps [simp]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   459
  \<open>dbl (- numeral k) = - dbl (numeral k)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   460
  \<open>dbl 0 = 0\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   461
  \<open>dbl 1 = 2\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   462
  \<open>dbl (- 1) = - 2\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   463
  \<open>dbl (numeral k) = numeral (Bit0 k)\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   464
  by (simp_all add: dbl_def numeral.simps minus_add)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   465
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   466
lemma dbl_inc_simps [simp]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   467
  \<open>dbl_inc (- numeral k) = - dbl_dec (numeral k)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   468
  \<open>dbl_inc 0 = 1\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   469
  \<open>dbl_inc 1 = 3\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   470
  \<open>dbl_inc (- 1) = - 1\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   471
  \<open>dbl_inc (numeral k) = numeral (Bit1 k)\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   472
  by (simp_all add: dbl_inc_def dbl_dec_def numeral.simps numeral_BitM is_num_normalize algebra_simps
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   473
      del: add_uminus_conv_diff)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   474
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   475
lemma dbl_dec_simps [simp]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   476
  \<open>dbl_dec (- numeral k) = - dbl_inc (numeral k)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   477
  \<open>dbl_dec 0 = - 1\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   478
  \<open>dbl_dec 1 = 1\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   479
  \<open>dbl_dec (- 1) = - 3\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   480
  \<open>dbl_dec (numeral k) = numeral (BitM k)\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   481
  by (simp_all add: dbl_dec_def dbl_inc_def numeral.simps numeral_BitM is_num_normalize)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   482
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   483
lemma sub_num_simps [simp]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   484
  \<open>sub One One = 0\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   485
  \<open>sub One (Bit0 l) = - numeral (BitM l)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   486
  \<open>sub One (Bit1 l) = - numeral (Bit0 l)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   487
  \<open>sub (Bit0 k) One = numeral (BitM k)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   488
  \<open>sub (Bit1 k) One = numeral (Bit0 k)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   489
  \<open>sub (Bit0 k) (Bit0 l) = dbl (sub k l)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   490
  \<open>sub (Bit0 k) (Bit1 l) = dbl_dec (sub k l)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   491
  \<open>sub (Bit1 k) (Bit0 l) = dbl_inc (sub k l)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   492
  \<open>sub (Bit1 k) (Bit1 l) = dbl (sub k l)\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   493
  by (simp_all add: dbl_def dbl_dec_def dbl_inc_def sub_def numeral.simps
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 53064
diff changeset
   494
    numeral_BitM is_num_normalize del: add_uminus_conv_diff add: diff_conv_add_uminus)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   495
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   496
lemma add_neg_numeral_simps:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   497
  \<open>numeral m + - numeral n = sub m n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   498
  \<open>- numeral m + numeral n = sub n m\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   499
  \<open>- numeral m + - numeral n = - (numeral m + numeral n)\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   500
  by (simp_all add: sub_def numeral_add numeral.simps is_num_normalize
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   501
      del: add_uminus_conv_diff add: diff_conv_add_uminus)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   502
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   503
lemma add_neg_numeral_special:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   504
  \<open>1 + - numeral m = sub One m\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   505
  \<open>- numeral m + 1 = sub One m\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   506
  \<open>numeral m + - 1 = sub m One\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   507
  \<open>- 1 + numeral n = sub n One\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   508
  \<open>- 1 + - numeral n = - numeral (inc n)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   509
  \<open>- numeral m + - 1 = - numeral (inc m)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   510
  \<open>1 + - 1 = 0\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   511
  \<open>- 1 + 1 = 0\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   512
  \<open>- 1 + - 1 = - 2\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   513
  by (simp_all add: sub_def numeral_add numeral.simps is_num_normalize right_minus numeral_inc
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   514
      del: add_uminus_conv_diff add: diff_conv_add_uminus)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   515
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   516
lemma diff_numeral_simps:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   517
  \<open>numeral m - numeral n = sub m n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   518
  \<open>numeral m - - numeral n = numeral (m + n)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   519
  \<open>- numeral m - numeral n = - numeral (m + n)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   520
  \<open>- numeral m - - numeral n = sub n m\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   521
  by (simp_all add: sub_def numeral_add numeral.simps is_num_normalize
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   522
      del: add_uminus_conv_diff add: diff_conv_add_uminus)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   523
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   524
lemma diff_numeral_special:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   525
  \<open>1 - numeral n = sub One n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   526
  \<open>numeral m - 1 = sub m One\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   527
  \<open>1 - - numeral n = numeral (One + n)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   528
  \<open>- numeral m - 1 = - numeral (m + One)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   529
  \<open>- 1 - numeral n = - numeral (inc n)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   530
  \<open>numeral m - - 1 = numeral (inc m)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   531
  \<open>- 1 - - numeral n = sub n One\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   532
  \<open>- numeral m - - 1 = sub One m\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   533
  \<open>1 - 1 = 0\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   534
  \<open>- 1 - 1 = - 2\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   535
  \<open>1 - - 1 = 2\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   536
  \<open>- 1 - - 1 = 0\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   537
  by (simp_all add: sub_def numeral_add numeral.simps is_num_normalize numeral_inc
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   538
      del: add_uminus_conv_diff add: diff_conv_add_uminus)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   539
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   540
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   541
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   542
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   543
subsubsection \<open>Structures with multiplication: class \<open>semiring_numeral\<close>\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   544
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   545
class semiring_numeral = semiring + monoid_mult
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   546
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   547
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   548
subclass numeral ..
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   549
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   550
lemma numeral_mult: \<open>numeral (m * n) = numeral m * numeral n\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   551
  by (induct n rule: num_induct)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   552
    (simp_all add: numeral_One mult_inc numeral_inc numeral_add distrib_left)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   553
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   554
lemma numeral_times_numeral: \<open>numeral m * numeral n = numeral (m * n)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   555
  by (rule numeral_mult [symmetric])
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   556
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   557
lemma mult_2: \<open>2 * z = z + z\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   558
  by (simp add: one_add_one [symmetric] distrib_right)
53064
7e3f39bc41df generalized sort constraint of lemmas
haftmann
parents: 52435
diff changeset
   559
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   560
lemma mult_2_right: \<open>z * 2 = z + z\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   561
  by (simp add: one_add_one [symmetric] distrib_left)
53064
7e3f39bc41df generalized sort constraint of lemmas
haftmann
parents: 52435
diff changeset
   562
66936
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66283
diff changeset
   563
lemma left_add_twice:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   564
  \<open>a + (a + b) = 2 * a + b\<close>
66936
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66283
diff changeset
   565
  by (simp add: mult_2 ac_simps)
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66283
diff changeset
   566
79590
b14c4cb37d99 more lemmas
haftmann
parents: 78099
diff changeset
   567
lemma numeral_Bit0_eq_double:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   568
  \<open>numeral (Bit0 n) = 2 * numeral n\<close>
79590
b14c4cb37d99 more lemmas
haftmann
parents: 78099
diff changeset
   569
  by (simp add: mult_2) (simp add: numeral_Bit0)
b14c4cb37d99 more lemmas
haftmann
parents: 78099
diff changeset
   570
b14c4cb37d99 more lemmas
haftmann
parents: 78099
diff changeset
   571
lemma numeral_Bit1_eq_inc_double:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   572
  \<open>numeral (Bit1 n) = 2 * numeral n + 1\<close>
79590
b14c4cb37d99 more lemmas
haftmann
parents: 78099
diff changeset
   573
  by (simp add: mult_2) (simp add: numeral_Bit1)
b14c4cb37d99 more lemmas
haftmann
parents: 78099
diff changeset
   574
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   575
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   576
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   577
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   578
subsubsection \<open>Structures with a zero: class \<open>semiring_1\<close>\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   579
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   580
context semiring_1
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   581
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   582
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   583
subclass semiring_numeral ..
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   584
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   585
lemma of_nat_numeral [simp]: \<open>of_nat (numeral n) = numeral n\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   586
  by (induct n) (simp_all only: numeral.simps numeral_class.numeral.simps of_nat_add of_nat_1)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   587
70927
cc204e10385c tuned syntax
haftmann
parents: 70356
diff changeset
   588
end
64178
12e6c3bbb488 transfer lifting rule for numeral
haftmann
parents: 63913
diff changeset
   589
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   590
lemma nat_of_num_numeral [code_abbrev]: \<open>nat_of_num = numeral\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   591
proof
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   592
  fix n
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   593
  have \<open>numeral n = nat_of_num n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   594
    by (induct n) (simp_all add: numeral.simps)
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   595
  then show \<open>nat_of_num n = numeral n\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   596
    by simp
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   597
qed
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   598
51143
0a2371e7ced3 two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents: 50817
diff changeset
   599
lemma nat_of_num_code [code]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   600
  \<open>nat_of_num One = 1\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   601
  \<open>nat_of_num (Bit0 n) = (let m = nat_of_num n in m + m)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   602
  \<open>nat_of_num (Bit1 n) = (let m = nat_of_num n in Suc (m + m))\<close>
51143
0a2371e7ced3 two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents: 50817
diff changeset
   603
  by (simp_all add: Let_def)
0a2371e7ced3 two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents: 50817
diff changeset
   604
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   605
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   606
subsubsection \<open>Equality: class \<open>semiring_char_0\<close>\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   607
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   608
context semiring_char_0
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   609
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   610
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   611
lemma numeral_eq_iff: \<open>numeral m = numeral n \<longleftrightarrow> m = n\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   612
  by (simp only: of_nat_numeral [symmetric] nat_of_num_numeral [symmetric]
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   613
    of_nat_eq_iff num_eq_iff)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   614
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   615
lemma numeral_eq_one_iff: \<open>numeral n = 1 \<longleftrightarrow> n = One\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   616
  by (rule numeral_eq_iff [of n One, unfolded numeral_One])
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   617
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   618
lemma one_eq_numeral_iff: \<open>1 = numeral n \<longleftrightarrow> One = n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   619
  by (rule numeral_eq_iff [of One n, unfolded numeral_One])
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   620
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   621
lemma numeral_neq_zero: \<open>numeral n \<noteq> 0\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   622
  by (simp add: of_nat_numeral [symmetric] nat_of_num_numeral [symmetric] nat_of_num_pos)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   623
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   624
lemma zero_neq_numeral: \<open>0 \<noteq> numeral n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   625
  unfolding eq_commute [of 0] by (rule numeral_neq_zero)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   626
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   627
lemmas eq_numeral_simps [simp] =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   628
  numeral_eq_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   629
  numeral_eq_one_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   630
  one_eq_numeral_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   631
  numeral_neq_zero
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   632
  zero_neq_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   633
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   634
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   635
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   636
70270
4065e3b0e5bf Generalisations involving numerals; comparisons should now work for ennreal
paulson <lp15@cam.ac.uk>
parents: 70226
diff changeset
   637
subsubsection \<open>Comparisons: class \<open>linordered_nonzero_semiring\<close>\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   638
70270
4065e3b0e5bf Generalisations involving numerals; comparisons should now work for ennreal
paulson <lp15@cam.ac.uk>
parents: 70226
diff changeset
   639
context linordered_nonzero_semiring
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   640
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   641
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   642
lemma numeral_le_iff: \<open>numeral m \<le> numeral n \<longleftrightarrow> m \<le> n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   643
proof -
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   644
  have \<open>of_nat (numeral m) \<le> of_nat (numeral n) \<longleftrightarrow> m \<le> n\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   645
    by (simp only: less_eq_num_def nat_of_num_numeral of_nat_le_iff)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   646
  then show ?thesis by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   647
qed
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   648
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   649
lemma one_le_numeral: \<open>1 \<le> numeral n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   650
  using numeral_le_iff [of One n] by (simp add: numeral_One)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   651
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   652
lemma numeral_le_one_iff: \<open>numeral n \<le> 1 \<longleftrightarrow> n \<le> One\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   653
  using numeral_le_iff [of n One] by (simp add: numeral_One)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   654
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   655
lemma numeral_less_iff: \<open>numeral m < numeral n \<longleftrightarrow> m < n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   656
proof -
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   657
  have \<open>of_nat (numeral m) < of_nat (numeral n) \<longleftrightarrow> m < n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   658
    unfolding less_num_def nat_of_num_numeral of_nat_less_iff ..
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   659
  then show ?thesis by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   660
qed
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   661
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   662
lemma not_numeral_less_one: \<open>\<not> numeral n < 1\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   663
  using numeral_less_iff [of n One] by (simp add: numeral_One)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   664
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   665
lemma one_less_numeral_iff: \<open>1 < numeral n \<longleftrightarrow> One < n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   666
  using numeral_less_iff [of One n] by (simp add: numeral_One)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   667
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   668
lemma zero_le_numeral: \<open>0 \<le> numeral n\<close>
70270
4065e3b0e5bf Generalisations involving numerals; comparisons should now work for ennreal
paulson <lp15@cam.ac.uk>
parents: 70226
diff changeset
   669
  using dual_order.trans one_le_numeral zero_le_one by blast
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   670
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   671
lemma zero_less_numeral: \<open>0 < numeral n\<close>
70270
4065e3b0e5bf Generalisations involving numerals; comparisons should now work for ennreal
paulson <lp15@cam.ac.uk>
parents: 70226
diff changeset
   672
  using less_linear not_numeral_less_one order.strict_trans zero_less_one by blast
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   673
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   674
lemma not_numeral_le_zero: \<open>\<not> numeral n \<le> 0\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   675
  by (simp add: not_le zero_less_numeral)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   676
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   677
lemma not_numeral_less_zero: \<open>\<not> numeral n < 0\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   678
  by (simp add: not_less zero_le_numeral)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   679
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   680
lemma one_of_nat_le_iff [simp]: \<open>1 \<le> of_nat k \<longleftrightarrow> 1 \<le> k\<close>
80612
e65eed943bee A lot of new material from the Ramsey development, including a couple of new simprules.
paulson <lp15@cam.ac.uk>
parents: 79590
diff changeset
   681
  using of_nat_le_iff [of 1] by simp
e65eed943bee A lot of new material from the Ramsey development, including a couple of new simprules.
paulson <lp15@cam.ac.uk>
parents: 79590
diff changeset
   682
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   683
lemma numeral_nat_le_iff [simp]: \<open>numeral n \<le> of_nat k \<longleftrightarrow> numeral n \<le> k\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   684
  using of_nat_le_iff [of \<open>numeral n\<close>] by simp
80612
e65eed943bee A lot of new material from the Ramsey development, including a couple of new simprules.
paulson <lp15@cam.ac.uk>
parents: 79590
diff changeset
   685
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   686
lemma of_nat_le_1_iff [simp]: \<open>of_nat k \<le> 1 \<longleftrightarrow> k \<le> 1\<close>
80612
e65eed943bee A lot of new material from the Ramsey development, including a couple of new simprules.
paulson <lp15@cam.ac.uk>
parents: 79590
diff changeset
   687
  using of_nat_le_iff [of _ 1] by simp
e65eed943bee A lot of new material from the Ramsey development, including a couple of new simprules.
paulson <lp15@cam.ac.uk>
parents: 79590
diff changeset
   688
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   689
lemma of_nat_le_numeral_iff [simp]: \<open>of_nat k \<le> numeral n \<longleftrightarrow> k \<le> numeral n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   690
  using of_nat_le_iff [of _ \<open>numeral n\<close>] by simp
80612
e65eed943bee A lot of new material from the Ramsey development, including a couple of new simprules.
paulson <lp15@cam.ac.uk>
parents: 79590
diff changeset
   691
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   692
lemma one_of_nat_less_iff [simp]: \<open>1 < of_nat k \<longleftrightarrow> 1 < k\<close>
80612
e65eed943bee A lot of new material from the Ramsey development, including a couple of new simprules.
paulson <lp15@cam.ac.uk>
parents: 79590
diff changeset
   693
  using of_nat_less_iff [of 1] by simp
e65eed943bee A lot of new material from the Ramsey development, including a couple of new simprules.
paulson <lp15@cam.ac.uk>
parents: 79590
diff changeset
   694
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   695
lemma numeral_nat_less_iff [simp]: \<open>numeral n < of_nat k \<longleftrightarrow> numeral n < k\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   696
  using of_nat_less_iff [of \<open>numeral n\<close>] by simp
80612
e65eed943bee A lot of new material from the Ramsey development, including a couple of new simprules.
paulson <lp15@cam.ac.uk>
parents: 79590
diff changeset
   697
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   698
lemma of_nat_less_1_iff [simp]: \<open>of_nat k < 1 \<longleftrightarrow> k < 1\<close>
80612
e65eed943bee A lot of new material from the Ramsey development, including a couple of new simprules.
paulson <lp15@cam.ac.uk>
parents: 79590
diff changeset
   699
  using of_nat_less_iff [of _ 1] by simp
e65eed943bee A lot of new material from the Ramsey development, including a couple of new simprules.
paulson <lp15@cam.ac.uk>
parents: 79590
diff changeset
   700
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   701
lemma of_nat_less_numeral_iff [simp]: \<open>of_nat k < numeral n \<longleftrightarrow> k < numeral n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   702
  using of_nat_less_iff [of _ \<open>numeral n\<close>] by simp
80612
e65eed943bee A lot of new material from the Ramsey development, including a couple of new simprules.
paulson <lp15@cam.ac.uk>
parents: 79590
diff changeset
   703
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   704
lemma of_nat_eq_numeral_iff [simp]: \<open>of_nat k = numeral n \<longleftrightarrow> k = numeral n\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   705
  using of_nat_eq_iff [of _ \<open>numeral n\<close>] by simp
80612
e65eed943bee A lot of new material from the Ramsey development, including a couple of new simprules.
paulson <lp15@cam.ac.uk>
parents: 79590
diff changeset
   706
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   707
lemmas le_numeral_extra =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   708
  zero_le_one not_one_le_zero
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   709
  order_refl [of 0] order_refl [of 1]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   710
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   711
lemmas less_numeral_extra =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   712
  zero_less_one not_one_less_zero
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   713
  less_irrefl [of 0] less_irrefl [of 1]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   714
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   715
lemmas le_numeral_simps [simp] =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   716
  numeral_le_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   717
  one_le_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   718
  numeral_le_one_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   719
  zero_le_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   720
  not_numeral_le_zero
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   721
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   722
lemmas less_numeral_simps [simp] =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   723
  numeral_less_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   724
  one_less_numeral_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   725
  not_numeral_less_one
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   726
  zero_less_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   727
  not_numeral_less_zero
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   728
61630
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   729
lemma min_0_1 [simp]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   730
  fixes min' :: \<open>'a \<Rightarrow> 'a \<Rightarrow> 'a\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   731
  defines \<open>min' \<equiv> min\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   732
  shows
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   733
    \<open>min' 0 1 = 0\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   734
    \<open>min' 1 0 = 0\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   735
    \<open>min' 0 (numeral x) = 0\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   736
    \<open>min' (numeral x) 0 = 0\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   737
    \<open>min' 1 (numeral x) = 1\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   738
    \<open>min' (numeral x) 1 = 1\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   739
  by (simp_all add: min'_def min_def le_num_One_iff)
61630
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   740
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   741
lemma max_0_1 [simp]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   742
  fixes max' :: \<open>'a \<Rightarrow> 'a \<Rightarrow> 'a\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   743
  defines \<open>max' \<equiv> max\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   744
  shows
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   745
    \<open>max' 0 1 = 1\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   746
    \<open>max' 1 0 = 1\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   747
    \<open>max' 0 (numeral x) = numeral x\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   748
    \<open>max' (numeral x) 0 = numeral x\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   749
    \<open>max' 1 (numeral x) = numeral x\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   750
    \<open>max' (numeral x) 1 = numeral x\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   751
  by (simp_all add: max'_def max_def le_num_One_iff)
61630
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   752
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   753
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   754
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
   755
text \<open>Unfold \<open>min\<close> and \<open>max\<close> on numerals.\<close>
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
   756
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
   757
lemmas max_number_of [simp] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   758
  max_def [of \<open>numeral u\<close> \<open>numeral v\<close>]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   759
  max_def [of \<open>numeral u\<close> \<open>- numeral v\<close>]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   760
  max_def [of \<open>- numeral u\<close> \<open>numeral v\<close>]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   761
  max_def [of \<open>- numeral u\<close> \<open>- numeral v\<close>] for u v
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
   762
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
   763
lemmas min_number_of [simp] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   764
  min_def [of \<open>numeral u\<close> \<open>numeral v\<close>]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   765
  min_def [of \<open>numeral u\<close> \<open>- numeral v\<close>]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   766
  min_def [of \<open>- numeral u\<close> \<open>numeral v\<close>]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   767
  min_def [of \<open>- numeral u\<close> \<open>- numeral v\<close>] for u v
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
   768
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   769
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   770
subsubsection \<open>Multiplication and negation: class \<open>ring_1\<close>\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   771
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   772
context ring_1
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   773
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   774
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   775
subclass neg_numeral ..
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   776
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   777
lemma mult_neg_numeral_simps:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   778
  \<open>- numeral m * - numeral n = numeral (m * n)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   779
  \<open>- numeral m * numeral n = - numeral (m * n)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   780
  \<open>numeral m * - numeral n = - numeral (m * n)\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   781
  by (simp_all only: mult_minus_left mult_minus_right minus_minus numeral_mult)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   782
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   783
lemma mult_minus1 [simp]: \<open>- 1 * z = - z\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   784
  by (simp add: numeral.simps)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   785
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   786
lemma mult_minus1_right [simp]: \<open>z * - 1 = - z\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   787
  by (simp add: numeral.simps)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   788
71758
2e3fa4e7cd73 another rule on numerals
haftmann
parents: 71452
diff changeset
   789
lemma minus_sub_one_diff_one [simp]:
2e3fa4e7cd73 another rule on numerals
haftmann
parents: 71452
diff changeset
   790
  \<open>- sub m One - 1 = - numeral m\<close>
2e3fa4e7cd73 another rule on numerals
haftmann
parents: 71452
diff changeset
   791
proof -
2e3fa4e7cd73 another rule on numerals
haftmann
parents: 71452
diff changeset
   792
  have \<open>sub m One + 1 = numeral m\<close>
2e3fa4e7cd73 another rule on numerals
haftmann
parents: 71452
diff changeset
   793
    by (simp flip: eq_diff_eq add: diff_numeral_special)
2e3fa4e7cd73 another rule on numerals
haftmann
parents: 71452
diff changeset
   794
  then have \<open>- (sub m One + 1) = - numeral m\<close>
2e3fa4e7cd73 another rule on numerals
haftmann
parents: 71452
diff changeset
   795
    by simp
2e3fa4e7cd73 another rule on numerals
haftmann
parents: 71452
diff changeset
   796
  then show ?thesis
2e3fa4e7cd73 another rule on numerals
haftmann
parents: 71452
diff changeset
   797
    by simp
2e3fa4e7cd73 another rule on numerals
haftmann
parents: 71452
diff changeset
   798
qed
2e3fa4e7cd73 another rule on numerals
haftmann
parents: 71452
diff changeset
   799
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   800
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   801
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   802
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   803
subsubsection \<open>Equality using \<open>iszero\<close> for rings with non-zero characteristic\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   804
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   805
context ring_1
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   806
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   807
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   808
definition iszero :: \<open>'a \<Rightarrow> bool\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   809
  where \<open>iszero z \<longleftrightarrow> z = 0\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   810
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   811
lemma iszero_0 [simp]: \<open>iszero 0\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   812
  by (simp add: iszero_def)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   813
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   814
lemma not_iszero_1 [simp]: \<open>\<not> iszero 1\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   815
  by (simp add: iszero_def)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   816
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   817
lemma not_iszero_Numeral1: \<open>\<not> iszero Numeral1\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   818
  by (simp add: numeral_One)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   819
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   820
lemma not_iszero_neg_1 [simp]: \<open>\<not> iszero (- 1)\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   821
  by (simp add: iszero_def)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   822
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   823
lemma not_iszero_neg_Numeral1: \<open>\<not> iszero (- Numeral1)\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   824
  by (simp add: numeral_One)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   825
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   826
lemma iszero_neg_numeral [simp]: \<open>iszero (- numeral w) \<longleftrightarrow> iszero (numeral w)\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   827
  unfolding iszero_def by (rule neg_equal_0_iff_equal)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   828
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   829
lemma eq_iff_iszero_diff: \<open>x = y \<longleftrightarrow> iszero (x - y)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   830
  unfolding iszero_def by (rule eq_iff_diff_eq_0)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   831
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   832
text \<open>
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   833
  The \<open>eq_numeral_iff_iszero\<close> lemmas are not declared \<open>[simp]\<close> by default,
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   834
  because for rings of characteristic zero, better simp rules are possible.
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   835
  For a type like integers mod \<open>n\<close>, type-instantiated versions of these rules
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   836
  should be added to the simplifier, along with a type-specific rule for
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   837
  deciding propositions of the form \<open>iszero (numeral w)\<close>.
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   838
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   839
  bh: Maybe it would not be so bad to just declare these as simp rules anyway?
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   840
  I should test whether these rules take precedence over the \<open>ring_char_0\<close>
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   841
  rules in the simplifier.
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   842
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   843
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   844
lemma eq_numeral_iff_iszero:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   845
  \<open>numeral x = numeral y \<longleftrightarrow> iszero (sub x y)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   846
  \<open>numeral x = - numeral y \<longleftrightarrow> iszero (numeral (x + y))\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   847
  \<open>- numeral x = numeral y \<longleftrightarrow> iszero (numeral (x + y))\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   848
  \<open>- numeral x = - numeral y \<longleftrightarrow> iszero (sub y x)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   849
  \<open>numeral x = 1 \<longleftrightarrow> iszero (sub x One)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   850
  \<open>1 = numeral y \<longleftrightarrow> iszero (sub One y)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   851
  \<open>- numeral x = 1 \<longleftrightarrow> iszero (numeral (x + One))\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   852
  \<open>1 = - numeral y \<longleftrightarrow> iszero (numeral (One + y))\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   853
  \<open>numeral x = 0 \<longleftrightarrow> iszero (numeral x)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   854
  \<open>0 = numeral y \<longleftrightarrow> iszero (numeral y)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   855
  \<open>- numeral x = 0 \<longleftrightarrow> iszero (numeral x)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   856
  \<open>0 = - numeral y \<longleftrightarrow> iszero (numeral y)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   857
  unfolding eq_iff_iszero_diff diff_numeral_simps diff_numeral_special
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   858
  by simp_all
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   859
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   860
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   861
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   862
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   863
subsubsection \<open>Equality and negation: class \<open>ring_char_0\<close>\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   864
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62348
diff changeset
   865
context ring_char_0
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   866
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   867
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   868
lemma not_iszero_numeral [simp]: \<open>\<not> iszero (numeral w)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   869
  by (simp add: iszero_def)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   870
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   871
lemma neg_numeral_eq_iff: \<open>- numeral m = - numeral n \<longleftrightarrow> m = n\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   872
  by simp
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   873
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   874
lemma numeral_neq_neg_numeral: \<open>numeral m \<noteq> - numeral n\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   875
  by (simp add: eq_neg_iff_add_eq_0 numeral_plus_numeral)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   876
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   877
lemma neg_numeral_neq_numeral: \<open>- numeral m \<noteq> numeral n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   878
  by (rule numeral_neq_neg_numeral [symmetric])
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   879
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   880
lemma zero_neq_neg_numeral: \<open>0 \<noteq> - numeral n\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   881
  by simp
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   882
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   883
lemma neg_numeral_neq_zero: \<open>- numeral n \<noteq> 0\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   884
  by simp
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   885
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   886
lemma one_neq_neg_numeral: \<open>1 \<noteq> - numeral n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   887
  using numeral_neq_neg_numeral [of One n] by (simp add: numeral_One)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   888
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   889
lemma neg_numeral_neq_one: \<open>- numeral n \<noteq> 1\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   890
  using neg_numeral_neq_numeral [of n One] by (simp add: numeral_One)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   891
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   892
lemma neg_one_neq_numeral: \<open>- 1 \<noteq> numeral n\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   893
  using neg_numeral_neq_numeral [of One n] by (simp add: numeral_One)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   894
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   895
lemma numeral_neq_neg_one: \<open>numeral n \<noteq> - 1\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   896
  using numeral_neq_neg_numeral [of n One] by (simp add: numeral_One)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   897
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   898
lemma neg_one_eq_numeral_iff: \<open>- 1 = - numeral n \<longleftrightarrow> n = One\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   899
  using neg_numeral_eq_iff [of One n] by (auto simp add: numeral_One)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   900
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   901
lemma numeral_eq_neg_one_iff: \<open>- numeral n = - 1 \<longleftrightarrow> n = One\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   902
  using neg_numeral_eq_iff [of n One] by (auto simp add: numeral_One)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   903
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   904
lemma neg_one_neq_zero: \<open>- 1 \<noteq> 0\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   905
  by simp
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   906
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   907
lemma zero_neq_neg_one: \<open>0 \<noteq> - 1\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   908
  by simp
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   909
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   910
lemma neg_one_neq_one: \<open>- 1 \<noteq> 1\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   911
  using neg_numeral_neq_numeral [of One One] by (simp only: numeral_One not_False_eq_True)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   912
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   913
lemma one_neq_neg_one: \<open>1 \<noteq> - 1\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   914
  using numeral_neq_neg_numeral [of One One] by (simp only: numeral_One not_False_eq_True)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   915
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   916
lemmas eq_neg_numeral_simps [simp] =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   917
  neg_numeral_eq_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   918
  numeral_neq_neg_numeral neg_numeral_neq_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   919
  one_neq_neg_numeral neg_numeral_neq_one
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   920
  zero_neq_neg_numeral neg_numeral_neq_zero
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   921
  neg_one_neq_numeral numeral_neq_neg_one
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   922
  neg_one_eq_numeral_iff numeral_eq_neg_one_iff
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   923
  neg_one_neq_zero zero_neq_neg_one
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   924
  neg_one_neq_one one_neq_neg_one
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   925
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   926
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   927
62348
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61944
diff changeset
   928
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   929
subsubsection \<open>Structures with negation and order: class \<open>linordered_idom\<close>\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   930
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   931
context linordered_idom
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   932
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   933
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   934
subclass ring_char_0 ..
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   935
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   936
lemma neg_numeral_le_iff: \<open>- numeral m \<le> - numeral n \<longleftrightarrow> n \<le> m\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   937
  by (simp only: neg_le_iff_le numeral_le_iff)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   938
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   939
lemma neg_numeral_less_iff: \<open>- numeral m < - numeral n \<longleftrightarrow> n < m\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   940
  by (simp only: neg_less_iff_less numeral_less_iff)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   941
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   942
lemma neg_numeral_less_zero: \<open>- numeral n < 0\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   943
  by (simp only: neg_less_0_iff_less zero_less_numeral)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   944
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   945
lemma neg_numeral_le_zero: \<open>- numeral n \<le> 0\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   946
  by (simp only: neg_le_0_iff_le zero_le_numeral)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   947
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   948
lemma not_zero_less_neg_numeral: \<open>\<not> 0 < - numeral n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   949
  by (simp only: not_less neg_numeral_le_zero)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   950
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   951
lemma not_zero_le_neg_numeral: \<open>\<not> 0 \<le> - numeral n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   952
  by (simp only: not_le neg_numeral_less_zero)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   953
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   954
lemma neg_numeral_less_numeral: \<open>- numeral m < numeral n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   955
  using neg_numeral_less_zero zero_less_numeral by (rule less_trans)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   956
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   957
lemma neg_numeral_le_numeral: \<open>- numeral m \<le> numeral n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   958
  by (simp only: less_imp_le neg_numeral_less_numeral)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   959
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   960
lemma not_numeral_less_neg_numeral: \<open>\<not> numeral m < - numeral n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   961
  by (simp only: not_less neg_numeral_le_numeral)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   962
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   963
lemma not_numeral_le_neg_numeral: \<open>\<not> numeral m \<le> - numeral n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   964
  by (simp only: not_le neg_numeral_less_numeral)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   965
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   966
lemma neg_numeral_less_one: \<open>- numeral m < 1\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   967
  by (rule neg_numeral_less_numeral [of m One, unfolded numeral_One])
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   968
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   969
lemma neg_numeral_le_one: \<open>- numeral m \<le> 1\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   970
  by (rule neg_numeral_le_numeral [of m One, unfolded numeral_One])
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   971
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   972
lemma not_one_less_neg_numeral: \<open>\<not> 1 < - numeral m\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   973
  by (simp only: not_less neg_numeral_le_one)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   974
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   975
lemma not_one_le_neg_numeral: \<open>\<not> 1 \<le> - numeral m\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   976
  by (simp only: not_le neg_numeral_less_one)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   977
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   978
lemma not_numeral_less_neg_one: \<open>\<not> numeral m < - 1\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   979
  using not_numeral_less_neg_numeral [of m One] by (simp add: numeral_One)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   980
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   981
lemma not_numeral_le_neg_one: \<open>\<not> numeral m \<le> - 1\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   982
  using not_numeral_le_neg_numeral [of m One] by (simp add: numeral_One)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   983
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   984
lemma neg_one_less_numeral: \<open>- 1 < numeral m\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   985
  using neg_numeral_less_numeral [of One m] by (simp add: numeral_One)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   986
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   987
lemma neg_one_le_numeral: \<open>- 1 \<le> numeral m\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   988
  using neg_numeral_le_numeral [of One m] by (simp add: numeral_One)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   989
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   990
lemma neg_numeral_less_neg_one_iff: \<open>- numeral m < - 1 \<longleftrightarrow> m \<noteq> One\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   991
  by (cases m) simp_all
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   992
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   993
lemma neg_numeral_le_neg_one: \<open>- numeral m \<le> - 1\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   994
  by simp
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   995
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   996
lemma not_neg_one_less_neg_numeral: \<open>\<not> - 1 < - numeral m\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   997
  by simp
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   998
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
   999
lemma not_neg_one_le_neg_numeral_iff: \<open>\<not> - 1 \<le> - numeral m \<longleftrightarrow> m \<noteq> One\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1000
  by (cases m) simp_all
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1001
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1002
lemma sub_non_negative: \<open>sub n m \<ge> 0 \<longleftrightarrow> n \<ge> m\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1003
  by (simp only: sub_def le_diff_eq) simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1004
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1005
lemma sub_positive: \<open>sub n m > 0 \<longleftrightarrow> n > m\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1006
  by (simp only: sub_def less_diff_eq) simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1007
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1008
lemma sub_non_positive: \<open>sub n m \<le> 0 \<longleftrightarrow> n \<le> m\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1009
  by (simp only: sub_def diff_le_eq) simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1010
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1011
lemma sub_negative: \<open>sub n m < 0 \<longleftrightarrow> n < m\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1012
  by (simp only: sub_def diff_less_eq) simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1013
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1014
lemmas le_neg_numeral_simps [simp] =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1015
  neg_numeral_le_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1016
  neg_numeral_le_numeral not_numeral_le_neg_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1017
  neg_numeral_le_zero not_zero_le_neg_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1018
  neg_numeral_le_one not_one_le_neg_numeral
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1019
  neg_one_le_numeral not_numeral_le_neg_one
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1020
  neg_numeral_le_neg_one not_neg_one_le_neg_numeral_iff
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1021
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1022
lemma le_minus_one_simps [simp]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1023
  \<open>- 1 \<le> 0\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1024
  \<open>- 1 \<le> 1\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1025
  \<open>\<not> 0 \<le> - 1\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1026
  \<open>\<not> 1 \<le> - 1\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1027
  by simp_all
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1028
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1029
lemmas less_neg_numeral_simps [simp] =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1030
  neg_numeral_less_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1031
  neg_numeral_less_numeral not_numeral_less_neg_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1032
  neg_numeral_less_zero not_zero_less_neg_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1033
  neg_numeral_less_one not_one_less_neg_numeral
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1034
  neg_one_less_numeral not_numeral_less_neg_one
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1035
  neg_numeral_less_neg_one_iff not_neg_one_less_neg_numeral
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1036
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1037
lemma less_minus_one_simps [simp]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1038
  \<open>- 1 < 0\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1039
  \<open>- 1 < 1\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1040
  \<open>\<not> 0 < - 1\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1041
  \<open>\<not> 1 < - 1\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1042
  by (simp_all add: less_le)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1043
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1044
lemma abs_numeral [simp]: \<open>\<bar>numeral n\<bar> = numeral n\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1045
  by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1046
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1047
lemma abs_neg_numeral [simp]: \<open>\<bar>- numeral n\<bar> = numeral n\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1048
  by (simp only: abs_minus_cancel abs_numeral)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1049
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1050
lemma abs_neg_one [simp]: \<open>\<bar>- 1\<bar> = 1\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1051
  by simp
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1052
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1053
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1054
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1055
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1056
subsubsection \<open>Natural numbers\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1057
67959
78a64f3f7125 more rules for numeral conversions;
haftmann
parents: 67399
diff changeset
  1058
lemma numeral_num_of_nat:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1059
  \<open>numeral (num_of_nat n) = n\<close> if \<open>n > 0\<close>
67959
78a64f3f7125 more rules for numeral conversions;
haftmann
parents: 67399
diff changeset
  1060
  using that nat_of_num_numeral num_of_nat_inverse by simp
78a64f3f7125 more rules for numeral conversions;
haftmann
parents: 67399
diff changeset
  1061
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1062
lemma Suc_1 [simp]: \<open>Suc 1 = 2\<close>
47299
e705ef5ffe95 add lemma Suc_1
huffman
parents: 47255
diff changeset
  1063
  unfolding Suc_eq_plus1 by (rule one_add_one)
e705ef5ffe95 add lemma Suc_1
huffman
parents: 47255
diff changeset
  1064
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1065
lemma Suc_numeral [simp]: \<open>Suc (numeral n) = numeral (n + One)\<close>
47299
e705ef5ffe95 add lemma Suc_1
huffman
parents: 47255
diff changeset
  1066
  unfolding Suc_eq_plus1 by (rule numeral_plus_one)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1067
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1068
definition pred_numeral :: \<open>num \<Rightarrow> nat\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1069
  where \<open>pred_numeral k = numeral k - 1\<close>
67959
78a64f3f7125 more rules for numeral conversions;
haftmann
parents: 67399
diff changeset
  1070
78a64f3f7125 more rules for numeral conversions;
haftmann
parents: 67399
diff changeset
  1071
declare [[code drop: pred_numeral]]
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1072
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1073
lemma numeral_eq_Suc: \<open>numeral k = Suc (pred_numeral k)\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1074
  by (simp add: pred_numeral_def)
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1075
47220
52426c62b5d0 replace lemmas eval_nat_numeral with a simpler reformulation
huffman
parents: 47218
diff changeset
  1076
lemma eval_nat_numeral:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1077
  \<open>numeral One = Suc 0\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1078
  \<open>numeral (Bit0 n) = Suc (numeral (BitM n))\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1079
  \<open>numeral (Bit1 n) = Suc (numeral (Bit0 n))\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1080
  by (simp_all add: numeral.simps BitM_plus_one)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1081
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1082
lemma pred_numeral_simps [simp]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1083
  \<open>pred_numeral One = 0\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1084
  \<open>pred_numeral (Bit0 k) = numeral (BitM k)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1085
  \<open>pred_numeral (Bit1 k) = numeral (Bit0 k)\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1086
  by (simp_all only: pred_numeral_def eval_nat_numeral diff_Suc_Suc diff_0)
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1087
67959
78a64f3f7125 more rules for numeral conversions;
haftmann
parents: 67399
diff changeset
  1088
lemma pred_numeral_inc [simp]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1089
  \<open>pred_numeral (inc k) = numeral k\<close>
67959
78a64f3f7125 more rules for numeral conversions;
haftmann
parents: 67399
diff changeset
  1090
  by (simp only: pred_numeral_def numeral_inc diff_add_inverse2)
78a64f3f7125 more rules for numeral conversions;
haftmann
parents: 67399
diff changeset
  1091
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1092
lemma numeral_2_eq_2: \<open>2 = Suc (Suc 0)\<close>
47220
52426c62b5d0 replace lemmas eval_nat_numeral with a simpler reformulation
huffman
parents: 47218
diff changeset
  1093
  by (simp add: eval_nat_numeral)
47192
0c0501cb6da6 move many lemmas from Nat_Numeral.thy to Power.thy or Num.thy
huffman
parents: 47191
diff changeset
  1094
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1095
lemma numeral_3_eq_3: \<open>3 = Suc (Suc (Suc 0))\<close>
47220
52426c62b5d0 replace lemmas eval_nat_numeral with a simpler reformulation
huffman
parents: 47218
diff changeset
  1096
  by (simp add: eval_nat_numeral)
47192
0c0501cb6da6 move many lemmas from Nat_Numeral.thy to Power.thy or Num.thy
huffman
parents: 47191
diff changeset
  1097
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1098
lemma numeral_1_eq_Suc_0: \<open>Numeral1 = Suc 0\<close>
47207
9368aa814518 move lemmas from Nat_Numeral to Int.thy and Num.thy
huffman
parents: 47192
diff changeset
  1099
  by (simp only: numeral_One One_nat_def)
9368aa814518 move lemmas from Nat_Numeral to Int.thy and Num.thy
huffman
parents: 47192
diff changeset
  1100
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1101
lemma Suc_nat_number_of_add: \<open>Suc (numeral v + n) = numeral (v + One) + n\<close>
47207
9368aa814518 move lemmas from Nat_Numeral to Int.thy and Num.thy
huffman
parents: 47192
diff changeset
  1102
  by simp
9368aa814518 move lemmas from Nat_Numeral to Int.thy and Num.thy
huffman
parents: 47192
diff changeset
  1103
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1104
lemma numerals: \<open>Numeral1 = (1::nat)\<close> \<open>2 = Suc (Suc 0)\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1105
  by (rule numeral_One) (rule numeral_2_eq_2)
47207
9368aa814518 move lemmas from Nat_Numeral to Int.thy and Num.thy
huffman
parents: 47192
diff changeset
  1106
63913
Lars Hupel <lars.hupel@mytum.de>
parents: 63654
diff changeset
  1107
lemmas numeral_nat = eval_nat_numeral BitM.simps One_nat_def
Lars Hupel <lars.hupel@mytum.de>
parents: 63654
diff changeset
  1108
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
  1109
text \<open>Comparisons involving \<^term>\<open>Suc\<close>.\<close>
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1110
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1111
lemma eq_numeral_Suc [simp]: \<open>numeral k = Suc n \<longleftrightarrow> pred_numeral k = n\<close>
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1112
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1113
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1114
lemma Suc_eq_numeral [simp]: \<open>Suc n = numeral k \<longleftrightarrow> n = pred_numeral k\<close>
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1115
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1116
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1117
lemma less_numeral_Suc [simp]: \<open>numeral k < Suc n \<longleftrightarrow> pred_numeral k < n\<close>
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1118
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1119
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1120
lemma less_Suc_numeral [simp]: \<open>Suc n < numeral k \<longleftrightarrow> n < pred_numeral k\<close>
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1121
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1122
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1123
lemma le_numeral_Suc [simp]: \<open>numeral k \<le> Suc n \<longleftrightarrow> pred_numeral k \<le> n\<close>
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1124
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1125
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1126
lemma le_Suc_numeral [simp]: \<open>Suc n \<le> numeral k \<longleftrightarrow> n \<le> pred_numeral k\<close>
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1127
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1128
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1129
lemma diff_Suc_numeral [simp]: \<open>Suc n - numeral k = n - pred_numeral k\<close>
47218
2b652cbadde1 new lemmas for simplifying subtraction on nat numerals
huffman
parents: 47216
diff changeset
  1130
  by (simp add: numeral_eq_Suc)
2b652cbadde1 new lemmas for simplifying subtraction on nat numerals
huffman
parents: 47216
diff changeset
  1131
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1132
lemma diff_numeral_Suc [simp]: \<open>numeral k - Suc n = pred_numeral k - n\<close>
47218
2b652cbadde1 new lemmas for simplifying subtraction on nat numerals
huffman
parents: 47216
diff changeset
  1133
  by (simp add: numeral_eq_Suc)
2b652cbadde1 new lemmas for simplifying subtraction on nat numerals
huffman
parents: 47216
diff changeset
  1134
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1135
lemma max_Suc_numeral [simp]: \<open>max (Suc n) (numeral k) = Suc (max n (pred_numeral k))\<close>
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1136
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1137
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1138
lemma max_numeral_Suc [simp]: \<open>max (numeral k) (Suc n) = Suc (max (pred_numeral k) n)\<close>
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1139
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1140
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1141
lemma min_Suc_numeral [simp]: \<open>min (Suc n) (numeral k) = Suc (min n (pred_numeral k))\<close>
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1142
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1143
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1144
lemma min_numeral_Suc [simp]: \<open>min (numeral k) (Suc n) = Suc (min (pred_numeral k) n)\<close>
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1145
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1146
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
  1147
text \<open>For \<^term>\<open>case_nat\<close> and \<^term>\<open>rec_nat\<close>.\<close>
47216
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1148
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1149
lemma case_nat_numeral [simp]: \<open>case_nat a f (numeral v) = (let pv = pred_numeral v in f pv)\<close>
47216
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1150
  by (simp add: numeral_eq_Suc)
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1151
55415
05f5fdb8d093 renamed 'nat_{case,rec}' to '{case,rec}_nat'
blanchet
parents: 54489
diff changeset
  1152
lemma case_nat_add_eq_if [simp]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1153
  \<open>case_nat a f ((numeral v) + n) = (let pv = pred_numeral v in f (pv + n))\<close>
47216
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1154
  by (simp add: numeral_eq_Suc)
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1155
55415
05f5fdb8d093 renamed 'nat_{case,rec}' to '{case,rec}_nat'
blanchet
parents: 54489
diff changeset
  1156
lemma rec_nat_numeral [simp]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1157
  \<open>rec_nat a f (numeral v) = (let pv = pred_numeral v in f pv (rec_nat a f pv))\<close>
47216
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1158
  by (simp add: numeral_eq_Suc Let_def)
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1159
55415
05f5fdb8d093 renamed 'nat_{case,rec}' to '{case,rec}_nat'
blanchet
parents: 54489
diff changeset
  1160
lemma rec_nat_add_eq_if [simp]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1161
  \<open>rec_nat a f (numeral v + n) = (let pv = pred_numeral v in f (pv + n) (rec_nat a f (pv + n)))\<close>
47216
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1162
  by (simp add: numeral_eq_Suc Let_def)
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1163
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
  1164
text \<open>Case analysis on \<^term>\<open>n < 2\<close>.\<close>
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1165
lemma less_2_cases: \<open>n < 2 \<Longrightarrow> n = 0 \<or> n = Suc 0\<close>
47255
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1166
  by (auto simp add: numeral_2_eq_2)
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1167
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1168
lemma less_2_cases_iff: \<open>n < 2 \<longleftrightarrow> n = 0 \<or> n = Suc 0\<close>
71452
9edb7fb69bc2 a few new lemmas
paulson <lp15@cam.ac.uk>
parents: 70927
diff changeset
  1169
  by (auto simp add: numeral_2_eq_2)
9edb7fb69bc2 a few new lemmas
paulson <lp15@cam.ac.uk>
parents: 70927
diff changeset
  1170
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1171
text \<open>Removal of Small Numerals: 0, 1 and (in additive positions) 2.\<close>
71452
9edb7fb69bc2 a few new lemmas
paulson <lp15@cam.ac.uk>
parents: 70927
diff changeset
  1172
text \<open>bh: Are these rules really a good idea? LCP: well, it already happens for 0 and 1!\<close>
47255
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1173
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1174
lemma add_2_eq_Suc [simp]: \<open>2 + n = Suc (Suc n)\<close>
47255
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1175
  by simp
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1176
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1177
lemma add_2_eq_Suc' [simp]: \<open>n + 2 = Suc (Suc n)\<close>
47255
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1178
  by simp
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1179
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1180
text \<open>Can be used to eliminate long strings of Sucs, but not by default.\<close>
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1181
lemma Suc3_eq_add_3: \<open>Suc (Suc (Suc n)) = 3 + n\<close>
47255
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1182
  by simp
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1183
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1184
lemmas nat_1_add_1 = one_add_one [where 'a=nat] (* legacy *)
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1185
71760
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1186
context semiring_numeral
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1187
begin
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1188
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1189
lemma numeral_add_unfold_funpow:
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1190
  \<open>numeral k + a = ((+) 1 ^^ numeral k) a\<close>
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1191
proof (rule sym, induction k arbitrary: a)
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1192
  case One
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1193
  then show ?case
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1194
    by (simp add: Num.numeral_One numeral_One)
71760
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1195
next
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1196
  case (Bit0 k)
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1197
  then show ?case
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1198
    by (simp add: Num.numeral_Bit0 numeral_Bit0 ac_simps funpow_add)
71760
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1199
next
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1200
  case (Bit1 k)
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1201
  then show ?case
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1202
    by (simp add: Num.numeral_Bit1 numeral_Bit1 ac_simps funpow_add)
71760
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1203
qed
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1204
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1205
end
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1206
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1207
context semiring_1
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1208
begin
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1209
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1210
lemma numeral_unfold_funpow:
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1211
  \<open>numeral k = ((+) 1 ^^ numeral k) 0\<close>
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1212
  using numeral_add_unfold_funpow [of k 0] by simp
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1213
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1214
end
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1215
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1216
context
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1217
  includes lifting_syntax
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1218
begin
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1219
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1220
lemma transfer_rule_numeral:
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1221
  \<open>((=) ===> R) numeral numeral\<close>
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1222
    if [transfer_rule]: \<open>R 0 0\<close> \<open>R 1 1\<close>
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1223
      \<open>(R ===> R ===> R) (+) (+)\<close>
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1224
    for R :: \<open>'a::{semiring_numeral,monoid_add} \<Rightarrow> 'b::{semiring_numeral,monoid_add} \<Rightarrow> bool\<close>
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1225
proof -
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1226
  have \<open>((=) ===> R) (\<lambda>k. ((+) 1 ^^ numeral k) 0) (\<lambda>k. ((+) 1 ^^ numeral k) 0)\<close>
71760
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1227
    by transfer_prover
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1228
  moreover have \<open>numeral = (\<lambda>k. ((+) (1::'a) ^^ numeral k) 0)\<close>
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1229
    using numeral_add_unfold_funpow [where ?'a = 'a, of _ 0]
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1230
    by (simp add: fun_eq_iff)
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1231
  moreover have \<open>numeral = (\<lambda>k. ((+) (1::'b) ^^ numeral k) 0)\<close>
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1232
    using numeral_add_unfold_funpow [where ?'a = 'b, of _ 0]
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1233
    by (simp add: fun_eq_iff)
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1234
  ultimately show ?thesis
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1235
    by simp
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1236
qed
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1237
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1238
end
e4e05fcd8937 generalized
haftmann
parents: 71758
diff changeset
  1239
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1240
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
  1241
subsection \<open>Particular lemmas concerning \<^term>\<open>2\<close>\<close>
58512
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1242
59867
58043346ca64 given up separate type classes demanding `inverse 0 = 0`
haftmann
parents: 59621
diff changeset
  1243
context linordered_field
58512
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1244
begin
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1245
62348
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61944
diff changeset
  1246
subclass field_char_0 ..
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61944
diff changeset
  1247
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1248
lemma half_gt_zero_iff: \<open>0 < a / 2 \<longleftrightarrow> 0 < a\<close>
58512
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1249
  by (auto simp add: field_simps)
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1250
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1251
lemma half_gt_zero [simp]: \<open>0 < a \<Longrightarrow> 0 < a / 2\<close>
58512
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1252
  by (simp add: half_gt_zero_iff)
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1253
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1254
end
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1255
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1256
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1257
subsection \<open>Numeral equations as default simplification rules\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1258
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1259
declare (in numeral) numeral_One [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1260
declare (in numeral) numeral_plus_numeral [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1261
declare (in numeral) add_numeral_special [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1262
declare (in neg_numeral) add_neg_numeral_simps [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1263
declare (in neg_numeral) add_neg_numeral_special [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1264
declare (in neg_numeral) diff_numeral_simps [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1265
declare (in neg_numeral) diff_numeral_special [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1266
declare (in semiring_numeral) numeral_times_numeral [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1267
declare (in ring_1) mult_neg_numeral_simps [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1268
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1269
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1270
subsubsection \<open>Special Simplification for Constants\<close>
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1271
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1272
text \<open>These distributive laws move literals inside sums and differences.\<close>
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1273
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1274
lemmas distrib_right_numeral [simp] = distrib_right [of _ _ \<open>numeral v\<close>] for v
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1275
lemmas distrib_left_numeral [simp] = distrib_left [of \<open>numeral v\<close>] for v
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1276
lemmas left_diff_distrib_numeral [simp] = left_diff_distrib [of _ _ \<open>numeral v\<close>] for v
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1277
lemmas right_diff_distrib_numeral [simp] = right_diff_distrib [of \<open>numeral v\<close>] for v
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1278
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1279
text \<open>These are actually for fields, like real\<close>
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1280
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1281
lemmas zero_less_divide_iff_numeral [simp, no_atp] = zero_less_divide_iff [of \<open>numeral w\<close>] for w
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1282
lemmas divide_less_0_iff_numeral [simp, no_atp] = divide_less_0_iff [of \<open>numeral w\<close>] for w
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1283
lemmas zero_le_divide_iff_numeral [simp, no_atp] = zero_le_divide_iff [of \<open>numeral w\<close>] for w
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1284
lemmas divide_le_0_iff_numeral [simp, no_atp] = divide_le_0_iff [of \<open>numeral w\<close>] for w
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1285
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1286
text \<open>Replaces \<open>inverse #nn\<close> by \<open>1/#nn\<close>.  It looks
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1287
  strange, but then other simprocs simplify the quotient.\<close>
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1288
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1289
lemmas inverse_eq_divide_numeral [simp] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1290
  inverse_eq_divide [of \<open>numeral w\<close>] for w
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1291
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1292
lemmas inverse_eq_divide_neg_numeral [simp] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1293
  inverse_eq_divide [of \<open>- numeral w\<close>] for w
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1294
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1295
text \<open>These laws simplify inequalities, moving unary minus from a term
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1296
  into the literal.\<close>
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1297
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1298
lemmas equation_minus_iff_numeral [no_atp] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1299
  equation_minus_iff [of \<open>numeral v\<close>] for v
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1300
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1301
lemmas minus_equation_iff_numeral [no_atp] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1302
  minus_equation_iff [of _ \<open>numeral v\<close>] for v
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1303
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1304
lemmas le_minus_iff_numeral [no_atp] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1305
  le_minus_iff [of \<open>numeral v\<close>] for v
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1306
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1307
lemmas minus_le_iff_numeral [no_atp] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1308
  minus_le_iff [of _ \<open>numeral v\<close>] for v
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1309
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1310
lemmas less_minus_iff_numeral [no_atp] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1311
  less_minus_iff [of \<open>numeral v\<close>] for v
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1312
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1313
lemmas minus_less_iff_numeral [no_atp] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1314
  minus_less_iff [of _ \<open>numeral v\<close>] for v
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1315
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1316
(* FIXME maybe simproc *)
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1317
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1318
text \<open>Cancellation of constant factors in comparisons (\<open><\<close> and \<open>\<le>\<close>)\<close>
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1319
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1320
lemmas mult_less_cancel_left_numeral [simp, no_atp] = mult_less_cancel_left [of \<open>numeral v\<close>] for v
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1321
lemmas mult_less_cancel_right_numeral [simp, no_atp] = mult_less_cancel_right [of _ \<open>numeral v\<close>] for v
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1322
lemmas mult_le_cancel_left_numeral [simp, no_atp] = mult_le_cancel_left [of \<open>numeral v\<close>] for v
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1323
lemmas mult_le_cancel_right_numeral [simp, no_atp] = mult_le_cancel_right [of _ \<open>numeral v\<close>] for v
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1324
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1325
text \<open>Multiplying out constant divisors in comparisons (\<open><\<close>, \<open>\<le>\<close> and \<open>=\<close>)\<close>
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1326
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1327
named_theorems divide_const_simps \<open>simplification rules to simplify comparisons involving constant divisors\<close>
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1328
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1329
lemmas le_divide_eq_numeral1 [simp,divide_const_simps] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1330
  pos_le_divide_eq [of \<open>numeral w\<close>, OF zero_less_numeral]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1331
  neg_le_divide_eq [of \<open>- numeral w\<close>, OF neg_numeral_less_zero] for w
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1332
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1333
lemmas divide_le_eq_numeral1 [simp,divide_const_simps] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1334
  pos_divide_le_eq [of \<open>numeral w\<close>, OF zero_less_numeral]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1335
  neg_divide_le_eq [of \<open>- numeral w\<close>, OF neg_numeral_less_zero] for w
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1336
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1337
lemmas less_divide_eq_numeral1 [simp,divide_const_simps] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1338
  pos_less_divide_eq [of \<open>numeral w\<close>, OF zero_less_numeral]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1339
  neg_less_divide_eq [of \<open>- numeral w\<close>, OF neg_numeral_less_zero] for w
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1340
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1341
lemmas divide_less_eq_numeral1 [simp,divide_const_simps] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1342
  pos_divide_less_eq [of \<open>numeral w\<close>, OF zero_less_numeral]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1343
  neg_divide_less_eq [of \<open>- numeral w\<close>, OF neg_numeral_less_zero] for w
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1344
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1345
lemmas eq_divide_eq_numeral1 [simp,divide_const_simps] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1346
  eq_divide_eq [of _ _ \<open>numeral w\<close>]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1347
  eq_divide_eq [of _ _ \<open>- numeral w\<close>] for w
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1348
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1349
lemmas divide_eq_eq_numeral1 [simp,divide_const_simps] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1350
  divide_eq_eq [of _ \<open>numeral w\<close>]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1351
  divide_eq_eq [of _ \<open>- numeral w\<close>] for w
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1352
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1353
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1354
subsubsection \<open>Optional Simplification Rules Involving Constants\<close>
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1355
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1356
text \<open>Simplify quotients that are compared with a literal constant.\<close>
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1357
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1358
lemmas le_divide_eq_numeral [divide_const_simps] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1359
  le_divide_eq [of \<open>numeral w\<close>]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1360
  le_divide_eq [of \<open>- numeral w\<close>] for w
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1361
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1362
lemmas divide_le_eq_numeral [divide_const_simps] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1363
  divide_le_eq [of _ _ \<open>numeral w\<close>]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1364
  divide_le_eq [of _ _ \<open>- numeral w\<close>] for w
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1365
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1366
lemmas less_divide_eq_numeral [divide_const_simps] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1367
  less_divide_eq [of \<open>numeral w\<close>]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1368
  less_divide_eq [of \<open>- numeral w\<close>] for w
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1369
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1370
lemmas divide_less_eq_numeral [divide_const_simps] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1371
  divide_less_eq [of _ _ \<open>numeral w\<close>]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1372
  divide_less_eq [of _ _ \<open>- numeral w\<close>] for w
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1373
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1374
lemmas eq_divide_eq_numeral [divide_const_simps] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1375
  eq_divide_eq [of \<open>numeral w\<close>]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1376
  eq_divide_eq [of \<open>- numeral w\<close>] for w
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1377
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1378
lemmas divide_eq_eq_numeral [divide_const_simps] =
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1379
  divide_eq_eq [of _ _ \<open>numeral w\<close>]
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1380
  divide_eq_eq [of _ _ \<open>- numeral w\<close>] for w
67116
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1381
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1382
text \<open>Not good as automatic simprules because they cause case splits.\<close>
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1383
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1384
lemmas [divide_const_simps] =
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1385
  le_divide_eq_1 divide_le_eq_1 less_divide_eq_1 divide_less_eq_1
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1386
7397a6df81d8 cleaned up and tuned
haftmann
parents: 66936
diff changeset
  1387
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1388
subsection \<open>Setting up simprocs\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1389
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1390
lemma mult_numeral_1: \<open>Numeral1 * a = a\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1391
  for a :: \<open>'a::semiring_numeral\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1392
  by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1393
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1394
lemma mult_numeral_1_right: \<open>a * Numeral1 = a\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1395
  for a :: \<open>'a::semiring_numeral\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1396
  by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1397
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1398
lemma divide_numeral_1: \<open>a / Numeral1 = a\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1399
  for a :: \<open>'a::field\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1400
  by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1401
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1402
lemma inverse_numeral_1: \<open>inverse Numeral1 = (Numeral1::'a::division_ring)\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1403
  by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1404
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1405
text \<open>
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1406
  Theorem lists for the cancellation simprocs. The use of a binary
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1407
  numeral for 1 reduces the number of special cases.
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1408
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1409
68536
e14848001c4c avoid pending shyps in global theory facts;
wenzelm
parents: 67959
diff changeset
  1410
lemma mult_1s_semiring_numeral:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1411
  \<open>Numeral1 * a = a\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1412
  \<open>a * Numeral1 = a\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1413
  for a :: \<open>'a::semiring_numeral\<close>
68536
e14848001c4c avoid pending shyps in global theory facts;
wenzelm
parents: 67959
diff changeset
  1414
  by simp_all
e14848001c4c avoid pending shyps in global theory facts;
wenzelm
parents: 67959
diff changeset
  1415
e14848001c4c avoid pending shyps in global theory facts;
wenzelm
parents: 67959
diff changeset
  1416
lemma mult_1s_ring_1:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1417
  \<open>- Numeral1 * b = - b\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1418
  \<open>b * - Numeral1 = - b\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1419
  for b :: \<open>'a::ring_1\<close>
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1420
  by simp_all
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1421
68536
e14848001c4c avoid pending shyps in global theory facts;
wenzelm
parents: 67959
diff changeset
  1422
lemmas mult_1s = mult_1s_semiring_numeral mult_1s_ring_1
e14848001c4c avoid pending shyps in global theory facts;
wenzelm
parents: 67959
diff changeset
  1423
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1424
setup \<open>
47226
ea712316fc87 set up numeral reorient simproc in Num.thy
huffman
parents: 47220
diff changeset
  1425
  Reorient_Proc.add
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
  1426
    (fn Const (\<^const_name>\<open>numeral\<close>, _) $ _ => true
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
  1427
      | Const (\<^const_name>\<open>uminus\<close>, _) $ (Const (\<^const_name>\<open>numeral\<close>, _) $ _) => true
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1428
      | _ => false)
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1429
\<close>
47226
ea712316fc87 set up numeral reorient simproc in Num.thy
huffman
parents: 47220
diff changeset
  1430
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1431
simproc_setup reorient_numeral (\<open>numeral w = x\<close> | \<open>- numeral w = y\<close>) =
78099
4d9349989d94 more uniform simproc_setup: avoid vacuous abstraction over morphism, which sometimes captures context values in its functional closure;
wenzelm
parents: 75669
diff changeset
  1432
  \<open>K Reorient_Proc.proc\<close>
47226
ea712316fc87 set up numeral reorient simproc in Num.thy
huffman
parents: 47220
diff changeset
  1433
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1434
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1435
subsubsection \<open>Simplification of arithmetic operations on integer constants\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1436
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1437
lemmas arith_special = (* already declared simp above *)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1438
  add_numeral_special add_neg_numeral_special
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1439
  diff_numeral_special
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1440
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1441
lemmas arith_extra_simps = (* rules already in simpset *)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1442
  numeral_plus_numeral add_neg_numeral_simps add_0_left add_0_right
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1443
  minus_zero
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1444
  diff_numeral_simps diff_0 diff_0_right
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1445
  numeral_times_numeral mult_neg_numeral_simps
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1446
  mult_zero_left mult_zero_right
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1447
  abs_numeral abs_neg_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1448
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1449
text \<open>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1450
  For making a minimal simpset, one must include these default simprules.
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
  1451
  Also include \<open>simp_thms\<close>.
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1452
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1453
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1454
lemmas arith_simps =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1455
  add_num_simps mult_num_simps sub_num_simps
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1456
  BitM.simps dbl_simps dbl_inc_simps dbl_dec_simps
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1457
  abs_zero abs_one arith_extra_simps
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1458
54249
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1459
lemmas more_arith_simps =
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1460
  neg_le_iff_le
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1461
  minus_zero left_minus right_minus
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1462
  mult_1_left mult_1_right
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1463
  mult_minus_left mult_minus_right
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
  1464
  minus_add_distrib minus_minus mult.assoc
54249
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1465
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1466
lemmas of_nat_simps =
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1467
  of_nat_0 of_nat_1 of_nat_Suc of_nat_add of_nat_mult
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1468
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1469
text \<open>Simplification of relational operations.\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1470
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1471
lemmas eq_numeral_extra =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1472
  zero_neq_one one_neq_zero
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1473
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1474
lemmas rel_simps =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1475
  le_num_simps less_num_simps eq_num_simps
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1476
  le_numeral_simps le_neg_numeral_simps le_minus_one_simps le_numeral_extra
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1477
  less_numeral_simps less_neg_numeral_simps less_minus_one_simps less_numeral_extra
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1478
  eq_numeral_simps eq_neg_numeral_simps eq_numeral_extra
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1479
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1480
lemma Let_numeral [simp]: \<open>Let (numeral v) f = f (numeral v)\<close>
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
  1481
  \<comment> \<open>Unfold all \<open>let\<close>s involving constants\<close>
54249
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1482
  unfolding Let_def ..
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1483
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1484
lemma Let_neg_numeral [simp]: \<open>Let (- numeral v) f = f (- numeral v)\<close>
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
  1485
  \<comment> \<open>Unfold all \<open>let\<close>s involving constants\<close>
54249
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1486
  unfolding Let_def ..
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1487
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1488
declaration \<open>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1489
let
59996
4dca48557921 tuned signature;
wenzelm
parents: 59867
diff changeset
  1490
  fun number_of ctxt T n =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68536
diff changeset
  1491
    if not (Sign.of_sort (Proof_Context.theory_of ctxt) (T, \<^sort>\<open>numeral\<close>))
54249
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1492
    then raise CTERM ("number_of", [])
59996
4dca48557921 tuned signature;
wenzelm
parents: 59867
diff changeset
  1493
    else Numeral.mk_cnumber (Thm.ctyp_of ctxt T) n;
54249
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1494
in
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1495
  K (
70356
4a327c061870 streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents: 70270
diff changeset
  1496
    Lin_Arith.set_number_of number_of
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1497
    #> Lin_Arith.add_simps
70356
4a327c061870 streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents: 70270
diff changeset
  1498
      @{thms arith_simps more_arith_simps rel_simps pred_numeral_simps
4a327c061870 streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents: 70270
diff changeset
  1499
        arith_special numeral_One of_nat_simps uminus_numeral_One
4a327c061870 streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents: 70270
diff changeset
  1500
        Suc_numeral Let_numeral Let_neg_numeral Let_0 Let_1
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1501
        le_Suc_numeral le_numeral_Suc less_Suc_numeral less_numeral_Suc
70356
4a327c061870 streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents: 70270
diff changeset
  1502
        Suc_eq_numeral eq_numeral_Suc mult_Suc mult_Suc_right of_nat_numeral})
54249
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1503
end
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1504
\<close>
54249
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1505
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1506
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1507
subsubsection \<open>Simplification of arithmetic when nested to the right\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1508
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1509
lemma add_numeral_left [simp]: \<open>numeral v + (numeral w + z) = (numeral(v + w) + z)\<close>
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
  1510
  by (simp_all add: add.assoc [symmetric])
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1511
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1512
lemma add_neg_numeral_left [simp]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1513
  \<open>numeral v + (- numeral w + y) = (sub v w + y)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1514
  \<open>- numeral v + (numeral w + y) = (sub w v + y)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1515
  \<open>- numeral v + (- numeral w + y) = (- numeral(v + w) + y)\<close>
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
  1516
  by (simp_all add: add.assoc [symmetric])
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1517
68536
e14848001c4c avoid pending shyps in global theory facts;
wenzelm
parents: 67959
diff changeset
  1518
lemma mult_numeral_left_semiring_numeral:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1519
  \<open>numeral v * (numeral w * z) = (numeral(v * w) * z :: 'a::semiring_numeral)\<close>
68536
e14848001c4c avoid pending shyps in global theory facts;
wenzelm
parents: 67959
diff changeset
  1520
  by (simp add: mult.assoc [symmetric])
e14848001c4c avoid pending shyps in global theory facts;
wenzelm
parents: 67959
diff changeset
  1521
e14848001c4c avoid pending shyps in global theory facts;
wenzelm
parents: 67959
diff changeset
  1522
lemma mult_numeral_left_ring_1:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1523
  \<open>- numeral v * (numeral w * y) = (- numeral(v * w) * y :: 'a::ring_1)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1524
  \<open>numeral v * (- numeral w * y) = (- numeral(v * w) * y :: 'a::ring_1)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1525
  \<open>- numeral v * (- numeral w * y) = (numeral(v * w) * y :: 'a::ring_1)\<close>
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
  1526
  by (simp_all add: mult.assoc [symmetric])
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1527
68536
e14848001c4c avoid pending shyps in global theory facts;
wenzelm
parents: 67959
diff changeset
  1528
lemmas mult_numeral_left [simp] =
e14848001c4c avoid pending shyps in global theory facts;
wenzelm
parents: 67959
diff changeset
  1529
  mult_numeral_left_semiring_numeral
e14848001c4c avoid pending shyps in global theory facts;
wenzelm
parents: 67959
diff changeset
  1530
  mult_numeral_left_ring_1
e14848001c4c avoid pending shyps in global theory facts;
wenzelm
parents: 67959
diff changeset
  1531
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1532
51143
0a2371e7ced3 two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents: 50817
diff changeset
  1533
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
  1534
subsection \<open>Code module namespace\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1535
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52210
diff changeset
  1536
code_identifier
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52210
diff changeset
  1537
  code_module Num \<rightharpoonup> (SML) Arith and (OCaml) Arith and (Haskell) Arith
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1538
66283
adf3155c57e2 Printing natural numbers as numerals in evaluation
eberlm <eberlm@in.tum.de>
parents: 64238
diff changeset
  1539
subsection \<open>Printing of evaluated natural numbers as numerals\<close>
adf3155c57e2 Printing natural numbers as numerals in evaluation
eberlm <eberlm@in.tum.de>
parents: 64238
diff changeset
  1540
adf3155c57e2 Printing natural numbers as numerals in evaluation
eberlm <eberlm@in.tum.de>
parents: 64238
diff changeset
  1541
lemma [code_post]:
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1542
  \<open>Suc 0 = 1\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1543
  \<open>Suc 1 = 2\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1544
  \<open>Suc (numeral n) = numeral (inc n)\<close>
66283
adf3155c57e2 Printing natural numbers as numerals in evaluation
eberlm <eberlm@in.tum.de>
parents: 64238
diff changeset
  1545
  by (simp_all add: numeral_inc)
adf3155c57e2 Printing natural numbers as numerals in evaluation
eberlm <eberlm@in.tum.de>
parents: 64238
diff changeset
  1546
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1547
lemmas [code_post] = inc.simps
66283
adf3155c57e2 Printing natural numbers as numerals in evaluation
eberlm <eberlm@in.tum.de>
parents: 64238
diff changeset
  1548
74592
3c587b7c3d5c more generic bit/word lemmas for distribution
haftmann
parents: 71991
diff changeset
  1549
3c587b7c3d5c more generic bit/word lemmas for distribution
haftmann
parents: 71991
diff changeset
  1550
subsection \<open>More on auxiliary conversion\<close>
3c587b7c3d5c more generic bit/word lemmas for distribution
haftmann
parents: 71991
diff changeset
  1551
3c587b7c3d5c more generic bit/word lemmas for distribution
haftmann
parents: 71991
diff changeset
  1552
context semiring_1
3c587b7c3d5c more generic bit/word lemmas for distribution
haftmann
parents: 71991
diff changeset
  1553
begin
3c587b7c3d5c more generic bit/word lemmas for distribution
haftmann
parents: 71991
diff changeset
  1554
3c587b7c3d5c more generic bit/word lemmas for distribution
haftmann
parents: 71991
diff changeset
  1555
lemma num_of_nat_numeral_eq [simp]:
3c587b7c3d5c more generic bit/word lemmas for distribution
haftmann
parents: 71991
diff changeset
  1556
  \<open>num_of_nat (numeral q) = q\<close>
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1557
  by (simp flip: nat_of_num_numeral add: nat_of_num_inverse)
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1558
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1559
lemma numeral_num_of_nat_unfold:
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1560
  \<open>numeral (num_of_nat n) = (if n = 0 then 1 else of_nat n)\<close>
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1561
  apply (simp only: of_nat_numeral [symmetric, of \<open>num_of_nat n\<close>] flip: nat_of_num_numeral)
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1562
  apply (auto simp add: num_of_nat_inverse)
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1563
  done
74592
3c587b7c3d5c more generic bit/word lemmas for distribution
haftmann
parents: 71991
diff changeset
  1564
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1565
end
74592
3c587b7c3d5c more generic bit/word lemmas for distribution
haftmann
parents: 71991
diff changeset
  1566
81980
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1567
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1568
hide_const (open) One Bit0 Bit1 BitM inc pow sqr sub dbl dbl_inc dbl_dec
13b5aa1b3fb4 modernized and streamlined theory
haftmann
parents: 81124
diff changeset
  1569
74592
3c587b7c3d5c more generic bit/word lemmas for distribution
haftmann
parents: 71991
diff changeset
  1570
end