src/HOL/Library/Code_Target_Int.thy
author haftmann
Thu, 26 Jun 2025 17:25:29 +0200
changeset 82773 4ec8e654112f
parent 81113 6fefd6c602fa
permissions -rw-r--r--
scope pending code equations to theories
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
     1
(*  Title:      HOL/Library/Code_Target_Int.thy
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
     2
    Author:     Florian Haftmann, TU Muenchen
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
     3
*)
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
     4
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 58881
diff changeset
     5
section \<open>Implementation of integer numbers by target-language integers\<close>
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
     6
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
     7
theory Code_Target_Int
65552
f533820e7248 theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
wenzelm
parents: 64997
diff changeset
     8
imports Main
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
     9
begin
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    10
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    11
code_datatype int_of_integer
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    12
55736
f1ed1e9cd080 unregister lifting setup following the best practice of Lifting
kuncar
parents: 54891
diff changeset
    13
context
f1ed1e9cd080 unregister lifting setup following the best practice of Lifting
kuncar
parents: 54891
diff changeset
    14
includes integer.lifting
f1ed1e9cd080 unregister lifting setup following the best practice of Lifting
kuncar
parents: 54891
diff changeset
    15
begin
f1ed1e9cd080 unregister lifting setup following the best practice of Lifting
kuncar
parents: 54891
diff changeset
    16
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    17
lemma [code]:
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    18
  "integer_of_int (int_of_integer k) = k"
51114
3e913a575dc6 type lifting setup for code numeral types
haftmann
parents: 51095
diff changeset
    19
  by transfer rule
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    20
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    21
lemma [code]:
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    22
  "Int.Pos = int_of_integer \<circ> integer_of_num"
65552
f533820e7248 theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
wenzelm
parents: 64997
diff changeset
    23
  by transfer (simp add: fun_eq_iff)
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    24
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    25
lemma [code]:
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    26
  "Int.Neg = int_of_integer \<circ> uminus \<circ> integer_of_num"
65552
f533820e7248 theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
wenzelm
parents: 64997
diff changeset
    27
  by transfer (simp add: fun_eq_iff)
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    28
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    29
lemma [code_abbrev]:
51095
7ae79f2e3cc7 explicit conversion integer_of_nat already in Code_Numeral_Types;
haftmann
parents: 50023
diff changeset
    30
  "int_of_integer (numeral k) = Int.Pos k"
51114
3e913a575dc6 type lifting setup for code numeral types
haftmann
parents: 51095
diff changeset
    31
  by transfer simp
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    32
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    33
lemma [code_abbrev]:
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54227
diff changeset
    34
  "int_of_integer (- numeral k) = Int.Neg k"
51114
3e913a575dc6 type lifting setup for code numeral types
haftmann
parents: 51095
diff changeset
    35
  by transfer simp
64997
067a6cca39f0 dedicated computation preprocessing rules for nat, int implemented by target language literals
haftmann
parents: 64242
diff changeset
    36
067a6cca39f0 dedicated computation preprocessing rules for nat, int implemented by target language literals
haftmann
parents: 64242
diff changeset
    37
context
65552
f533820e7248 theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
wenzelm
parents: 64997
diff changeset
    38
begin
64997
067a6cca39f0 dedicated computation preprocessing rules for nat, int implemented by target language literals
haftmann
parents: 64242
diff changeset
    39
067a6cca39f0 dedicated computation preprocessing rules for nat, int implemented by target language literals
haftmann
parents: 64242
diff changeset
    40
qualified definition positive :: "num \<Rightarrow> int"
067a6cca39f0 dedicated computation preprocessing rules for nat, int implemented by target language literals
haftmann
parents: 64242
diff changeset
    41
  where [simp]: "positive = numeral"
067a6cca39f0 dedicated computation preprocessing rules for nat, int implemented by target language literals
haftmann
parents: 64242
diff changeset
    42
067a6cca39f0 dedicated computation preprocessing rules for nat, int implemented by target language literals
haftmann
parents: 64242
diff changeset
    43
qualified definition negative :: "num \<Rightarrow> int"
067a6cca39f0 dedicated computation preprocessing rules for nat, int implemented by target language literals
haftmann
parents: 64242
diff changeset
    44
  where [simp]: "negative = uminus \<circ> numeral"
067a6cca39f0 dedicated computation preprocessing rules for nat, int implemented by target language literals
haftmann
parents: 64242
diff changeset
    45
067a6cca39f0 dedicated computation preprocessing rules for nat, int implemented by target language literals
haftmann
parents: 64242
diff changeset
    46
lemma [code_computation_unfold]:
067a6cca39f0 dedicated computation preprocessing rules for nat, int implemented by target language literals
haftmann
parents: 64242
diff changeset
    47
  "numeral = positive"
067a6cca39f0 dedicated computation preprocessing rules for nat, int implemented by target language literals
haftmann
parents: 64242
diff changeset
    48
  "Int.Pos = positive"
067a6cca39f0 dedicated computation preprocessing rules for nat, int implemented by target language literals
haftmann
parents: 64242
diff changeset
    49
  "Int.Neg = negative"
067a6cca39f0 dedicated computation preprocessing rules for nat, int implemented by target language literals
haftmann
parents: 64242
diff changeset
    50
  by (simp_all add: fun_eq_iff)
067a6cca39f0 dedicated computation preprocessing rules for nat, int implemented by target language literals
haftmann
parents: 64242
diff changeset
    51
067a6cca39f0 dedicated computation preprocessing rules for nat, int implemented by target language literals
haftmann
parents: 64242
diff changeset
    52
end
067a6cca39f0 dedicated computation preprocessing rules for nat, int implemented by target language literals
haftmann
parents: 64242
diff changeset
    53
51095
7ae79f2e3cc7 explicit conversion integer_of_nat already in Code_Numeral_Types;
haftmann
parents: 50023
diff changeset
    54
lemma [code, symmetric, code_post]:
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    55
  "0 = int_of_integer 0"
51114
3e913a575dc6 type lifting setup for code numeral types
haftmann
parents: 51095
diff changeset
    56
  by transfer simp
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    57
51095
7ae79f2e3cc7 explicit conversion integer_of_nat already in Code_Numeral_Types;
haftmann
parents: 50023
diff changeset
    58
lemma [code, symmetric, code_post]:
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    59
  "1 = int_of_integer 1"
51114
3e913a575dc6 type lifting setup for code numeral types
haftmann
parents: 51095
diff changeset
    60
  by transfer simp
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    61
58099
7f232ae7de7c convenient printing of (- 1 :: integer) after code evaluation
haftmann
parents: 57512
diff changeset
    62
lemma [code_post]:
7f232ae7de7c convenient printing of (- 1 :: integer) after code evaluation
haftmann
parents: 57512
diff changeset
    63
  "int_of_integer (- 1) = - 1"
7f232ae7de7c convenient printing of (- 1 :: integer) after code evaluation
haftmann
parents: 57512
diff changeset
    64
  by simp
7f232ae7de7c convenient printing of (- 1 :: integer) after code evaluation
haftmann
parents: 57512
diff changeset
    65
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    66
lemma [code]:
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    67
  "k + l = int_of_integer (of_int k + of_int l)"
51114
3e913a575dc6 type lifting setup for code numeral types
haftmann
parents: 51095
diff changeset
    68
  by transfer simp
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    69
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    70
lemma [code]:
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    71
  "- k = int_of_integer (- of_int k)"
51114
3e913a575dc6 type lifting setup for code numeral types
haftmann
parents: 51095
diff changeset
    72
  by transfer simp
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    73
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    74
lemma [code]:
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    75
  "k - l = int_of_integer (of_int k - of_int l)"
51114
3e913a575dc6 type lifting setup for code numeral types
haftmann
parents: 51095
diff changeset
    76
  by transfer simp
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    77
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    78
lemma [code]:
51143
0a2371e7ced3 two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents: 51114
diff changeset
    79
  "Int.dup k = int_of_integer (Code_Numeral.dup (of_int k))"
51114
3e913a575dc6 type lifting setup for code numeral types
haftmann
parents: 51095
diff changeset
    80
  by transfer simp
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    81
54891
2f4491f15fe6 examples how to avoid the "code, code del" antipattern
haftmann
parents: 54796
diff changeset
    82
declare [[code drop: Int.sub]]
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    83
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    84
lemma [code]:
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    85
  "k * l = int_of_integer (of_int k * of_int l)"
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    86
  by simp
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    87
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    88
lemma [code]:
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    89
  "k div l = int_of_integer (of_int k div of_int l)"
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    90
  by simp
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    91
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    92
lemma [code]:
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    93
  "k mod l = int_of_integer (of_int k mod of_int l)"
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    94
  by simp
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    95
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
    96
lemma [code]:
61275
053ec04ea866 monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
haftmann
parents: 60868
diff changeset
    97
  "divmod m n = map_prod int_of_integer int_of_integer (divmod m n)"
053ec04ea866 monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
haftmann
parents: 60868
diff changeset
    98
  unfolding prod_eq_iff divmod_def map_prod_def case_prod_beta fst_conv snd_conv
053ec04ea866 monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
haftmann
parents: 60868
diff changeset
    99
  by transfer simp
053ec04ea866 monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
haftmann
parents: 60868
diff changeset
   100
053ec04ea866 monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
haftmann
parents: 60868
diff changeset
   101
lemma [code]:
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   102
  "HOL.equal k l = HOL.equal (of_int k :: integer) (of_int l)"
51114
3e913a575dc6 type lifting setup for code numeral types
haftmann
parents: 51095
diff changeset
   103
  by transfer (simp add: equal)
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   104
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   105
lemma [code]:
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   106
  "k \<le> l \<longleftrightarrow> (of_int k :: integer) \<le> of_int l"
51114
3e913a575dc6 type lifting setup for code numeral types
haftmann
parents: 51095
diff changeset
   107
  by transfer rule
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   108
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   109
lemma [code]:
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   110
  "k < l \<longleftrightarrow> (of_int k :: integer) < of_int l"
51114
3e913a575dc6 type lifting setup for code numeral types
haftmann
parents: 51095
diff changeset
   111
  by transfer rule
61856
4b1b85f38944 add gcd instance for integer and serialisation to target language operations
Andreas Lochbihler
parents: 61275
diff changeset
   112
4b1b85f38944 add gcd instance for integer and serialisation to target language operations
Andreas Lochbihler
parents: 61275
diff changeset
   113
lemma gcd_int_of_integer [code]:
4b1b85f38944 add gcd instance for integer and serialisation to target language operations
Andreas Lochbihler
parents: 61275
diff changeset
   114
  "gcd (int_of_integer x) (int_of_integer y) = int_of_integer (gcd x y)"
75651
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   115
  by transfer rule
61856
4b1b85f38944 add gcd instance for integer and serialisation to target language operations
Andreas Lochbihler
parents: 61275
diff changeset
   116
4b1b85f38944 add gcd instance for integer and serialisation to target language operations
Andreas Lochbihler
parents: 61275
diff changeset
   117
lemma lcm_int_of_integer [code]:
4b1b85f38944 add gcd instance for integer and serialisation to target language operations
Andreas Lochbihler
parents: 61275
diff changeset
   118
  "lcm (int_of_integer x) (int_of_integer y) = int_of_integer (lcm x y)"
75651
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   119
  by transfer rule
61856
4b1b85f38944 add gcd instance for integer and serialisation to target language operations
Andreas Lochbihler
parents: 61275
diff changeset
   120
55736
f1ed1e9cd080 unregister lifting setup following the best practice of Lifting
kuncar
parents: 54891
diff changeset
   121
end
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   122
54796
cdc6d8cbf770 avoid clashes of fact names
haftmann
parents: 54489
diff changeset
   123
lemma (in ring_1) of_int_code_if:
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   124
  "of_int k = (if k = 0 then 0
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   125
     else if k < 0 then - of_int (- k)
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   126
     else let
60868
dd18c33c001e direct bootstrap of integer division from natural division
haftmann
parents: 60500
diff changeset
   127
       l = 2 * of_int (k div 2);
dd18c33c001e direct bootstrap of integer division from natural division
haftmann
parents: 60500
diff changeset
   128
       j = k mod 2
dd18c33c001e direct bootstrap of integer division from natural division
haftmann
parents: 60500
diff changeset
   129
     in if j = 0 then l else l + 1)"
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   130
proof -
64242
93c6f0da5c70 more standardized theorem names for facts involving the div and mod identity
haftmann
parents: 63351
diff changeset
   131
  from div_mult_mod_eq have *: "of_int k = of_int (k div 2 * 2 + k mod 2)" by simp
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   132
  show ?thesis
60868
dd18c33c001e direct bootstrap of integer division from natural division
haftmann
parents: 60500
diff changeset
   133
    by (simp add: Let_def of_int_add [symmetric]) (simp add: * mult.commute)
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   134
qed
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   135
54796
cdc6d8cbf770 avoid clashes of fact names
haftmann
parents: 54489
diff changeset
   136
declare of_int_code_if [code]
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   137
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   138
lemma [code]:
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   139
  "nat = nat_of_integer \<circ> of_int"
55736
f1ed1e9cd080 unregister lifting setup following the best practice of Lifting
kuncar
parents: 54891
diff changeset
   140
  including integer.lifting by transfer (simp add: fun_eq_iff)
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   141
68028
1f9f973eed2a proper datatype for 8-bit characters
haftmann
parents: 65552
diff changeset
   142
definition char_of_int :: "int \<Rightarrow> char"
1f9f973eed2a proper datatype for 8-bit characters
haftmann
parents: 65552
diff changeset
   143
  where [code_abbrev]: "char_of_int = char_of"
1f9f973eed2a proper datatype for 8-bit characters
haftmann
parents: 65552
diff changeset
   144
1f9f973eed2a proper datatype for 8-bit characters
haftmann
parents: 65552
diff changeset
   145
definition int_of_char :: "char \<Rightarrow> int"
1f9f973eed2a proper datatype for 8-bit characters
haftmann
parents: 65552
diff changeset
   146
  where [code_abbrev]: "int_of_char = of_char"
1f9f973eed2a proper datatype for 8-bit characters
haftmann
parents: 65552
diff changeset
   147
1f9f973eed2a proper datatype for 8-bit characters
haftmann
parents: 65552
diff changeset
   148
lemma [code]:
1f9f973eed2a proper datatype for 8-bit characters
haftmann
parents: 65552
diff changeset
   149
  "char_of_int = char_of_integer \<circ> integer_of_int"
1f9f973eed2a proper datatype for 8-bit characters
haftmann
parents: 65552
diff changeset
   150
  including integer.lifting unfolding char_of_integer_def char_of_int_def
1f9f973eed2a proper datatype for 8-bit characters
haftmann
parents: 65552
diff changeset
   151
  by transfer (simp add: fun_eq_iff)
1f9f973eed2a proper datatype for 8-bit characters
haftmann
parents: 65552
diff changeset
   152
1f9f973eed2a proper datatype for 8-bit characters
haftmann
parents: 65552
diff changeset
   153
lemma [code]:
1f9f973eed2a proper datatype for 8-bit characters
haftmann
parents: 65552
diff changeset
   154
  "int_of_char = int_of_integer \<circ> integer_of_char"
1f9f973eed2a proper datatype for 8-bit characters
haftmann
parents: 65552
diff changeset
   155
  including integer.lifting unfolding integer_of_char_def int_of_char_def
1f9f973eed2a proper datatype for 8-bit characters
haftmann
parents: 65552
diff changeset
   156
  by transfer (simp add: fun_eq_iff)
1f9f973eed2a proper datatype for 8-bit characters
haftmann
parents: 65552
diff changeset
   157
75651
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   158
context
81113
6fefd6c602fa clarified syntax for opening bundles;
wenzelm
parents: 75651
diff changeset
   159
  includes integer.lifting and bit_operations_syntax
75651
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   160
begin
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   161
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   162
lemma [code]:
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   163
  \<open>bit (int_of_integer k) n \<longleftrightarrow> bit k n\<close>
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   164
  by transfer rule
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   165
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   166
lemma [code]:
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   167
  \<open>NOT (int_of_integer k) = int_of_integer (NOT k)\<close>
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   168
  by transfer rule
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   169
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   170
lemma [code]:
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   171
  \<open>int_of_integer k AND int_of_integer l = int_of_integer (k AND l)\<close>
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   172
  by transfer rule
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   173
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   174
lemma [code]:
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   175
  \<open>int_of_integer k OR int_of_integer l = int_of_integer (k OR l)\<close>
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   176
  by transfer rule
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   177
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   178
lemma [code]:
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   179
  \<open>int_of_integer k XOR int_of_integer l = int_of_integer (k XOR l)\<close>
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   180
  by transfer rule
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   181
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   182
lemma [code]:
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   183
  \<open>push_bit n (int_of_integer k) = int_of_integer (push_bit n k)\<close>
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   184
  by transfer rule
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   185
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   186
lemma [code]:
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   187
  \<open>drop_bit n (int_of_integer k) = int_of_integer (drop_bit n k)\<close>
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   188
  by transfer rule
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   189
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   190
lemma [code]:
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   191
  \<open>take_bit n (int_of_integer k) = int_of_integer (take_bit n k)\<close>
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   192
  by transfer rule
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   193
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   194
lemma [code]:
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   195
  \<open>mask n = int_of_integer (mask n)\<close>
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   196
  by transfer rule
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   197
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   198
lemma [code]:
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   199
  \<open>set_bit n (int_of_integer k) = int_of_integer (set_bit n k)\<close>
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   200
  by transfer rule
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   201
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   202
lemma [code]:
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   203
  \<open>unset_bit n (int_of_integer k) = int_of_integer (unset_bit n k)\<close>
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   204
  by transfer rule
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   205
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   206
lemma [code]:
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   207
  \<open>flip_bit n (int_of_integer k) = int_of_integer (flip_bit n k)\<close>
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   208
  by transfer rule
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   209
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   210
end
f4116b7a6679 Move code lemmas for symbolic computation of bit operations on int to distribution.
haftmann
parents: 68028
diff changeset
   211
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 51143
diff changeset
   212
code_identifier
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 51143
diff changeset
   213
  code_module Code_Target_Int \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 51143
diff changeset
   214
    (SML) Arith and (OCaml) Arith and (Haskell) Arith
50023
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   215
28f3263d4d1b refined stack of library theories implementing int and/or nat by target language numerals
haftmann
parents:
diff changeset
   216
end