src/HOL/Library/Numeral_Type.thy
author wenzelm
Sun, 11 Mar 2012 13:54:08 +0100
changeset 46868 6c250adbe101
parent 46236 ae79f2978a67
child 47108 2a1953f0d20d
permissions -rw-r--r--
eliminated old-fashioned 'constrains' element;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29629
5111ce425e7a tuned header
haftmann
parents: 29025
diff changeset
     1
(*  Title:      HOL/Library/Numeral_Type.thy
5111ce425e7a tuned header
haftmann
parents: 29025
diff changeset
     2
    Author:     Brian Huffman
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
     3
*)
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
     4
29629
5111ce425e7a tuned header
haftmann
parents: 29025
diff changeset
     5
header {* Numeral Syntax for Types *}
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
     6
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
     7
theory Numeral_Type
37653
847e95ca9b0a split off Cardinality from Numeral_Type
haftmann
parents: 36350
diff changeset
     8
imports Cardinality
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
     9
begin
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    10
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    11
subsection {* Numeral Types *}
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    12
24406
d96eb21fc1bc rename type pls to num0
huffman
parents: 24332
diff changeset
    13
typedef (open) num0 = "UNIV :: nat set" ..
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    14
typedef (open) num1 = "UNIV :: unit set" ..
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    15
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    16
typedef (open) 'a bit0 = "{0 ..< 2 * int CARD('a::finite)}"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    17
proof
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    18
  show "0 \<in> {0 ..< 2 * int CARD('a)}"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    19
    by simp
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    20
qed
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    21
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    22
typedef (open) 'a bit1 = "{0 ..< 1 + 2 * int CARD('a::finite)}"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    23
proof
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    24
  show "0 \<in> {0 ..< 1 + 2 * int CARD('a)}"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    25
    by simp
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    26
qed
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    27
30001
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    28
lemma card_num0 [simp]: "CARD (num0) = 0"
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    29
  unfolding type_definition.card [OF type_definition_num0]
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    30
  by simp
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    31
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    32
lemma card_num1 [simp]: "CARD(num1) = 1"
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    33
  unfolding type_definition.card [OF type_definition_num1]
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    34
  by (simp only: card_unit)
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    35
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    36
lemma card_bit0 [simp]: "CARD('a bit0) = 2 * CARD('a::finite)"
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    37
  unfolding type_definition.card [OF type_definition_bit0]
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    38
  by simp
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    39
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    40
lemma card_bit1 [simp]: "CARD('a bit1) = Suc (2 * CARD('a::finite))"
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    41
  unfolding type_definition.card [OF type_definition_bit1]
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    42
  by simp
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    43
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    44
instance num1 :: finite
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    45
proof
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    46
  show "finite (UNIV::num1 set)"
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    47
    unfolding type_definition.univ [OF type_definition_num1]
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    48
    using finite by (rule finite_imageI)
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    49
qed
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    50
30001
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    51
instance bit0 :: (finite) card2
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    52
proof
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    53
  show "finite (UNIV::'a bit0 set)"
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    54
    unfolding type_definition.univ [OF type_definition_bit0]
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    55
    by simp
30001
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    56
  show "2 \<le> CARD('a bit0)"
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    57
    by simp
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    58
qed
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    59
30001
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    60
instance bit1 :: (finite) card2
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    61
proof
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    62
  show "finite (UNIV::'a bit1 set)"
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    63
    unfolding type_definition.univ [OF type_definition_bit1]
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    64
    by simp
30001
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    65
  show "2 \<le> CARD('a bit1)"
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
    66
    by simp
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    67
qed
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
    68
25378
dca691610489 tuned document;
wenzelm
parents: 24630
diff changeset
    69
37653
847e95ca9b0a split off Cardinality from Numeral_Type
haftmann
parents: 36350
diff changeset
    70
subsection {* Locales for for modular arithmetic subtypes *}
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    71
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    72
locale mod_type =
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    73
  fixes n :: int
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30729
diff changeset
    74
  and Rep :: "'a::{zero,one,plus,times,uminus,minus} \<Rightarrow> int"
fec1a04b7220 power operation defined generic
haftmann
parents: 30729
diff changeset
    75
  and Abs :: "int \<Rightarrow> 'a::{zero,one,plus,times,uminus,minus}"
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    76
  assumes type: "type_definition Rep Abs {0..<n}"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    77
  and size1: "1 < n"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    78
  and zero_def: "0 = Abs 0"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    79
  and one_def:  "1 = Abs 1"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    80
  and add_def:  "x + y = Abs ((Rep x + Rep y) mod n)"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    81
  and mult_def: "x * y = Abs ((Rep x * Rep y) mod n)"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    82
  and diff_def: "x - y = Abs ((Rep x - Rep y) mod n)"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    83
  and minus_def: "- x = Abs ((- Rep x) mod n)"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    84
begin
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    85
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    86
lemma size0: "0 < n"
35362
828a42fb7445 explicit @{type_syntax} markup;
wenzelm
parents: 35115
diff changeset
    87
using size1 by simp
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    88
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    89
lemmas definitions =
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30729
diff changeset
    90
  zero_def one_def add_def mult_def minus_def diff_def
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    91
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    92
lemma Rep_less_n: "Rep x < n"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    93
by (rule type_definition.Rep [OF type, simplified, THEN conjunct2])
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    94
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    95
lemma Rep_le_n: "Rep x \<le> n"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    96
by (rule Rep_less_n [THEN order_less_imp_le])
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    97
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    98
lemma Rep_inject_sym: "x = y \<longleftrightarrow> Rep x = Rep y"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
    99
by (rule type_definition.Rep_inject [OF type, symmetric])
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   100
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   101
lemma Rep_inverse: "Abs (Rep x) = x"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   102
by (rule type_definition.Rep_inverse [OF type])
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   103
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   104
lemma Abs_inverse: "m \<in> {0..<n} \<Longrightarrow> Rep (Abs m) = m"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   105
by (rule type_definition.Abs_inverse [OF type])
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   106
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   107
lemma Rep_Abs_mod: "Rep (Abs (m mod n)) = m mod n"
33361
1f18de40b43f combined former theories Divides and IntDiv to one theory Divides
haftmann
parents: 33035
diff changeset
   108
by (simp add: Abs_inverse pos_mod_conj [OF size0])
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   109
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   110
lemma Rep_Abs_0: "Rep (Abs 0) = 0"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   111
by (simp add: Abs_inverse size0)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   112
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   113
lemma Rep_0: "Rep 0 = 0"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   114
by (simp add: zero_def Rep_Abs_0)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   115
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   116
lemma Rep_Abs_1: "Rep (Abs 1) = 1"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   117
by (simp add: Abs_inverse size1)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   118
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   119
lemma Rep_1: "Rep 1 = 1"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   120
by (simp add: one_def Rep_Abs_1)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   121
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   122
lemma Rep_mod: "Rep x mod n = Rep x"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   123
apply (rule_tac x=x in type_definition.Abs_cases [OF type])
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   124
apply (simp add: type_definition.Abs_inverse [OF type])
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   125
apply (simp add: mod_pos_pos_trivial)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   126
done
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   127
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   128
lemmas Rep_simps =
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   129
  Rep_inject_sym Rep_inverse Rep_Abs_mod Rep_mod Rep_Abs_0 Rep_Abs_1
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   130
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   131
lemma comm_ring_1: "OFCLASS('a, comm_ring_1_class)"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   132
apply (intro_classes, unfold definitions)
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 35431
diff changeset
   133
apply (simp_all add: Rep_simps zmod_simps field_simps)
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   134
done
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   135
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   136
end
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   137
46868
6c250adbe101 eliminated old-fashioned 'constrains' element;
wenzelm
parents: 46236
diff changeset
   138
locale mod_ring = mod_type n Rep Abs
6c250adbe101 eliminated old-fashioned 'constrains' element;
wenzelm
parents: 46236
diff changeset
   139
  for n :: int
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30729
diff changeset
   140
  and Rep :: "'a::{number_ring} \<Rightarrow> int"
fec1a04b7220 power operation defined generic
haftmann
parents: 30729
diff changeset
   141
  and Abs :: "int \<Rightarrow> 'a::{number_ring}"
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   142
begin
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   143
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   144
lemma of_nat_eq: "of_nat k = Abs (int k mod n)"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   145
apply (induct k)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   146
apply (simp add: zero_def)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   147
apply (simp add: Rep_simps add_def one_def zmod_simps add_ac)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   148
done
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   149
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   150
lemma of_int_eq: "of_int z = Abs (z mod n)"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   151
apply (cases z rule: int_diff_cases)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   152
apply (simp add: Rep_simps of_nat_eq diff_def zmod_simps)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   153
done
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   154
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   155
lemma Rep_number_of:
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   156
  "Rep (number_of w) = number_of w mod n"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   157
by (simp add: number_of_eq of_int_eq Rep_Abs_mod)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   158
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   159
lemma iszero_number_of:
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   160
  "iszero (number_of w::'a) \<longleftrightarrow> number_of w mod n = 0"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   161
by (simp add: Rep_simps number_of_eq of_int_eq iszero_def zero_def)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   162
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   163
lemma cases:
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   164
  assumes 1: "\<And>z. \<lbrakk>(x::'a) = of_int z; 0 \<le> z; z < n\<rbrakk> \<Longrightarrow> P"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   165
  shows "P"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   166
apply (cases x rule: type_definition.Abs_cases [OF type])
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   167
apply (rule_tac z="y" in 1)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   168
apply (simp_all add: of_int_eq mod_pos_pos_trivial)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   169
done
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   170
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   171
lemma induct:
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   172
  "(\<And>z. \<lbrakk>0 \<le> z; z < n\<rbrakk> \<Longrightarrow> P (of_int z)) \<Longrightarrow> P (x::'a)"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   173
by (cases x rule: cases) simp
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   174
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   175
end
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   176
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   177
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   178
subsection {* Number ring instances *}
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   179
30032
c7f0c1b8001b class instances for num1
huffman
parents: 30001
diff changeset
   180
text {*
c7f0c1b8001b class instances for num1
huffman
parents: 30001
diff changeset
   181
  Unfortunately a number ring instance is not possible for
c7f0c1b8001b class instances for num1
huffman
parents: 30001
diff changeset
   182
  @{typ num1}, since 0 and 1 are not distinct.
c7f0c1b8001b class instances for num1
huffman
parents: 30001
diff changeset
   183
*}
c7f0c1b8001b class instances for num1
huffman
parents: 30001
diff changeset
   184
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30729
diff changeset
   185
instantiation num1 :: "{comm_ring,comm_monoid_mult,number}"
30032
c7f0c1b8001b class instances for num1
huffman
parents: 30001
diff changeset
   186
begin
c7f0c1b8001b class instances for num1
huffman
parents: 30001
diff changeset
   187
c7f0c1b8001b class instances for num1
huffman
parents: 30001
diff changeset
   188
lemma num1_eq_iff: "(x::num1) = (y::num1) \<longleftrightarrow> True"
c7f0c1b8001b class instances for num1
huffman
parents: 30001
diff changeset
   189
  by (induct x, induct y) simp
c7f0c1b8001b class instances for num1
huffman
parents: 30001
diff changeset
   190
c7f0c1b8001b class instances for num1
huffman
parents: 30001
diff changeset
   191
instance proof
c7f0c1b8001b class instances for num1
huffman
parents: 30001
diff changeset
   192
qed (simp_all add: num1_eq_iff)
c7f0c1b8001b class instances for num1
huffman
parents: 30001
diff changeset
   193
c7f0c1b8001b class instances for num1
huffman
parents: 30001
diff changeset
   194
end
c7f0c1b8001b class instances for num1
huffman
parents: 30001
diff changeset
   195
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   196
instantiation
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30729
diff changeset
   197
  bit0 and bit1 :: (finite) "{zero,one,plus,times,uminus,minus}"
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   198
begin
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   199
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   200
definition Abs_bit0' :: "int \<Rightarrow> 'a bit0" where
29998
19e1ef628b25 nicer induction/cases rules for numeral types
huffman
parents: 29997
diff changeset
   201
  "Abs_bit0' x = Abs_bit0 (x mod int CARD('a bit0))"
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   202
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   203
definition Abs_bit1' :: "int \<Rightarrow> 'a bit1" where
29998
19e1ef628b25 nicer induction/cases rules for numeral types
huffman
parents: 29997
diff changeset
   204
  "Abs_bit1' x = Abs_bit1 (x mod int CARD('a bit1))"
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   205
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   206
definition "0 = Abs_bit0 0"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   207
definition "1 = Abs_bit0 1"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   208
definition "x + y = Abs_bit0' (Rep_bit0 x + Rep_bit0 y)"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   209
definition "x * y = Abs_bit0' (Rep_bit0 x * Rep_bit0 y)"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   210
definition "x - y = Abs_bit0' (Rep_bit0 x - Rep_bit0 y)"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   211
definition "- x = Abs_bit0' (- Rep_bit0 x)"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   212
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   213
definition "0 = Abs_bit1 0"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   214
definition "1 = Abs_bit1 1"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   215
definition "x + y = Abs_bit1' (Rep_bit1 x + Rep_bit1 y)"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   216
definition "x * y = Abs_bit1' (Rep_bit1 x * Rep_bit1 y)"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   217
definition "x - y = Abs_bit1' (Rep_bit1 x - Rep_bit1 y)"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   218
definition "- x = Abs_bit1' (- Rep_bit1 x)"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   219
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   220
instance ..
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   221
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   222
end
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   223
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 30663
diff changeset
   224
interpretation bit0:
29998
19e1ef628b25 nicer induction/cases rules for numeral types
huffman
parents: 29997
diff changeset
   225
  mod_type "int CARD('a::finite bit0)"
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   226
           "Rep_bit0 :: 'a::finite bit0 \<Rightarrow> int"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   227
           "Abs_bit0 :: int \<Rightarrow> 'a::finite bit0"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   228
apply (rule mod_type.intro)
29998
19e1ef628b25 nicer induction/cases rules for numeral types
huffman
parents: 29997
diff changeset
   229
apply (simp add: int_mult type_definition_bit0)
30001
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
   230
apply (rule one_less_int_card)
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   231
apply (rule zero_bit0_def)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   232
apply (rule one_bit0_def)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   233
apply (rule plus_bit0_def [unfolded Abs_bit0'_def])
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   234
apply (rule times_bit0_def [unfolded Abs_bit0'_def])
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   235
apply (rule minus_bit0_def [unfolded Abs_bit0'_def])
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   236
apply (rule uminus_bit0_def [unfolded Abs_bit0'_def])
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   237
done
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   238
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 30663
diff changeset
   239
interpretation bit1:
29998
19e1ef628b25 nicer induction/cases rules for numeral types
huffman
parents: 29997
diff changeset
   240
  mod_type "int CARD('a::finite bit1)"
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   241
           "Rep_bit1 :: 'a::finite bit1 \<Rightarrow> int"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   242
           "Abs_bit1 :: int \<Rightarrow> 'a::finite bit1"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   243
apply (rule mod_type.intro)
29998
19e1ef628b25 nicer induction/cases rules for numeral types
huffman
parents: 29997
diff changeset
   244
apply (simp add: int_mult type_definition_bit1)
30001
dd27e16677b2 cleaned up
huffman
parents: 29999
diff changeset
   245
apply (rule one_less_int_card)
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   246
apply (rule zero_bit1_def)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   247
apply (rule one_bit1_def)
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   248
apply (rule plus_bit1_def [unfolded Abs_bit1'_def])
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   249
apply (rule times_bit1_def [unfolded Abs_bit1'_def])
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   250
apply (rule minus_bit1_def [unfolded Abs_bit1'_def])
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   251
apply (rule uminus_bit1_def [unfolded Abs_bit1'_def])
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   252
done
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   253
31021
53642251a04f farewell to class recpower
haftmann
parents: 30960
diff changeset
   254
instance bit0 :: (finite) comm_ring_1
53642251a04f farewell to class recpower
haftmann
parents: 30960
diff changeset
   255
  by (rule bit0.comm_ring_1)+
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   256
31021
53642251a04f farewell to class recpower
haftmann
parents: 30960
diff changeset
   257
instance bit1 :: (finite) comm_ring_1
53642251a04f farewell to class recpower
haftmann
parents: 30960
diff changeset
   258
  by (rule bit1.comm_ring_1)+
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   259
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   260
instantiation bit0 and bit1 :: (finite) number_ring
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   261
begin
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   262
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   263
definition "(number_of w :: _ bit0) = of_int w"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   264
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   265
definition "(number_of w :: _ bit1) = of_int w"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   266
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   267
instance proof
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   268
qed (rule number_of_bit0_def number_of_bit1_def)+
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   269
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   270
end
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   271
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 30663
diff changeset
   272
interpretation bit0:
29998
19e1ef628b25 nicer induction/cases rules for numeral types
huffman
parents: 29997
diff changeset
   273
  mod_ring "int CARD('a::finite bit0)"
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   274
           "Rep_bit0 :: 'a::finite bit0 \<Rightarrow> int"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   275
           "Abs_bit0 :: int \<Rightarrow> 'a::finite bit0"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   276
  ..
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   277
30729
461ee3e49ad3 interpretation/interpret: prefixes are mandatory by default;
wenzelm
parents: 30663
diff changeset
   278
interpretation bit1:
29998
19e1ef628b25 nicer induction/cases rules for numeral types
huffman
parents: 29997
diff changeset
   279
  mod_ring "int CARD('a::finite bit1)"
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   280
           "Rep_bit1 :: 'a::finite bit1 \<Rightarrow> int"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   281
           "Abs_bit1 :: int \<Rightarrow> 'a::finite bit1"
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   282
  ..
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   283
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   284
text {* Set up cases, induction, and arithmetic *}
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   285
29999
da85a244e328 fix case_names
huffman
parents: 29998
diff changeset
   286
lemmas bit0_cases [case_names of_int, cases type: bit0] = bit0.cases
da85a244e328 fix case_names
huffman
parents: 29998
diff changeset
   287
lemmas bit1_cases [case_names of_int, cases type: bit1] = bit1.cases
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   288
29999
da85a244e328 fix case_names
huffman
parents: 29998
diff changeset
   289
lemmas bit0_induct [case_names of_int, induct type: bit0] = bit0.induct
da85a244e328 fix case_names
huffman
parents: 29998
diff changeset
   290
lemmas bit1_induct [case_names of_int, induct type: bit1] = bit1.induct
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   291
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   292
lemmas bit0_iszero_number_of [simp] = bit0.iszero_number_of
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   293
lemmas bit1_iszero_number_of [simp] = bit1.iszero_number_of
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   294
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   295
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   296
subsection {* Syntax *}
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   297
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   298
syntax
46236
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   299
  "_NumeralType" :: "num_token => type"  ("_")
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   300
  "_NumeralType0" :: type ("0")
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   301
  "_NumeralType1" :: type ("1")
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   302
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   303
translations
35362
828a42fb7445 explicit @{type_syntax} markup;
wenzelm
parents: 35115
diff changeset
   304
  (type) "1" == (type) "num1"
828a42fb7445 explicit @{type_syntax} markup;
wenzelm
parents: 35115
diff changeset
   305
  (type) "0" == (type) "num0"
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   306
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   307
parse_translation {*
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   308
let
46236
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   309
  fun mk_bintype n =
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   310
    let
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   311
      fun mk_bit 0 = Syntax.const @{type_syntax bit0}
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   312
        | mk_bit 1 = Syntax.const @{type_syntax bit1};
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   313
      fun bin_of n =
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   314
        if n = 1 then Syntax.const @{type_syntax num1}
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   315
        else if n = 0 then Syntax.const @{type_syntax num0}
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   316
        else if n = ~1 then raise TERM ("negative type numeral", [])
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   317
        else
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   318
          let val (q, r) = Integer.div_mod n 2;
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   319
          in mk_bit r $ bin_of q end;
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   320
    in bin_of n end;
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   321
46236
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   322
  fun numeral_tr [Free (str, _)] = mk_bintype (the (Int.fromString str))
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   323
    | numeral_tr ts = raise TERM ("numeral_tr", ts);
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   324
35115
446c5063e4fd modernized translations;
wenzelm
parents: 33361
diff changeset
   325
in [(@{syntax_const "_NumeralType"}, numeral_tr)] end;
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   326
*}
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   327
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   328
print_translation {*
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   329
let
46236
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   330
  fun int_of [] = 0
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   331
    | int_of (b :: bs) = b + 2 * int_of bs;
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   332
46236
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   333
  fun bin_of (Const (@{type_syntax num0}, _)) = []
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   334
    | bin_of (Const (@{type_syntax num1}, _)) = [1]
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   335
    | bin_of (Const (@{type_syntax bit0}, _) $ bs) = 0 :: bin_of bs
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   336
    | bin_of (Const (@{type_syntax bit1}, _) $ bs) = 1 :: bin_of bs
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   337
    | bin_of t = raise TERM ("bin_of", [t]);
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   338
46236
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   339
  fun bit_tr' b [t] =
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   340
        let
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   341
          val rev_digs = b :: bin_of t handle TERM _ => raise Match
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   342
          val i = int_of rev_digs;
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   343
          val num = string_of_int (abs i);
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   344
        in
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   345
          Syntax.const @{syntax_const "_NumeralType"} $ Syntax.free num
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   346
        end
ae79f2978a67 position constraints for numerals enable PIDE markup;
wenzelm
parents: 37653
diff changeset
   347
    | bit_tr' b _ = raise Match;
35362
828a42fb7445 explicit @{type_syntax} markup;
wenzelm
parents: 35115
diff changeset
   348
in [(@{type_syntax bit0}, bit_tr' 0), (@{type_syntax bit1}, bit_tr' 1)] end;
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   349
*}
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   350
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   351
subsection {* Examples *}
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   352
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   353
lemma "CARD(0) = 0" by simp
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   354
lemma "CARD(17) = 17" by simp
29997
f6756c097c2d number_ring instances for numeral types
huffman
parents: 29629
diff changeset
   355
lemma "8 * 11 ^ 3 - 6 = (2::5)" by simp
28920
4ed4b8b1988d fix typed print translation for card UNIV
huffman
parents: 27487
diff changeset
   356
24332
e3a2b75b1cf9 boolean algebras as locales and numbers as types by Brian Huffman
kleing
parents:
diff changeset
   357
end