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