src/HOL/Num.thy
author wenzelm
Mon, 28 Dec 2015 01:26:34 +0100
changeset 61944 5d06ecfdb472
parent 61799 4cf66f21b764
child 62348 9a5f43dac883
permissions -rw-r--r--
prefer symbols for "abs";
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
58154
47c3c7019b97 tuned imports
blanchet
parents: 58152
diff changeset
     9
imports BNF_Least_Fixpoint
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
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
    16
text \<open>Increment function for type @{typ num}\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    17
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    18
primrec inc :: "num \<Rightarrow> num" where
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    19
  "inc One = Bit0 One" |
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    20
  "inc (Bit0 x) = Bit1 x" |
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    21
  "inc (Bit1 x) = Bit0 (inc x)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    22
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
    23
text \<open>Converting between type @{typ num} and type @{typ nat}\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    24
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    25
primrec nat_of_num :: "num \<Rightarrow> nat" where
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    26
  "nat_of_num One = Suc 0" |
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    27
  "nat_of_num (Bit0 x) = nat_of_num x + nat_of_num x" |
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    28
  "nat_of_num (Bit1 x) = Suc (nat_of_num x + nat_of_num x)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    29
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    30
primrec num_of_nat :: "nat \<Rightarrow> num" where
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    31
  "num_of_nat 0 = One" |
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    32
  "num_of_nat (Suc n) = (if 0 < n then inc (num_of_nat n) else One)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    33
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    34
lemma nat_of_num_pos: "0 < nat_of_num x"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    35
  by (induct x) simp_all
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    36
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    37
lemma nat_of_num_neq_0: " nat_of_num x \<noteq> 0"
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
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    40
lemma nat_of_num_inc: "nat_of_num (inc x) = Suc (nat_of_num x)"
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
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    43
lemma num_of_nat_double:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    44
  "0 < n \<Longrightarrow> num_of_nat (n + n) = Bit0 (num_of_nat n)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    45
  by (induct n) simp_all
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    46
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
    47
text \<open>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    48
  Type @{typ num} is isomorphic to the strictly positive
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    49
  natural numbers.
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
    50
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    51
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    52
lemma nat_of_num_inverse: "num_of_nat (nat_of_num x) = x"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    53
  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
    54
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    55
lemma num_of_nat_inverse: "0 < n \<Longrightarrow> nat_of_num (num_of_nat n) = n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    56
  by (induct n) (simp_all add: nat_of_num_inc)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    57
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    58
lemma num_eq_iff: "x = y \<longleftrightarrow> nat_of_num x = nat_of_num y"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    59
  apply safe
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    60
  apply (drule arg_cong [where f=num_of_nat])
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    61
  apply (simp add: nat_of_num_inverse)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    62
  done
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    63
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    64
lemma num_induct [case_names One inc]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    65
  fixes P :: "num \<Rightarrow> bool"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    66
  assumes One: "P One"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    67
    and inc: "\<And>x. P x \<Longrightarrow> P (inc x)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    68
  shows "P x"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    69
proof -
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    70
  obtain n where n: "Suc n = nat_of_num x"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    71
    by (cases "nat_of_num x", simp_all add: nat_of_num_neq_0)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    72
  have "P (num_of_nat (Suc n))"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    73
  proof (induct n)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    74
    case 0 show ?case using One by simp
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)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    77
    then have "P (inc (num_of_nat (Suc n)))" by (rule inc)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    78
    then show "P (num_of_nat (Suc (Suc n)))" by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    79
  qed
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    80
  with n show "P x"
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>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    85
  From now on, there are two possible models for @{typ num}:
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
    86
  as positive naturals (rule \<open>num_induct\<close>)
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
    87
  and as digit representation (rules \<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
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    93
instantiation num :: "{plus,times,linorder}"
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
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    96
definition [code del]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    97
  "m + n = num_of_nat (nat_of_num m + nat_of_num n)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    98
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
    99
definition [code del]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   100
  "m * n = num_of_nat (nat_of_num m * nat_of_num n)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   101
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   102
definition [code del]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   103
  "m \<le> n \<longleftrightarrow> nat_of_num m \<le> nat_of_num n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   104
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   105
definition [code del]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   106
  "m < n \<longleftrightarrow> nat_of_num m < nat_of_num n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   107
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   108
instance
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 60758
diff changeset
   109
  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
   110
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   111
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   112
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   113
lemma nat_of_num_add: "nat_of_num (x + y) = nat_of_num x + nat_of_num y"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   114
  unfolding plus_num_def
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   115
  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
   116
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   117
lemma nat_of_num_mult: "nat_of_num (x * y) = nat_of_num x * nat_of_num y"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   118
  unfolding times_num_def
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   119
  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
   120
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   121
lemma add_num_simps [simp, code]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   122
  "One + One = Bit0 One"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   123
  "One + Bit0 n = Bit1 n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   124
  "One + Bit1 n = Bit0 (n + One)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   125
  "Bit0 m + One = Bit1 m"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   126
  "Bit0 m + Bit0 n = Bit0 (m + n)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   127
  "Bit0 m + Bit1 n = Bit1 (m + n)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   128
  "Bit1 m + One = Bit0 (m + One)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   129
  "Bit1 m + Bit0 n = Bit1 (m + n)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   130
  "Bit1 m + Bit1 n = Bit0 (m + n + One)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   131
  by (simp_all add: num_eq_iff nat_of_num_add)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   132
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   133
lemma mult_num_simps [simp, code]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   134
  "m * One = m"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   135
  "One * n = n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   136
  "Bit0 m * Bit0 n = Bit0 (Bit0 (m * n))"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   137
  "Bit0 m * Bit1 n = Bit0 (m * Bit1 n)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   138
  "Bit1 m * Bit0 n = Bit0 (Bit1 m * n)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   139
  "Bit1 m * Bit1 n = Bit1 (m + n + Bit0 (m * n))"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   140
  by (simp_all add: num_eq_iff nat_of_num_add
49962
a8cc904a6820 Renamed {left,right}_distrib to distrib_{right,left}.
webertj
parents: 49690
diff changeset
   141
    nat_of_num_mult distrib_right distrib_left)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   142
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   143
lemma eq_num_simps:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   144
  "One = One \<longleftrightarrow> True"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   145
  "One = Bit0 n \<longleftrightarrow> False"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   146
  "One = Bit1 n \<longleftrightarrow> False"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   147
  "Bit0 m = One \<longleftrightarrow> False"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   148
  "Bit1 m = One \<longleftrightarrow> False"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   149
  "Bit0 m = Bit0 n \<longleftrightarrow> m = n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   150
  "Bit0 m = Bit1 n \<longleftrightarrow> False"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   151
  "Bit1 m = Bit0 n \<longleftrightarrow> False"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   152
  "Bit1 m = Bit1 n \<longleftrightarrow> m = n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   153
  by simp_all
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   154
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   155
lemma le_num_simps [simp, code]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   156
  "One \<le> n \<longleftrightarrow> True"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   157
  "Bit0 m \<le> One \<longleftrightarrow> False"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   158
  "Bit1 m \<le> One \<longleftrightarrow> False"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   159
  "Bit0 m \<le> Bit0 n \<longleftrightarrow> m \<le> n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   160
  "Bit0 m \<le> Bit1 n \<longleftrightarrow> m \<le> n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   161
  "Bit1 m \<le> Bit1 n \<longleftrightarrow> m \<le> n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   162
  "Bit1 m \<le> Bit0 n \<longleftrightarrow> m < n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   163
  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
   164
  by (auto simp add: less_eq_num_def less_num_def)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   165
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   166
lemma less_num_simps [simp, code]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   167
  "m < One \<longleftrightarrow> False"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   168
  "One < Bit0 n \<longleftrightarrow> True"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   169
  "One < Bit1 n \<longleftrightarrow> True"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   170
  "Bit0 m < Bit0 n \<longleftrightarrow> m < n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   171
  "Bit0 m < Bit1 n \<longleftrightarrow> m \<le> n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   172
  "Bit1 m < Bit1 n \<longleftrightarrow> m < n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   173
  "Bit1 m < Bit0 n \<longleftrightarrow> m < n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   174
  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
   175
  by (auto simp add: less_eq_num_def less_num_def)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   176
61630
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   177
lemma le_num_One_iff: "x \<le> num.One \<longleftrightarrow> x = num.One"
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   178
by (simp add: antisym_conv)
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   179
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   180
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
   181
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   182
lemma add_One: "x + One = inc x"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   183
  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
   184
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   185
lemma add_One_commute: "One + n = n + One"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   186
  by (induct n) simp_all
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   187
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   188
lemma add_inc: "x + inc y = inc (x + y)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   189
  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
   190
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   191
lemma mult_inc: "x * inc y = x * y + x"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   192
  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
   193
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   194
text \<open>The @{const num_of_nat} conversion\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   195
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   196
lemma num_of_nat_One:
47300
2284a40e0f57 remove unnecessary qualifiers on names
huffman
parents: 47299
diff changeset
   197
  "n \<le> 1 \<Longrightarrow> num_of_nat n = One"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   198
  by (cases n) simp_all
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   199
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   200
lemma num_of_nat_plus_distrib:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   201
  "0 < m \<Longrightarrow> 0 < n \<Longrightarrow> num_of_nat (m + n) = num_of_nat m + num_of_nat n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   202
  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
   203
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   204
text \<open>A double-and-decrement function\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   205
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   206
primrec BitM :: "num \<Rightarrow> num" where
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   207
  "BitM One = One" |
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   208
  "BitM (Bit0 n) = Bit1 (BitM n)" |
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   209
  "BitM (Bit1 n) = Bit1 (Bit0 n)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   210
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   211
lemma BitM_plus_one: "BitM n + One = Bit0 n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   212
  by (induct n) simp_all
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   213
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   214
lemma one_plus_BitM: "One + BitM n = Bit0 n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   215
  unfolding add_One_commute BitM_plus_one ..
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   216
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   217
text \<open>Squaring and exponentiation\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   218
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   219
primrec sqr :: "num \<Rightarrow> num" where
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   220
  "sqr One = One" |
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   221
  "sqr (Bit0 n) = Bit0 (Bit0 (sqr n))" |
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   222
  "sqr (Bit1 n) = Bit1 (Bit0 (sqr n + n))"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   223
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   224
primrec pow :: "num \<Rightarrow> num \<Rightarrow> num" where
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   225
  "pow x One = x" |
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   226
  "pow x (Bit0 y) = sqr (pow x y)" |
47191
ebd8c46d156b bootstrap Num.thy before Power.thy;
huffman
parents: 47126
diff changeset
   227
  "pow x (Bit1 y) = sqr (pow x y) * x"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   228
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   229
lemma nat_of_num_sqr: "nat_of_num (sqr x) = nat_of_num x * nat_of_num x"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   230
  by (induct x, simp_all add: algebra_simps nat_of_num_add)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   231
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   232
lemma sqr_conv_mult: "sqr x = x * x"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   233
  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
   234
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   235
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   236
subsection \<open>Binary numerals\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   237
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   238
text \<open>
47211
e1b0c8236ae4 fix search-and-replace errors
huffman
parents: 47209
diff changeset
   239
  We embed binary representations into a generic algebraic
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   240
  structure using \<open>numeral\<close>.
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   241
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   242
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   243
class numeral = one + semigroup_add
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   244
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   245
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   246
primrec numeral :: "num \<Rightarrow> 'a" where
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   247
  numeral_One: "numeral One = 1" |
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   248
  numeral_Bit0: "numeral (Bit0 n) = numeral n + numeral n" |
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   249
  numeral_Bit1: "numeral (Bit1 n) = numeral n + numeral n + 1"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   250
50817
652731d92061 sharing of recursive results on evaluation
haftmann
parents: 49962
diff changeset
   251
lemma numeral_code [code]:
652731d92061 sharing of recursive results on evaluation
haftmann
parents: 49962
diff changeset
   252
  "numeral One = 1"
652731d92061 sharing of recursive results on evaluation
haftmann
parents: 49962
diff changeset
   253
  "numeral (Bit0 n) = (let m = numeral n in m + m)"
652731d92061 sharing of recursive results on evaluation
haftmann
parents: 49962
diff changeset
   254
  "numeral (Bit1 n) = (let m = numeral n in m + m + 1)"
652731d92061 sharing of recursive results on evaluation
haftmann
parents: 49962
diff changeset
   255
  by (simp_all add: Let_def)
652731d92061 sharing of recursive results on evaluation
haftmann
parents: 49962
diff changeset
   256
  
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   257
lemma one_plus_numeral_commute: "1 + numeral x = numeral x + 1"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   258
  apply (induct x)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   259
  apply simp
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
   260
  apply (simp add: add.assoc [symmetric], simp add: add.assoc)
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
   261
  apply (simp add: add.assoc [symmetric], simp add: add.assoc)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   262
  done
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   263
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   264
lemma numeral_inc: "numeral (inc x) = numeral x + 1"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   265
proof (induct x)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   266
  case (Bit1 x)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   267
  have "numeral x + (1 + numeral x) + 1 = numeral x + (numeral x + 1) + 1"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   268
    by (simp only: one_plus_numeral_commute)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   269
  with Bit1 show ?case
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
   270
    by (simp add: add.assoc)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   271
qed simp_all
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   272
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   273
declare numeral.simps [simp del]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   274
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   275
abbreviation "Numeral1 \<equiv> numeral One"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   276
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   277
declare numeral_One [code_post]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   278
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   279
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   280
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   281
text \<open>Numeral syntax.\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   282
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   283
syntax
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   284
  "_Numeral" :: "num_const \<Rightarrow> 'a"    ("_")
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   285
58410
6d46ad54a2ab explicit separation of signed and unsigned numerals using existing lexical categories num and xnum
haftmann
parents: 58310
diff changeset
   286
ML_file "Tools/numeral.ML"
6d46ad54a2ab explicit separation of signed and unsigned numerals using existing lexical categories num and xnum
haftmann
parents: 58310
diff changeset
   287
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   288
parse_translation \<open>
52143
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   289
  let
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   290
    fun numeral_tr [(c as Const (@{syntax_const "_constrain"}, _)) $ t $ u] =
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   291
          c $ numeral_tr [t] $ u
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   292
      | numeral_tr [Const (num, _)] =
58421
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58410
diff changeset
   293
          (Numeral.mk_number_syntax o #value o Lexicon.read_num) num
52143
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   294
      | numeral_tr ts = raise TERM ("numeral_tr", ts);
55974
c835a9379026 more official const syntax: avoid educated guessing by Syntax_Phases.decode_term;
wenzelm
parents: 55534
diff changeset
   295
  in [(@{syntax_const "_Numeral"}, K numeral_tr)] end
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   296
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   297
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   298
typed_print_translation \<open>
52143
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   299
  let
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   300
    fun dest_num (Const (@{const_syntax Bit0}, _) $ n) = 2 * dest_num n
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   301
      | dest_num (Const (@{const_syntax Bit1}, _) $ n) = 2 * dest_num n + 1
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   302
      | dest_num (Const (@{const_syntax One}, _)) = 1;
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   303
    fun num_tr' ctxt T [n] =
52143
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   304
      let
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   305
        val k = dest_num n;
52187
wenzelm
parents: 52143
diff changeset
   306
        val t' =
wenzelm
parents: 52143
diff changeset
   307
          Syntax.const @{syntax_const "_Numeral"} $
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   308
            Syntax.free (string_of_int k);
52143
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   309
      in
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   310
        (case T of
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   311
          Type (@{type_name fun}, [_, T']) =>
52210
0226035df99d more explicit Printer.type_emphasis, depending on show_type_emphasis;
wenzelm
parents: 52187
diff changeset
   312
            if Printer.type_emphasis ctxt T' then
0226035df99d more explicit Printer.type_emphasis, depending on show_type_emphasis;
wenzelm
parents: 52187
diff changeset
   313
              Syntax.const @{syntax_const "_constrain"} $ t' $
0226035df99d more explicit Printer.type_emphasis, depending on show_type_emphasis;
wenzelm
parents: 52187
diff changeset
   314
                Syntax_Phases.term_of_typ ctxt T'
0226035df99d more explicit Printer.type_emphasis, depending on show_type_emphasis;
wenzelm
parents: 52187
diff changeset
   315
            else t'
52187
wenzelm
parents: 52143
diff changeset
   316
        | _ => if T = dummyT then t' else raise Match)
52143
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   317
      end;
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   318
  in
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   319
   [(@{const_syntax numeral}, num_tr')]
52143
36ffe23b25f8 syntax translations always depend on context;
wenzelm
parents: 51143
diff changeset
   320
  end
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   321
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   322
47228
4f4d85c3516f load Tools/numeral.ML in Num.thy
huffman
parents: 47227
diff changeset
   323
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   324
subsection \<open>Class-specific numeral rules\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   325
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   326
text \<open>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   327
  @{const numeral} is a morphism.
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   328
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   329
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   330
subsubsection \<open>Structures with addition: class \<open>numeral\<close>\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   331
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   332
context numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   333
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   334
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   335
lemma numeral_add: "numeral (m + n) = numeral m + numeral n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   336
  by (induct n rule: num_induct)
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
   337
     (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
   338
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   339
lemma numeral_plus_numeral: "numeral m + numeral n = numeral (m + n)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   340
  by (rule numeral_add [symmetric])
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   341
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   342
lemma numeral_plus_one: "numeral n + 1 = numeral (n + One)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   343
  using numeral_add [of n One] by (simp add: numeral_One)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   344
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   345
lemma one_plus_numeral: "1 + numeral n = numeral (One + n)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   346
  using numeral_add [of One n] by (simp add: numeral_One)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   347
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   348
lemma one_add_one: "1 + 1 = 2"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   349
  using numeral_add [of One One] by (simp add: numeral_One)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   350
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   351
lemmas add_numeral_special =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   352
  numeral_plus_one one_plus_numeral one_add_one
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   353
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   354
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   355
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   356
subsubsection \<open>
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   357
  Structures with negation: class \<open>neg_numeral\<close>
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   358
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   359
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   360
class neg_numeral = numeral + group_add
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   361
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   362
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   363
lemma uminus_numeral_One:
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   364
  "- Numeral1 = - 1"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   365
  by (simp add: numeral_One)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   366
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   367
text \<open>Numerals form an abelian subgroup.\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   368
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   369
inductive is_num :: "'a \<Rightarrow> bool" where
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   370
  "is_num 1" |
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   371
  "is_num x \<Longrightarrow> is_num (- x)" |
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   372
  "\<lbrakk>is_num x; is_num y\<rbrakk> \<Longrightarrow> is_num (x + y)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   373
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   374
lemma is_num_numeral: "is_num (numeral k)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   375
  by (induct k, simp_all add: numeral.simps is_num.intros)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   376
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   377
lemma is_num_add_commute:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   378
  "\<lbrakk>is_num x; is_num y\<rbrakk> \<Longrightarrow> x + y = y + x"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   379
  apply (induct x rule: is_num.induct)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   380
  apply (induct y rule: is_num.induct)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   381
  apply simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   382
  apply (rule_tac a=x in add_left_imp_eq)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   383
  apply (rule_tac a=x in add_right_imp_eq)
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
   384
  apply (simp add: add.assoc)
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
   385
  apply (simp add: add.assoc [symmetric], simp add: add.assoc)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   386
  apply (rule_tac a=x in add_left_imp_eq)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   387
  apply (rule_tac a=x in add_right_imp_eq)
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
   388
  apply (simp add: add.assoc)
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
   389
  apply (simp add: add.assoc, simp add: add.assoc [symmetric])
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   390
  done
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   391
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   392
lemma is_num_add_left_commute:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   393
  "\<lbrakk>is_num x; is_num y\<rbrakk> \<Longrightarrow> x + (y + z) = y + (x + z)"
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
   394
  by (simp only: add.assoc [symmetric] is_num_add_commute)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   395
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   396
lemmas is_num_normalize =
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
   397
  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
   398
  is_num.intros is_num_numeral
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 53064
diff changeset
   399
  minus_add
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   400
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   401
definition dbl :: "'a \<Rightarrow> 'a" where "dbl x = x + x"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   402
definition dbl_inc :: "'a \<Rightarrow> 'a" where "dbl_inc x = x + x + 1"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   403
definition dbl_dec :: "'a \<Rightarrow> 'a" where "dbl_dec x = x + x - 1"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   404
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   405
definition sub :: "num \<Rightarrow> num \<Rightarrow> 'a" where
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   406
  "sub k l = numeral k - numeral l"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   407
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   408
lemma numeral_BitM: "numeral (BitM n) = numeral (Bit0 n) - 1"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   409
  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
   410
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   411
lemma dbl_simps [simp]:
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   412
  "dbl (- numeral k) = - dbl (numeral k)"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   413
  "dbl 0 = 0"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   414
  "dbl 1 = 2"
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   415
  "dbl (- 1) = - 2"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   416
  "dbl (numeral k) = numeral (Bit0 k)"
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   417
  by (simp_all add: dbl_def numeral.simps minus_add)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   418
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   419
lemma dbl_inc_simps [simp]:
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   420
  "dbl_inc (- numeral k) = - dbl_dec (numeral k)"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   421
  "dbl_inc 0 = 1"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   422
  "dbl_inc 1 = 3"
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   423
  "dbl_inc (- 1) = - 1"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   424
  "dbl_inc (numeral k) = numeral (Bit1 k)"
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   425
  by (simp_all add: dbl_inc_def dbl_dec_def numeral.simps numeral_BitM is_num_normalize algebra_simps del: add_uminus_conv_diff)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   426
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   427
lemma dbl_dec_simps [simp]:
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   428
  "dbl_dec (- numeral k) = - dbl_inc (numeral k)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   429
  "dbl_dec 0 = - 1"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   430
  "dbl_dec 1 = 1"
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   431
  "dbl_dec (- 1) = - 3"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   432
  "dbl_dec (numeral k) = numeral (BitM k)"
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   433
  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
   434
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   435
lemma sub_num_simps [simp]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   436
  "sub One One = 0"
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   437
  "sub One (Bit0 l) = - numeral (BitM l)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   438
  "sub One (Bit1 l) = - numeral (Bit0 l)"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   439
  "sub (Bit0 k) One = numeral (BitM k)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   440
  "sub (Bit1 k) One = numeral (Bit0 k)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   441
  "sub (Bit0 k) (Bit0 l) = dbl (sub k l)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   442
  "sub (Bit0 k) (Bit1 l) = dbl_dec (sub k l)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   443
  "sub (Bit1 k) (Bit0 l) = dbl_inc (sub k l)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   444
  "sub (Bit1 k) (Bit1 l) = dbl (sub k l)"
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   445
  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
   446
    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
   447
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   448
lemma add_neg_numeral_simps:
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   449
  "numeral m + - numeral n = sub m n"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   450
  "- numeral m + numeral n = sub n m"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   451
  "- numeral m + - numeral n = - (numeral m + numeral n)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   452
  by (simp_all add: sub_def numeral_add numeral.simps is_num_normalize
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 53064
diff changeset
   453
    del: add_uminus_conv_diff add: diff_conv_add_uminus)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   454
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   455
lemma add_neg_numeral_special:
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   456
  "1 + - numeral m = sub One m"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   457
  "- numeral m + 1 = sub One m"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   458
  "numeral m + - 1 = sub m One"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   459
  "- 1 + numeral n = sub n One"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   460
  "- 1 + - numeral n = - numeral (inc n)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   461
  "- numeral m + - 1 = - numeral (inc m)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   462
  "1 + - 1 = 0"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   463
  "- 1 + 1 = 0"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   464
  "- 1 + - 1 = - 2"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   465
  by (simp_all add: sub_def numeral_add numeral.simps is_num_normalize right_minus numeral_inc
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   466
    del: add_uminus_conv_diff add: diff_conv_add_uminus)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   467
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   468
lemma diff_numeral_simps:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   469
  "numeral m - numeral n = sub m n"
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   470
  "numeral m - - numeral n = numeral (m + n)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   471
  "- numeral m - numeral n = - numeral (m + n)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   472
  "- numeral m - - numeral n = sub n m"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   473
  by (simp_all add: sub_def numeral_add numeral.simps is_num_normalize
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 53064
diff changeset
   474
    del: add_uminus_conv_diff add: diff_conv_add_uminus)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   475
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   476
lemma diff_numeral_special:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   477
  "1 - numeral n = sub One n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   478
  "numeral m - 1 = sub m One"
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   479
  "1 - - numeral n = numeral (One + n)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   480
  "- numeral m - 1 = - numeral (m + One)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   481
  "- 1 - numeral n = - numeral (inc n)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   482
  "numeral m - - 1 = numeral (inc m)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   483
  "- 1 - - numeral n = sub n One"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   484
  "- numeral m - - 1 = sub One m"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   485
  "1 - 1 = 0"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   486
  "- 1 - 1 = - 2"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   487
  "1 - - 1 = 2"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   488
  "- 1 - - 1 = 0"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   489
  by (simp_all add: sub_def numeral_add numeral.simps is_num_normalize numeral_inc
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   490
    del: add_uminus_conv_diff add: diff_conv_add_uminus)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   491
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   492
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   493
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   494
subsubsection \<open>
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   495
  Structures with multiplication: class \<open>semiring_numeral\<close>
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   496
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   497
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   498
class semiring_numeral = semiring + monoid_mult
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   499
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   500
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   501
subclass numeral ..
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 numeral_mult: "numeral (m * n) = numeral m * numeral n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   504
  apply (induct n rule: num_induct)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   505
  apply (simp add: numeral_One)
49962
a8cc904a6820 Renamed {left,right}_distrib to distrib_{right,left}.
webertj
parents: 49690
diff changeset
   506
  apply (simp add: mult_inc numeral_inc numeral_add distrib_left)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   507
  done
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   508
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   509
lemma numeral_times_numeral: "numeral m * numeral n = numeral (m * n)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   510
  by (rule numeral_mult [symmetric])
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   511
53064
7e3f39bc41df generalized sort constraint of lemmas
haftmann
parents: 52435
diff changeset
   512
lemma mult_2: "2 * z = z + z"
7e3f39bc41df generalized sort constraint of lemmas
haftmann
parents: 52435
diff changeset
   513
  unfolding one_add_one [symmetric] distrib_right by simp
7e3f39bc41df generalized sort constraint of lemmas
haftmann
parents: 52435
diff changeset
   514
7e3f39bc41df generalized sort constraint of lemmas
haftmann
parents: 52435
diff changeset
   515
lemma mult_2_right: "z * 2 = z + z"
7e3f39bc41df generalized sort constraint of lemmas
haftmann
parents: 52435
diff changeset
   516
  unfolding one_add_one [symmetric] distrib_left by simp
7e3f39bc41df generalized sort constraint of lemmas
haftmann
parents: 52435
diff changeset
   517
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   518
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   519
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   520
subsubsection \<open>
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   521
  Structures with a zero: class \<open>semiring_1\<close>
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   522
\<close>
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
context semiring_1
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   525
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   526
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   527
subclass semiring_numeral ..
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   528
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   529
lemma of_nat_numeral [simp]: "of_nat (numeral n) = numeral n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   530
  by (induct n,
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   531
    simp_all only: numeral.simps numeral_class.numeral.simps of_nat_add of_nat_1)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   532
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   533
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   534
51143
0a2371e7ced3 two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents: 50817
diff changeset
   535
lemma nat_of_num_numeral [code_abbrev]:
0a2371e7ced3 two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents: 50817
diff changeset
   536
  "nat_of_num = numeral"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   537
proof
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   538
  fix n
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   539
  have "numeral n = nat_of_num n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   540
    by (induct n) (simp_all add: numeral.simps)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   541
  then show "nat_of_num n = numeral n" by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   542
qed
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   543
51143
0a2371e7ced3 two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents: 50817
diff changeset
   544
lemma nat_of_num_code [code]:
0a2371e7ced3 two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents: 50817
diff changeset
   545
  "nat_of_num One = 1"
0a2371e7ced3 two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents: 50817
diff changeset
   546
  "nat_of_num (Bit0 n) = (let m = nat_of_num n in m + m)"
0a2371e7ced3 two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents: 50817
diff changeset
   547
  "nat_of_num (Bit1 n) = (let m = nat_of_num n in Suc (m + m))"
0a2371e7ced3 two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents: 50817
diff changeset
   548
  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
   549
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   550
subsubsection \<open>
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   551
  Equality: class \<open>semiring_char_0\<close>
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   552
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   553
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   554
context semiring_char_0
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   555
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   556
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   557
lemma numeral_eq_iff: "numeral m = numeral n \<longleftrightarrow> m = n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   558
  unfolding of_nat_numeral [symmetric] nat_of_num_numeral [symmetric]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   559
    of_nat_eq_iff num_eq_iff ..
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   560
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   561
lemma numeral_eq_one_iff: "numeral n = 1 \<longleftrightarrow> n = One"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   562
  by (rule numeral_eq_iff [of n One, unfolded numeral_One])
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   563
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   564
lemma one_eq_numeral_iff: "1 = numeral n \<longleftrightarrow> One = n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   565
  by (rule numeral_eq_iff [of One n, unfolded numeral_One])
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   566
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   567
lemma numeral_neq_zero: "numeral n \<noteq> 0"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   568
  unfolding of_nat_numeral [symmetric] nat_of_num_numeral [symmetric]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   569
  by (simp add: nat_of_num_pos)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   570
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   571
lemma zero_neq_numeral: "0 \<noteq> numeral n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   572
  unfolding eq_commute [of 0] by (rule numeral_neq_zero)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   573
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   574
lemmas eq_numeral_simps [simp] =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   575
  numeral_eq_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   576
  numeral_eq_one_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   577
  one_eq_numeral_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   578
  numeral_neq_zero
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   579
  zero_neq_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   580
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   581
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   582
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   583
subsubsection \<open>
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   584
  Comparisons: class \<open>linordered_semidom\<close>
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   585
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   586
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   587
text \<open>Could be perhaps more general than here.\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   588
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   589
context linordered_semidom
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   590
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   591
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   592
lemma numeral_le_iff: "numeral m \<le> numeral n \<longleftrightarrow> m \<le> n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   593
proof -
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   594
  have "of_nat (numeral m) \<le> of_nat (numeral n) \<longleftrightarrow> m \<le> n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   595
    unfolding less_eq_num_def nat_of_num_numeral of_nat_le_iff ..
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   596
  then show ?thesis by simp
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
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   599
lemma one_le_numeral: "1 \<le> numeral n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   600
using numeral_le_iff [of One n] by (simp add: numeral_One)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   601
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   602
lemma numeral_le_one_iff: "numeral n \<le> 1 \<longleftrightarrow> n \<le> One"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   603
using numeral_le_iff [of n One] by (simp add: numeral_One)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   604
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   605
lemma numeral_less_iff: "numeral m < numeral n \<longleftrightarrow> m < n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   606
proof -
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   607
  have "of_nat (numeral m) < of_nat (numeral n) \<longleftrightarrow> m < n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   608
    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
   609
  then show ?thesis by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   610
qed
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   611
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   612
lemma not_numeral_less_one: "\<not> numeral n < 1"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   613
  using numeral_less_iff [of n One] by (simp add: numeral_One)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   614
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   615
lemma one_less_numeral_iff: "1 < numeral n \<longleftrightarrow> One < n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   616
  using numeral_less_iff [of One n] by (simp add: numeral_One)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   617
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   618
lemma zero_le_numeral: "0 \<le> numeral n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   619
  by (induct n) (simp_all add: numeral.simps)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   620
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   621
lemma zero_less_numeral: "0 < numeral n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   622
  by (induct n) (simp_all add: numeral.simps add_pos_pos)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   623
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   624
lemma not_numeral_le_zero: "\<not> numeral n \<le> 0"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   625
  by (simp add: not_le zero_less_numeral)
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
lemma not_numeral_less_zero: "\<not> numeral n < 0"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   628
  by (simp add: not_less zero_le_numeral)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   629
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   630
lemmas le_numeral_extra =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   631
  zero_le_one not_one_le_zero
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   632
  order_refl [of 0] order_refl [of 1]
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
lemmas less_numeral_extra =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   635
  zero_less_one not_one_less_zero
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   636
  less_irrefl [of 0] less_irrefl [of 1]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   637
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   638
lemmas le_numeral_simps [simp] =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   639
  numeral_le_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   640
  one_le_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   641
  numeral_le_one_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   642
  zero_le_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   643
  not_numeral_le_zero
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   644
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   645
lemmas less_numeral_simps [simp] =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   646
  numeral_less_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   647
  one_less_numeral_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   648
  not_numeral_less_one
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   649
  zero_less_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   650
  not_numeral_less_zero
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   651
61630
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   652
lemma min_0_1 [simp]:
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   653
  fixes min' :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" defines "min' \<equiv> min" shows
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   654
  "min' 0 1 = 0"
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   655
  "min' 1 0 = 0"
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   656
  "min' 0 (numeral x) = 0"
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   657
  "min' (numeral x) 0 = 0"
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   658
  "min' 1 (numeral x) = 1"
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   659
  "min' (numeral x) 1 = 1"
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   660
by(simp_all add: min'_def min_def le_num_One_iff)
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   661
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   662
lemma max_0_1 [simp]: 
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   663
  fixes max' :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" defines "max' \<equiv> max" shows
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   664
  "max' 0 1 = 1"
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   665
  "max' 1 0 = 1"
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   666
  "max' 0 (numeral x) = numeral x"
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   667
  "max' (numeral x) 0 = numeral x"
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   668
  "max' 1 (numeral x) = numeral x"
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   669
  "max' (numeral x) 1 = numeral x"
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   670
by(simp_all add: max'_def max_def le_num_One_iff)
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61169
diff changeset
   671
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   672
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   673
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   674
subsubsection \<open>
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   675
  Multiplication and negation: class \<open>ring_1\<close>
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   676
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   677
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   678
context ring_1
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   679
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   680
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   681
subclass neg_numeral ..
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   682
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   683
lemma mult_neg_numeral_simps:
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   684
  "- numeral m * - numeral n = numeral (m * n)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   685
  "- numeral m * numeral n = - numeral (m * n)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   686
  "numeral m * - numeral n = - numeral (m * n)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   687
  unfolding mult_minus_left mult_minus_right
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   688
  by (simp_all only: minus_minus numeral_mult)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   689
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   690
lemma mult_minus1 [simp]: "- 1 * z = - z"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   691
  unfolding numeral.simps mult_minus_left by simp
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   692
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   693
lemma mult_minus1_right [simp]: "z * - 1 = - z"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   694
  unfolding numeral.simps mult_minus_right by simp
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   695
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   696
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   697
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   698
subsubsection \<open>
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   699
  Equality using \<open>iszero\<close> for rings with non-zero characteristic
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   700
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   701
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   702
context ring_1
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   703
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   704
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   705
definition iszero :: "'a \<Rightarrow> bool"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   706
  where "iszero z \<longleftrightarrow> z = 0"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   707
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   708
lemma iszero_0 [simp]: "iszero 0"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   709
  by (simp add: iszero_def)
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
lemma not_iszero_1 [simp]: "\<not> iszero 1"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   712
  by (simp add: iszero_def)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   713
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   714
lemma not_iszero_Numeral1: "\<not> iszero Numeral1"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   715
  by (simp add: numeral_One)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   716
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   717
lemma not_iszero_neg_1 [simp]: "\<not> iszero (- 1)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   718
  by (simp add: iszero_def)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   719
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   720
lemma not_iszero_neg_Numeral1: "\<not> iszero (- Numeral1)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   721
  by (simp add: numeral_One)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   722
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   723
lemma iszero_neg_numeral [simp]:
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   724
  "iszero (- numeral w) \<longleftrightarrow> iszero (numeral w)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   725
  unfolding iszero_def
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   726
  by (rule neg_equal_0_iff_equal)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   727
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   728
lemma eq_iff_iszero_diff: "x = y \<longleftrightarrow> iszero (x - y)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   729
  unfolding iszero_def by (rule eq_iff_diff_eq_0)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   730
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   731
text \<open>The \<open>eq_numeral_iff_iszero\<close> lemmas are not declared
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   732
\<open>[simp]\<close> by default, because for rings of characteristic zero,
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   733
better simp rules are possible. For a type like integers mod \<open>n\<close>, type-instantiated versions of these rules should be added to the
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   734
simplifier, along with a type-specific rule for deciding propositions
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   735
of the form \<open>iszero (numeral w)\<close>.
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   736
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   737
bh: Maybe it would not be so bad to just declare these as simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   738
rules anyway? I should test whether these rules take precedence over
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   739
the \<open>ring_char_0\<close> rules in the simplifier.
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   740
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   741
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   742
lemma eq_numeral_iff_iszero:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   743
  "numeral x = numeral y \<longleftrightarrow> iszero (sub x y)"
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   744
  "numeral x = - numeral y \<longleftrightarrow> iszero (numeral (x + y))"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   745
  "- numeral x = numeral y \<longleftrightarrow> iszero (numeral (x + y))"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   746
  "- numeral x = - numeral y \<longleftrightarrow> iszero (sub y x)"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   747
  "numeral x = 1 \<longleftrightarrow> iszero (sub x One)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   748
  "1 = numeral y \<longleftrightarrow> iszero (sub One y)"
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   749
  "- numeral x = 1 \<longleftrightarrow> iszero (numeral (x + One))"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   750
  "1 = - numeral y \<longleftrightarrow> iszero (numeral (One + y))"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   751
  "numeral x = 0 \<longleftrightarrow> iszero (numeral x)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   752
  "0 = numeral y \<longleftrightarrow> iszero (numeral y)"
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   753
  "- numeral x = 0 \<longleftrightarrow> iszero (numeral x)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   754
  "0 = - numeral y \<longleftrightarrow> iszero (numeral y)"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   755
  unfolding eq_iff_iszero_diff diff_numeral_simps diff_numeral_special
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   756
  by simp_all
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   757
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   758
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   759
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   760
subsubsection \<open>
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   761
  Equality and negation: class \<open>ring_char_0\<close>
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   762
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   763
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   764
class ring_char_0 = ring_1 + semiring_char_0
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   765
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   766
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   767
lemma not_iszero_numeral [simp]: "\<not> iszero (numeral w)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   768
  by (simp add: iszero_def)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   769
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   770
lemma neg_numeral_eq_iff: "- numeral m = - numeral n \<longleftrightarrow> m = n"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   771
  by simp
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   772
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   773
lemma numeral_neq_neg_numeral: "numeral m \<noteq> - numeral n"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   774
  unfolding eq_neg_iff_add_eq_0
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   775
  by (simp add: numeral_plus_numeral)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   776
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   777
lemma neg_numeral_neq_numeral: "- numeral m \<noteq> numeral n"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   778
  by (rule numeral_neq_neg_numeral [symmetric])
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   779
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   780
lemma zero_neq_neg_numeral: "0 \<noteq> - numeral n"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   781
  unfolding neg_0_equal_iff_equal by simp
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   782
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   783
lemma neg_numeral_neq_zero: "- numeral n \<noteq> 0"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   784
  unfolding neg_equal_0_iff_equal by simp
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   785
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   786
lemma one_neq_neg_numeral: "1 \<noteq> - numeral n"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   787
  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
   788
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   789
lemma neg_numeral_neq_one: "- numeral n \<noteq> 1"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   790
  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
   791
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   792
lemma neg_one_neq_numeral:
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   793
  "- 1 \<noteq> numeral n"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   794
  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
   795
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   796
lemma numeral_neq_neg_one:
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   797
  "numeral n \<noteq> - 1"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   798
  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
   799
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   800
lemma neg_one_eq_numeral_iff:
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   801
  "- 1 = - numeral n \<longleftrightarrow> n = One"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   802
  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
   803
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   804
lemma numeral_eq_neg_one_iff:
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   805
  "- numeral n = - 1 \<longleftrightarrow> n = One"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   806
  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
   807
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   808
lemma neg_one_neq_zero:
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   809
  "- 1 \<noteq> 0"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   810
  by simp
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   811
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   812
lemma zero_neq_neg_one:
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   813
  "0 \<noteq> - 1"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   814
  by simp
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   815
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   816
lemma neg_one_neq_one:
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   817
  "- 1 \<noteq> 1"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   818
  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
   819
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   820
lemma one_neq_neg_one:
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   821
  "1 \<noteq> - 1"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   822
  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
   823
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   824
lemmas eq_neg_numeral_simps [simp] =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   825
  neg_numeral_eq_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   826
  numeral_neq_neg_numeral neg_numeral_neq_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   827
  one_neq_neg_numeral neg_numeral_neq_one
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   828
  zero_neq_neg_numeral neg_numeral_neq_zero
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   829
  neg_one_neq_numeral numeral_neq_neg_one
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   830
  neg_one_eq_numeral_iff numeral_eq_neg_one_iff
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   831
  neg_one_neq_zero zero_neq_neg_one
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   832
  neg_one_neq_one one_neq_neg_one
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   833
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   834
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   835
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   836
subsubsection \<open>
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
   837
  Structures with negation and order: class \<open>linordered_idom\<close>
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   838
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   839
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   840
context linordered_idom
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   841
begin
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   842
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   843
subclass ring_char_0 ..
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   844
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   845
lemma neg_numeral_le_iff: "- numeral m \<le> - numeral n \<longleftrightarrow> n \<le> m"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   846
  by (simp only: neg_le_iff_le numeral_le_iff)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   847
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   848
lemma neg_numeral_less_iff: "- numeral m < - numeral n \<longleftrightarrow> n < m"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   849
  by (simp only: neg_less_iff_less numeral_less_iff)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   850
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   851
lemma neg_numeral_less_zero: "- numeral n < 0"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   852
  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
   853
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   854
lemma neg_numeral_le_zero: "- numeral n \<le> 0"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   855
  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
   856
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   857
lemma not_zero_less_neg_numeral: "\<not> 0 < - numeral n"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   858
  by (simp only: not_less neg_numeral_le_zero)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   859
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   860
lemma not_zero_le_neg_numeral: "\<not> 0 \<le> - numeral n"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   861
  by (simp only: not_le neg_numeral_less_zero)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   862
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   863
lemma neg_numeral_less_numeral: "- numeral m < numeral n"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   864
  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
   865
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   866
lemma neg_numeral_le_numeral: "- numeral m \<le> numeral n"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   867
  by (simp only: less_imp_le neg_numeral_less_numeral)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   868
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   869
lemma not_numeral_less_neg_numeral: "\<not> numeral m < - numeral n"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   870
  by (simp only: not_less neg_numeral_le_numeral)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   871
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   872
lemma not_numeral_le_neg_numeral: "\<not> numeral m \<le> - numeral n"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   873
  by (simp only: not_le neg_numeral_less_numeral)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   874
  
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   875
lemma neg_numeral_less_one: "- numeral m < 1"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   876
  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
   877
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   878
lemma neg_numeral_le_one: "- numeral m \<le> 1"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   879
  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
   880
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   881
lemma not_one_less_neg_numeral: "\<not> 1 < - numeral m"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   882
  by (simp only: not_less neg_numeral_le_one)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   883
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   884
lemma not_one_le_neg_numeral: "\<not> 1 \<le> - numeral m"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   885
  by (simp only: not_le neg_numeral_less_one)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   886
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   887
lemma not_numeral_less_neg_one: "\<not> numeral m < - 1"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   888
  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
   889
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   890
lemma not_numeral_le_neg_one: "\<not> numeral m \<le> - 1"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   891
  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
   892
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   893
lemma neg_one_less_numeral: "- 1 < numeral m"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   894
  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
   895
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   896
lemma neg_one_le_numeral: "- 1 \<le> numeral m"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   897
  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
   898
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   899
lemma neg_numeral_less_neg_one_iff: "- numeral m < - 1 \<longleftrightarrow> m \<noteq> One"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   900
  by (cases m) simp_all
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   901
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   902
lemma neg_numeral_le_neg_one: "- numeral m \<le> - 1"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   903
  by simp
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   904
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   905
lemma not_neg_one_less_neg_numeral: "\<not> - 1 < - numeral m"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   906
  by simp
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   907
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   908
lemma not_neg_one_le_neg_numeral_iff: "\<not> - 1 \<le> - numeral m \<longleftrightarrow> m \<noteq> One"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   909
  by (cases m) simp_all
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   910
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   911
lemma sub_non_negative:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   912
  "sub n m \<ge> 0 \<longleftrightarrow> n \<ge> m"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   913
  by (simp only: sub_def le_diff_eq) simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   914
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   915
lemma sub_positive:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   916
  "sub n m > 0 \<longleftrightarrow> n > m"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   917
  by (simp only: sub_def less_diff_eq) simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   918
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   919
lemma sub_non_positive:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   920
  "sub n m \<le> 0 \<longleftrightarrow> n \<le> m"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   921
  by (simp only: sub_def diff_le_eq) simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   922
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   923
lemma sub_negative:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   924
  "sub n m < 0 \<longleftrightarrow> n < m"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   925
  by (simp only: sub_def diff_less_eq) simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   926
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   927
lemmas le_neg_numeral_simps [simp] =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   928
  neg_numeral_le_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   929
  neg_numeral_le_numeral not_numeral_le_neg_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   930
  neg_numeral_le_zero not_zero_le_neg_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   931
  neg_numeral_le_one not_one_le_neg_numeral
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   932
  neg_one_le_numeral not_numeral_le_neg_one
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   933
  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
   934
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   935
lemma le_minus_one_simps [simp]:
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   936
  "- 1 \<le> 0"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   937
  "- 1 \<le> 1"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   938
  "\<not> 0 \<le> - 1"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   939
  "\<not> 1 \<le> - 1"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   940
  by simp_all
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   941
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   942
lemmas less_neg_numeral_simps [simp] =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   943
  neg_numeral_less_iff
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   944
  neg_numeral_less_numeral not_numeral_less_neg_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   945
  neg_numeral_less_zero not_zero_less_neg_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   946
  neg_numeral_less_one not_one_less_neg_numeral
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   947
  neg_one_less_numeral not_numeral_less_neg_one
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   948
  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
   949
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   950
lemma less_minus_one_simps [simp]:
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   951
  "- 1 < 0"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   952
  "- 1 < 1"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   953
  "\<not> 0 < - 1"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   954
  "\<not> 1 < - 1"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   955
  by (simp_all add: less_le)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   956
61944
5d06ecfdb472 prefer symbols for "abs";
wenzelm
parents: 61799
diff changeset
   957
lemma abs_numeral [simp]: "\<bar>numeral n\<bar> = numeral n"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   958
  by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   959
61944
5d06ecfdb472 prefer symbols for "abs";
wenzelm
parents: 61799
diff changeset
   960
lemma abs_neg_numeral [simp]: "\<bar>- numeral n\<bar> = numeral n"
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   961
  by (simp only: abs_minus_cancel abs_numeral)
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   962
61944
5d06ecfdb472 prefer symbols for "abs";
wenzelm
parents: 61799
diff changeset
   963
lemma abs_neg_one [simp]: "\<bar>- 1\<bar> = 1"
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
   964
  by simp
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   965
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   966
end
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   967
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   968
subsubsection \<open>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   969
  Natural numbers
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
   970
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   971
47299
e705ef5ffe95 add lemma Suc_1
huffman
parents: 47255
diff changeset
   972
lemma Suc_1 [simp]: "Suc 1 = 2"
e705ef5ffe95 add lemma Suc_1
huffman
parents: 47255
diff changeset
   973
  unfolding Suc_eq_plus1 by (rule one_add_one)
e705ef5ffe95 add lemma Suc_1
huffman
parents: 47255
diff changeset
   974
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   975
lemma Suc_numeral [simp]: "Suc (numeral n) = numeral (n + One)"
47299
e705ef5ffe95 add lemma Suc_1
huffman
parents: 47255
diff changeset
   976
  unfolding Suc_eq_plus1 by (rule numeral_plus_one)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   977
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
   978
definition pred_numeral :: "num \<Rightarrow> nat"
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
   979
  where [code del]: "pred_numeral k = numeral k - 1"
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
   980
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
   981
lemma numeral_eq_Suc: "numeral k = Suc (pred_numeral k)"
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
   982
  unfolding pred_numeral_def by simp
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
   983
47220
52426c62b5d0 replace lemmas eval_nat_numeral with a simpler reformulation
huffman
parents: 47218
diff changeset
   984
lemma eval_nat_numeral:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   985
  "numeral One = Suc 0"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   986
  "numeral (Bit0 n) = Suc (numeral (BitM n))"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   987
  "numeral (Bit1 n) = Suc (numeral (Bit0 n))"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   988
  by (simp_all add: numeral.simps BitM_plus_one)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
   989
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
   990
lemma pred_numeral_simps [simp]:
47300
2284a40e0f57 remove unnecessary qualifiers on names
huffman
parents: 47299
diff changeset
   991
  "pred_numeral One = 0"
2284a40e0f57 remove unnecessary qualifiers on names
huffman
parents: 47299
diff changeset
   992
  "pred_numeral (Bit0 k) = numeral (BitM k)"
2284a40e0f57 remove unnecessary qualifiers on names
huffman
parents: 47299
diff changeset
   993
  "pred_numeral (Bit1 k) = numeral (Bit0 k)"
47220
52426c62b5d0 replace lemmas eval_nat_numeral with a simpler reformulation
huffman
parents: 47218
diff changeset
   994
  unfolding pred_numeral_def eval_nat_numeral
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
   995
  by (simp_all only: diff_Suc_Suc diff_0)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
   996
47192
0c0501cb6da6 move many lemmas from Nat_Numeral.thy to Power.thy or Num.thy
huffman
parents: 47191
diff changeset
   997
lemma numeral_2_eq_2: "2 = Suc (Suc 0)"
47220
52426c62b5d0 replace lemmas eval_nat_numeral with a simpler reformulation
huffman
parents: 47218
diff changeset
   998
  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
   999
0c0501cb6da6 move many lemmas from Nat_Numeral.thy to Power.thy or Num.thy
huffman
parents: 47191
diff changeset
  1000
lemma numeral_3_eq_3: "3 = Suc (Suc (Suc 0))"
47220
52426c62b5d0 replace lemmas eval_nat_numeral with a simpler reformulation
huffman
parents: 47218
diff changeset
  1001
  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
  1002
47207
9368aa814518 move lemmas from Nat_Numeral to Int.thy and Num.thy
huffman
parents: 47192
diff changeset
  1003
lemma numeral_1_eq_Suc_0: "Numeral1 = Suc 0"
9368aa814518 move lemmas from Nat_Numeral to Int.thy and Num.thy
huffman
parents: 47192
diff changeset
  1004
  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
  1005
9368aa814518 move lemmas from Nat_Numeral to Int.thy and Num.thy
huffman
parents: 47192
diff changeset
  1006
lemma Suc_nat_number_of_add:
47300
2284a40e0f57 remove unnecessary qualifiers on names
huffman
parents: 47299
diff changeset
  1007
  "Suc (numeral v + n) = numeral (v + One) + n"
47207
9368aa814518 move lemmas from Nat_Numeral to Int.thy and Num.thy
huffman
parents: 47192
diff changeset
  1008
  by simp
9368aa814518 move lemmas from Nat_Numeral to Int.thy and Num.thy
huffman
parents: 47192
diff changeset
  1009
9368aa814518 move lemmas from Nat_Numeral to Int.thy and Num.thy
huffman
parents: 47192
diff changeset
  1010
(*Maps #n to n for n = 1, 2*)
9368aa814518 move lemmas from Nat_Numeral to Int.thy and Num.thy
huffman
parents: 47192
diff changeset
  1011
lemmas numerals = numeral_One [where 'a=nat] numeral_2_eq_2
9368aa814518 move lemmas from Nat_Numeral to Int.thy and Num.thy
huffman
parents: 47192
diff changeset
  1012
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1013
text \<open>Comparisons involving @{term Suc}.\<close>
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1014
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1015
lemma eq_numeral_Suc [simp]: "numeral k = Suc n \<longleftrightarrow> pred_numeral k = n"
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1016
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1017
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1018
lemma Suc_eq_numeral [simp]: "Suc n = numeral k \<longleftrightarrow> n = pred_numeral k"
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1019
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1020
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1021
lemma less_numeral_Suc [simp]: "numeral k < Suc n \<longleftrightarrow> pred_numeral k < n"
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1022
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1023
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1024
lemma less_Suc_numeral [simp]: "Suc n < numeral k \<longleftrightarrow> n < pred_numeral k"
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1025
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1026
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1027
lemma le_numeral_Suc [simp]: "numeral k \<le> Suc n \<longleftrightarrow> pred_numeral k \<le> n"
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1028
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1029
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1030
lemma le_Suc_numeral [simp]: "Suc n \<le> numeral k \<longleftrightarrow> n \<le> pred_numeral k"
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1031
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1032
47218
2b652cbadde1 new lemmas for simplifying subtraction on nat numerals
huffman
parents: 47216
diff changeset
  1033
lemma diff_Suc_numeral [simp]: "Suc n - numeral k = n - pred_numeral k"
2b652cbadde1 new lemmas for simplifying subtraction on nat numerals
huffman
parents: 47216
diff changeset
  1034
  by (simp add: numeral_eq_Suc)
2b652cbadde1 new lemmas for simplifying subtraction on nat numerals
huffman
parents: 47216
diff changeset
  1035
2b652cbadde1 new lemmas for simplifying subtraction on nat numerals
huffman
parents: 47216
diff changeset
  1036
lemma diff_numeral_Suc [simp]: "numeral k - Suc n = pred_numeral k - n"
2b652cbadde1 new lemmas for simplifying subtraction on nat numerals
huffman
parents: 47216
diff changeset
  1037
  by (simp add: numeral_eq_Suc)
2b652cbadde1 new lemmas for simplifying subtraction on nat numerals
huffman
parents: 47216
diff changeset
  1038
47209
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1039
lemma max_Suc_numeral [simp]:
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1040
  "max (Suc n) (numeral k) = Suc (max n (pred_numeral k))"
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1041
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1042
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1043
lemma max_numeral_Suc [simp]:
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1044
  "max (numeral k) (Suc n) = Suc (max (pred_numeral k) n)"
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1045
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1046
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1047
lemma min_Suc_numeral [simp]:
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1048
  "min (Suc n) (numeral k) = Suc (min n (pred_numeral k))"
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1049
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1050
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1051
lemma min_numeral_Suc [simp]:
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1052
  "min (numeral k) (Suc n) = Suc (min (pred_numeral k) n)"
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1053
  by (simp add: numeral_eq_Suc)
4893907fe872 add constant pred_numeral k = numeral k - (1::nat);
huffman
parents: 47207
diff changeset
  1054
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1055
text \<open>For @{term case_nat} and @{term rec_nat}.\<close>
47216
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1056
55415
05f5fdb8d093 renamed 'nat_{case,rec}' to '{case,rec}_nat'
blanchet
parents: 54489
diff changeset
  1057
lemma case_nat_numeral [simp]:
05f5fdb8d093 renamed 'nat_{case,rec}' to '{case,rec}_nat'
blanchet
parents: 54489
diff changeset
  1058
  "case_nat a f (numeral v) = (let pv = pred_numeral v in f pv)"
47216
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1059
  by (simp add: numeral_eq_Suc)
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1060
55415
05f5fdb8d093 renamed 'nat_{case,rec}' to '{case,rec}_nat'
blanchet
parents: 54489
diff changeset
  1061
lemma case_nat_add_eq_if [simp]:
05f5fdb8d093 renamed 'nat_{case,rec}' to '{case,rec}_nat'
blanchet
parents: 54489
diff changeset
  1062
  "case_nat a f ((numeral v) + n) = (let pv = pred_numeral v in f (pv + n))"
47216
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1063
  by (simp add: numeral_eq_Suc)
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1064
55415
05f5fdb8d093 renamed 'nat_{case,rec}' to '{case,rec}_nat'
blanchet
parents: 54489
diff changeset
  1065
lemma rec_nat_numeral [simp]:
05f5fdb8d093 renamed 'nat_{case,rec}' to '{case,rec}_nat'
blanchet
parents: 54489
diff changeset
  1066
  "rec_nat a f (numeral v) =
05f5fdb8d093 renamed 'nat_{case,rec}' to '{case,rec}_nat'
blanchet
parents: 54489
diff changeset
  1067
    (let pv = pred_numeral v in f pv (rec_nat a f pv))"
47216
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1068
  by (simp add: numeral_eq_Suc Let_def)
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1069
55415
05f5fdb8d093 renamed 'nat_{case,rec}' to '{case,rec}_nat'
blanchet
parents: 54489
diff changeset
  1070
lemma rec_nat_add_eq_if [simp]:
05f5fdb8d093 renamed 'nat_{case,rec}' to '{case,rec}_nat'
blanchet
parents: 54489
diff changeset
  1071
  "rec_nat a f (numeral v + n) =
05f5fdb8d093 renamed 'nat_{case,rec}' to '{case,rec}_nat'
blanchet
parents: 54489
diff changeset
  1072
    (let pv = pred_numeral v in f (pv + n) (rec_nat a f (pv + n)))"
47216
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1073
  by (simp add: numeral_eq_Suc Let_def)
4d0878d54ca5 move more theorems from Nat_Numeral.thy to Num.thy
huffman
parents: 47211
diff changeset
  1074
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1075
text \<open>Case analysis on @{term "n < 2"}\<close>
47255
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1076
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1077
lemma less_2_cases: "n < 2 \<Longrightarrow> n = 0 \<or> n = Suc 0"
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1078
  by (auto simp add: numeral_2_eq_2)
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1079
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1080
text \<open>Removal of Small Numerals: 0, 1 and (in additive positions) 2\<close>
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1081
text \<open>bh: Are these rules really a good idea?\<close>
47255
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1082
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1083
lemma add_2_eq_Suc [simp]: "2 + n = Suc (Suc n)"
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1084
  by simp
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1085
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1086
lemma add_2_eq_Suc' [simp]: "n + 2 = Suc (Suc n)"
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1087
  by simp
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1088
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1089
text \<open>Can be used to eliminate long strings of Sucs, but not by default.\<close>
47255
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1090
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1091
lemma Suc3_eq_add_3: "Suc (Suc (Suc n)) = 3 + n"
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1092
  by simp
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1093
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47228
diff changeset
  1094
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
  1095
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1096
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1097
subsection \<open>Particular lemmas concerning @{term 2}\<close>
58512
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1098
59867
58043346ca64 given up separate type classes demanding `inverse 0 = 0`
haftmann
parents: 59621
diff changeset
  1099
context linordered_field
58512
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1100
begin
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1101
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1102
lemma half_gt_zero_iff:
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1103
  "0 < a / 2 \<longleftrightarrow> 0 < a" (is "?P \<longleftrightarrow> ?Q")
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1104
  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
  1105
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1106
lemma half_gt_zero [simp]:
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1107
  "0 < a \<Longrightarrow> 0 < a / 2"
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1108
  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
  1109
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1110
end
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1111
dc4d76dfa8f0 moved lemmas out of Int.thy which have nothing to do with int
haftmann
parents: 58421
diff changeset
  1112
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1113
subsection \<open>Numeral equations as default simplification rules\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1114
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1115
declare (in numeral) numeral_One [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1116
declare (in numeral) numeral_plus_numeral [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1117
declare (in numeral) add_numeral_special [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1118
declare (in neg_numeral) add_neg_numeral_simps [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1119
declare (in neg_numeral) add_neg_numeral_special [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1120
declare (in neg_numeral) diff_numeral_simps [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1121
declare (in neg_numeral) diff_numeral_special [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1122
declare (in semiring_numeral) numeral_times_numeral [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1123
declare (in ring_1) mult_neg_numeral_simps [simp]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1124
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1125
subsection \<open>Setting up simprocs\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1126
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1127
lemma mult_numeral_1: "Numeral1 * a = (a::'a::semiring_numeral)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1128
  by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1129
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1130
lemma mult_numeral_1_right: "a * Numeral1 = (a::'a::semiring_numeral)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1131
  by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1132
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1133
lemma divide_numeral_1: "a / Numeral1 = (a::'a::field)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1134
  by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1135
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1136
lemma inverse_numeral_1:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1137
  "inverse Numeral1 = (Numeral1::'a::division_ring)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1138
  by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1139
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1140
text\<open>Theorem lists for the cancellation simprocs. The use of a binary
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1141
numeral for 1 reduces the number of special cases.\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1142
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1143
lemma mult_1s:
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1144
  fixes a :: "'a::semiring_numeral"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1145
    and b :: "'b::ring_1"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1146
  shows "Numeral1 * a = a"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1147
    "a * Numeral1 = a"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1148
    "- Numeral1 * b = - b"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1149
    "b * - Numeral1 = - b"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1150
  by simp_all
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1151
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1152
setup \<open>
47226
ea712316fc87 set up numeral reorient simproc in Num.thy
huffman
parents: 47220
diff changeset
  1153
  Reorient_Proc.add
ea712316fc87 set up numeral reorient simproc in Num.thy
huffman
parents: 47220
diff changeset
  1154
    (fn Const (@{const_name numeral}, _) $ _ => true
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1155
    | Const (@{const_name uminus}, _) $ (Const (@{const_name numeral}, _) $ _) => true
47226
ea712316fc87 set up numeral reorient simproc in Num.thy
huffman
parents: 47220
diff changeset
  1156
    | _ => false)
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1157
\<close>
47226
ea712316fc87 set up numeral reorient simproc in Num.thy
huffman
parents: 47220
diff changeset
  1158
ea712316fc87 set up numeral reorient simproc in Num.thy
huffman
parents: 47220
diff changeset
  1159
simproc_setup reorient_numeral
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1160
  ("numeral w = x" | "- numeral w = y") = Reorient_Proc.proc
47226
ea712316fc87 set up numeral reorient simproc in Num.thy
huffman
parents: 47220
diff changeset
  1161
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1162
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1163
subsubsection \<open>Simplification of arithmetic operations on integer constants.\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1164
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1165
lemmas arith_special = (* already declared simp above *)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1166
  add_numeral_special add_neg_numeral_special
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1167
  diff_numeral_special
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1168
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1169
(* rules already in simpset *)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1170
lemmas arith_extra_simps =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1171
  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
  1172
  minus_zero
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1173
  diff_numeral_simps diff_0 diff_0_right
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1174
  numeral_times_numeral mult_neg_numeral_simps
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1175
  mult_zero_left mult_zero_right
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1176
  abs_numeral abs_neg_numeral
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1177
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1178
text \<open>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1179
  For making a minimal simpset, one must include these default simprules.
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
  1180
  Also include \<open>simp_thms\<close>.
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1181
\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1182
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1183
lemmas arith_simps =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1184
  add_num_simps mult_num_simps sub_num_simps
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1185
  BitM.simps dbl_simps dbl_inc_simps dbl_dec_simps
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1186
  abs_zero abs_one arith_extra_simps
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1187
54249
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1188
lemmas more_arith_simps =
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1189
  neg_le_iff_le
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1190
  minus_zero left_minus right_minus
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1191
  mult_1_left mult_1_right
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1192
  mult_minus_left mult_minus_right
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
  1193
  minus_add_distrib minus_minus mult.assoc
54249
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1194
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1195
lemmas of_nat_simps =
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1196
  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
  1197
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1198
text \<open>Simplification of relational operations\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1199
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1200
lemmas eq_numeral_extra =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1201
  zero_neq_one one_neq_zero
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1202
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1203
lemmas rel_simps =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1204
  le_num_simps less_num_simps eq_num_simps
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1205
  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
  1206
  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
  1207
  eq_numeral_simps eq_neg_numeral_simps eq_numeral_extra
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1208
54249
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1209
lemma Let_numeral [simp]: "Let (numeral v) f = f (numeral v)"
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
  1210
  \<comment> \<open>Unfold all \<open>let\<close>s involving constants\<close>
54249
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1211
  unfolding Let_def ..
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1212
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1213
lemma Let_neg_numeral [simp]: "Let (- numeral v) f = f (- numeral v)"
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61630
diff changeset
  1214
  \<comment> \<open>Unfold all \<open>let\<close>s involving constants\<close>
54249
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1215
  unfolding Let_def ..
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1216
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1217
declaration \<open>
54249
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1218
let 
59996
4dca48557921 tuned signature;
wenzelm
parents: 59867
diff changeset
  1219
  fun number_of ctxt T n =
4dca48557921 tuned signature;
wenzelm
parents: 59867
diff changeset
  1220
    if not (Sign.of_sort (Proof_Context.theory_of ctxt) (T, @{sort numeral}))
54249
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1221
    then raise CTERM ("number_of", [])
59996
4dca48557921 tuned signature;
wenzelm
parents: 59867
diff changeset
  1222
    else Numeral.mk_cnumber (Thm.ctyp_of ctxt T) n;
54249
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1223
in
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1224
  K (
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1225
    Lin_Arith.add_simps (@{thms arith_simps} @ @{thms more_arith_simps}
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1226
      @ @{thms rel_simps}
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1227
      @ @{thms pred_numeral_simps}
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1228
      @ @{thms arith_special numeral_One}
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1229
      @ @{thms of_nat_simps})
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1230
    #> Lin_Arith.add_simps [@{thm Suc_numeral},
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1231
      @{thm Let_numeral}, @{thm Let_neg_numeral}, @{thm Let_0}, @{thm Let_1},
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1232
      @{thm le_Suc_numeral}, @{thm le_numeral_Suc},
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1233
      @{thm less_Suc_numeral}, @{thm less_numeral_Suc},
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1234
      @{thm Suc_eq_numeral}, @{thm eq_numeral_Suc},
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1235
      @{thm mult_Suc}, @{thm mult_Suc_right},
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1236
      @{thm of_nat_numeral}]
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1237
    #> Lin_Arith.set_number_of number_of)
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1238
end
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1239
\<close>
54249
ce00f2fef556 streamlined setup of linear arithmetic
haftmann
parents: 54230
diff changeset
  1240
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1241
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1242
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
  1243
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1244
lemma add_numeral_left [simp]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1245
  "numeral v + (numeral w + z) = (numeral(v + w) + z)"
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
  1246
  by (simp_all add: add.assoc [symmetric])
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1247
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1248
lemma add_neg_numeral_left [simp]:
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1249
  "numeral v + (- numeral w + y) = (sub v w + y)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1250
  "- numeral v + (numeral w + y) = (sub w v + y)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1251
  "- numeral v + (- numeral w + y) = (- numeral(v + w) + y)"
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
  1252
  by (simp_all add: add.assoc [symmetric])
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1253
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1254
lemma mult_numeral_left [simp]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1255
  "numeral v * (numeral w * z) = (numeral(v * w) * z :: 'a::semiring_numeral)"
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1256
  "- numeral v * (numeral w * y) = (- numeral(v * w) * y :: 'b::ring_1)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1257
  "numeral v * (- numeral w * y) = (- numeral(v * w) * y :: 'b::ring_1)"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54249
diff changeset
  1258
  "- numeral v * (- numeral w * y) = (numeral(v * w) * y :: 'b::ring_1)"
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55974
diff changeset
  1259
  by (simp_all add: mult.assoc [symmetric])
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1260
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1261
hide_const (open) One Bit0 Bit1 BitM inc pow sqr sub dbl dbl_inc dbl_dec
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1262
51143
0a2371e7ced3 two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents: 50817
diff changeset
  1263
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59996
diff changeset
  1264
subsection \<open>code module namespace\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1265
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52210
diff changeset
  1266
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
  1267
  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
  1268
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents:
diff changeset
  1269
end