src/ZF/Integ/Bin.ML
author paulson
Fri, 24 May 2002 16:55:28 +0200
changeset 13178 bc54319f6875
parent 13175 81082cfa5618
child 13535 007559e981c7
permissions -rw-r--r--
new quantifier lemmas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
     1
(*  Title:      ZF/ex/Bin.ML
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
     2
    ID:         $Id$
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
     4
    Copyright   1994  University of Cambridge
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
     5
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
     6
Arithmetic on binary integers.
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
     7
*)
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
     8
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
     9
13175
81082cfa5618 new definition of "apply" and new simprule "beta_if"
paulson
parents: 12152
diff changeset
    10
Addsimps bin.intrs;
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
    11
AddTCs bin.intrs;
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    12
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    13
Goal "NCons(Pls,0) = Pls";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    14
by (Asm_simp_tac 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    15
qed "NCons_Pls_0";
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    16
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
    17
Goal "NCons(Pls,1) = Pls BIT 1";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    18
by (Asm_simp_tac 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    19
qed "NCons_Pls_1";
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    20
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
    21
Goal "NCons(Min,0) = Min BIT 0";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    22
by (Asm_simp_tac 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    23
qed "NCons_Min_0";
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    24
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    25
Goal "NCons(Min,1) = Min";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    26
by (Asm_simp_tac 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    27
qed "NCons_Min_1";
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    28
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
    29
Goal "NCons(w BIT x,b) = w BIT x BIT b";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    30
by (asm_simp_tac (simpset() addsimps bin.case_eqns) 1);
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
    31
qed "NCons_BIT";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    32
9909
111ccda5009b tuned ML code (the_context, bind_thms(s));
wenzelm
parents: 9883
diff changeset
    33
bind_thms ("NCons_simps",
111ccda5009b tuned ML code (the_context, bind_thms(s));
wenzelm
parents: 9883
diff changeset
    34
 [NCons_Pls_0, NCons_Pls_1,
111ccda5009b tuned ML code (the_context, bind_thms(s));
wenzelm
parents: 9883
diff changeset
    35
  NCons_Min_0, NCons_Min_1,
111ccda5009b tuned ML code (the_context, bind_thms(s));
wenzelm
parents: 9883
diff changeset
    36
  NCons_BIT]);
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    37
Addsimps NCons_simps;
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    38
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    39
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    40
(** Type checking **)
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    41
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    42
Goal "w: bin ==> integ_of(w) : int";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    43
by (induct_tac "w" 1);
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
    44
by (ALLGOALS (asm_simp_tac (simpset() addsimps [bool_into_nat])));
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    45
qed "integ_of_type";
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
    46
AddTCs [integ_of_type];
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    47
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    48
Goal "[| w: bin; b: bool |] ==> NCons(w,b) : bin";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    49
by (induct_tac "w" 1);
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    50
by Auto_tac;
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    51
qed "NCons_type";
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
    52
AddTCs [NCons_type];
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    53
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    54
Goal "w: bin ==> bin_succ(w) : bin";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    55
by (induct_tac "w" 1);
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    56
by Auto_tac;
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    57
qed "bin_succ_type";
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
    58
AddTCs [bin_succ_type];
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    59
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    60
Goal "w: bin ==> bin_pred(w) : bin";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    61
by (induct_tac "w" 1);
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    62
by Auto_tac;
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    63
qed "bin_pred_type";
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
    64
AddTCs [bin_pred_type];
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    65
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    66
Goal "w: bin ==> bin_minus(w) : bin";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    67
by (induct_tac "w" 1);
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    68
by Auto_tac;
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    69
qed "bin_minus_type";
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
    70
AddTCs [bin_minus_type];
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    71
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    72
(*This proof is complicated by the mutual recursion*)
9207
0c294bd701ea removed the mutual recursion from "bin_add"
paulson
parents: 6153
diff changeset
    73
Goalw [bin_add_def] "v: bin ==> ALL w: bin. bin_add(v,w) : bin";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    74
by (induct_tac "v" 1);
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    75
by (rtac ballI 3);
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    76
by (rename_tac "w'" 3);
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    77
by (induct_tac "w'" 3);
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
    78
by (ALLGOALS (asm_simp_tac (simpset() addsimps [NCons_type])));
6112
5e4871c5136b datatype package improvements
paulson
parents: 6065
diff changeset
    79
qed_spec_mp "bin_add_type";
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
    80
AddTCs [bin_add_type];
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    81
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    82
Goal "[| v: bin; w: bin |] ==> bin_mult(v,w) : bin";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
    83
by (induct_tac "v" 1);
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    84
by Auto_tac;
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    85
qed "bin_mult_type";
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
    86
AddTCs [bin_mult_type];
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    87
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    88
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    89
(**** The carry/borrow functions, bin_succ and bin_pred ****)
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    90
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    91
(*NCons preserves the integer value of its argument*)
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    92
Goal "[| w: bin; b: bool |] ==> integ_of(NCons(w,b)) = integ_of(w BIT b)";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    93
by (etac bin.elim 1);
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    94
by (Asm_simp_tac 3);
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    95
by (ALLGOALS (etac boolE));
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
    96
by (ALLGOALS Asm_simp_tac);
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    97
qed "integ_of_NCons";
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    98
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
    99
Addsimps [integ_of_NCons];
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   100
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   101
Goal "w: bin ==> integ_of(bin_succ(w)) = $#1 $+ integ_of(w)";
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   102
by (etac bin.induct 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   103
by (Simp_tac 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   104
by (Simp_tac 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   105
by (etac boolE 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   106
by (ALLGOALS (asm_simp_tac (simpset() addsimps zadd_ac)));
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   107
qed "integ_of_succ";
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   108
9548
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   109
Goal "w: bin ==> integ_of(bin_pred(w)) = $- ($#1) $+ integ_of(w)";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   110
by (etac bin.induct 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   111
by (Simp_tac 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   112
by (Simp_tac 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   113
by (etac boolE 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   114
by (ALLGOALS (asm_simp_tac (simpset() addsimps zadd_ac)));
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   115
qed "integ_of_pred";
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   116
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
   117
Addsimps [integ_of_succ, integ_of_pred];
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   118
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   119
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   120
(*** bin_minus: (unary!) negation of binary integers ***)
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   121
9548
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   122
Goal "w: bin ==> integ_of(bin_minus(w)) = $- integ_of(w)";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   123
by (etac bin.induct 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   124
by (Simp_tac 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   125
by (Simp_tac 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   126
by (etac boolE 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   127
by (ALLGOALS 
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   128
    (asm_simp_tac (simpset() addsimps zadd_ac@[zminus_zadd_distrib])));
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   129
qed "integ_of_minus";
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   130
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   131
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   132
(*** bin_add: binary addition ***)
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   133
9207
0c294bd701ea removed the mutual recursion from "bin_add"
paulson
parents: 6153
diff changeset
   134
Goalw [bin_add_def] "w: bin ==> bin_add(Pls,w) = w";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   135
by (Asm_simp_tac 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   136
qed "bin_add_Pls";
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   137
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   138
Goalw [bin_add_def] "w: bin ==> bin_add(w,Pls) = w";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   139
by (etac bin.induct 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   140
by Auto_tac;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   141
qed "bin_add_Pls_right";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   142
9207
0c294bd701ea removed the mutual recursion from "bin_add"
paulson
parents: 6153
diff changeset
   143
Goalw [bin_add_def] "w: bin ==> bin_add(Min,w) = bin_pred(w)";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   144
by (Asm_simp_tac 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   145
qed "bin_add_Min";
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   146
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   147
Goalw [bin_add_def] "w: bin ==> bin_add(w,Min) = bin_pred(w)";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   148
by (etac bin.induct 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   149
by Auto_tac;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   150
qed "bin_add_Min_right";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   151
9207
0c294bd701ea removed the mutual recursion from "bin_add"
paulson
parents: 6153
diff changeset
   152
Goalw [bin_add_def] "bin_add(v BIT x,Pls) = v BIT x";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   153
by (Simp_tac 1);
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   154
qed "bin_add_BIT_Pls";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   155
9207
0c294bd701ea removed the mutual recursion from "bin_add"
paulson
parents: 6153
diff changeset
   156
Goalw [bin_add_def] "bin_add(v BIT x,Min) = bin_pred(v BIT x)";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   157
by (Simp_tac 1);
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   158
qed "bin_add_BIT_Min";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   159
9207
0c294bd701ea removed the mutual recursion from "bin_add"
paulson
parents: 6153
diff changeset
   160
Goalw [bin_add_def] "[| w: bin;  y: bool |]              \
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   161
\     ==> bin_add(v BIT x, w BIT y) = \
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
   162
\         NCons(bin_add(v, cond(x and y, bin_succ(w), w)), x xor y)";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   163
by (Asm_simp_tac 1);
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   164
qed "bin_add_BIT_BIT";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   165
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   166
Addsimps [bin_add_Pls, bin_add_Min, bin_add_BIT_Pls,
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   167
	  bin_add_BIT_Min, bin_add_BIT_BIT,
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   168
	  integ_of_succ, integ_of_pred];
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   169
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   170
Goal "v: bin ==> \
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
   171
\         ALL w: bin. integ_of(bin_add(v,w)) = integ_of(v) $+ integ_of(w)";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   172
by (etac bin.induct 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   173
by (Simp_tac 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   174
by (Simp_tac 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   175
by (rtac ballI 1);
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
   176
by (induct_tac "wa" 1);
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   177
by (ALLGOALS (asm_simp_tac (simpset() addsimps zadd_ac setloop (etac boolE))));
6112
5e4871c5136b datatype package improvements
paulson
parents: 6065
diff changeset
   178
qed_spec_mp "integ_of_add";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   179
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   180
(*Subtraction*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   181
Goalw [zdiff_def]
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   182
     "[| v: bin;  w: bin |]   \
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   183
\     ==> integ_of(v) $- integ_of(w) = integ_of(bin_add (v, bin_minus(w)))";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   184
by (asm_simp_tac (simpset() addsimps [integ_of_add, integ_of_minus]) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   185
qed "diff_integ_of_eq";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   186
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   187
9207
0c294bd701ea removed the mutual recursion from "bin_add"
paulson
parents: 6153
diff changeset
   188
(*** bin_mult: binary multiplication ***)
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   189
6046
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
   190
Goal "[| v: bin;  w: bin |]   \
2c8a8be36c94 converted to use new primrec section
paulson
parents: 5561
diff changeset
   191
\     ==> integ_of(bin_mult(v,w)) = integ_of(v) $* integ_of(w)";
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents: 6046
diff changeset
   192
by (induct_tac "v" 1);
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   193
by (Asm_simp_tac 1);
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   194
by (asm_simp_tac (simpset() addsimps [integ_of_minus]) 1);
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   195
by (etac boolE 1);
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   196
by (asm_simp_tac (simpset() addsimps [zadd_zmult_distrib]) 2);
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   197
by (asm_simp_tac (simpset() addsimps [integ_of_add,
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   198
				      zadd_zmult_distrib] @ zadd_ac) 1);
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   199
qed "integ_of_mult";
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   200
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   201
(**** Computations ****)
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   202
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   203
(** extra rules for bin_succ, bin_pred **)
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   204
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   205
Goal "bin_succ(w BIT 1) = bin_succ(w) BIT 0";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   206
by (Simp_tac 1);
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   207
qed "bin_succ_1";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   208
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   209
Goal "bin_succ(w BIT 0) = NCons(w,1)";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   210
by (Simp_tac 1);
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   211
qed "bin_succ_0";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   212
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   213
Goal "bin_pred(w BIT 1) = NCons(w,0)";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   214
by (Simp_tac 1);
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   215
qed "bin_pred_1";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   216
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   217
Goal "bin_pred(w BIT 0) = bin_pred(w) BIT 1";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   218
by (Simp_tac 1);
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   219
qed "bin_pred_0";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   220
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   221
(** extra rules for bin_minus **)
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   222
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   223
Goal "bin_minus(w BIT 1) = bin_pred(NCons(bin_minus(w), 0))";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   224
by (Simp_tac 1);
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   225
qed "bin_minus_1";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   226
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   227
Goal "bin_minus(w BIT 0) = bin_minus(w) BIT 0";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   228
by (Simp_tac 1);
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   229
qed "bin_minus_0";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   230
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   231
(** extra rules for bin_add **)
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   232
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   233
Goal "w: bin ==> bin_add(v BIT 1, w BIT 1) = \
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   234
\                    NCons(bin_add(v, bin_succ(w)), 0)";
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   235
by (Asm_simp_tac 1);
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   236
qed "bin_add_BIT_11";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   237
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   238
Goal "w: bin ==> bin_add(v BIT 1, w BIT 0) =  \
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   239
\                    NCons(bin_add(v,w), 1)";
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   240
by (Asm_simp_tac 1);
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   241
qed "bin_add_BIT_10";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   242
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   243
Goal "[| w: bin;  y: bool |] \
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   244
\     ==> bin_add(v BIT 0, w BIT y) = NCons(bin_add(v,w), y)";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   245
by (Asm_simp_tac 1);
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   246
qed "bin_add_BIT_0";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   247
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   248
(** extra rules for bin_mult **)
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   249
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   250
Goal "bin_mult(v BIT 1, w) = bin_add(NCons(bin_mult(v,w),0), w)";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   251
by (Simp_tac 1);
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   252
qed "bin_mult_1";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   253
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   254
Goal "bin_mult(v BIT 0, w) = NCons(bin_mult(v,w),0)";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   255
by (Simp_tac 1);
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   256
qed "bin_mult_0";
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   257
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   258
9548
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   259
(** Simplification rules with integer constants **)
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   260
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   261
Goal "$#0 = #0";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   262
by (Simp_tac 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   263
qed "int_of_0";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   264
9576
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   265
Goal "$# succ(n) = #1 $+ $#n";
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   266
by (simp_tac (simpset() addsimps [int_of_add RS sym, natify_succ]) 1);
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   267
qed "int_of_succ";
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   268
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   269
Goal "$- #0 = #0";
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   270
by (Simp_tac 1);
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   271
qed "zminus_0";
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   272
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   273
Addsimps [zminus_0];
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   274
9548
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   275
Goal "#0 $+ z = intify(z)";
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   276
by (Simp_tac 1);
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   277
qed "zadd_0_intify";
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   278
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   279
Goal "z $+ #0 = intify(z)";
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   280
by (Simp_tac 1);
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   281
qed "zadd_0_right_intify";
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   282
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   283
Addsimps [zadd_0_intify, zadd_0_right_intify];
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   284
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   285
Goal "#1 $* z = intify(z)";
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   286
by (Simp_tac 1);
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   287
qed "zmult_1_intify";
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   288
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   289
Goal "z $* #1 = intify(z)";
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   290
by (stac zmult_commute 1);
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   291
by (Simp_tac 1);
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   292
qed "zmult_1_right_intify";
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   293
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   294
Addsimps [zmult_1_intify, zmult_1_right_intify];
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   295
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   296
Goal "#0 $* z = #0";
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   297
by (Simp_tac 1);
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   298
qed "zmult_0";
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   299
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   300
Goal "z $* #0 = #0";
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   301
by (stac zmult_commute 1);
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   302
by (Simp_tac 1);
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   303
qed "zmult_0_right";
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   304
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   305
Addsimps [zmult_0, zmult_0_right];
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   306
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   307
Goal "#-1 $* z = $-z";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   308
by (simp_tac (simpset() addsimps zcompare_rls) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   309
qed "zmult_minus1";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   310
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   311
Goal "z $* #-1 = $-z";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   312
by (stac zmult_commute 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   313
by (rtac zmult_minus1 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   314
qed "zmult_minus1_right";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   315
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   316
Addsimps [zmult_minus1, zmult_minus1_right];
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   317
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   318
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   319
(*** Simplification rules for comparison of binary numbers (N Voelker) ***)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   320
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   321
(** Equals (=) **)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   322
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   323
Goalw [iszero_def]
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   324
     "[| v: bin;  w: bin |]   \
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   325
\     ==> ((integ_of(v)) = integ_of(w)) <-> \
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   326
\         iszero (integ_of (bin_add (v, bin_minus(w))))"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   327
by (asm_simp_tac (simpset() addsimps
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   328
              (zcompare_rls @ [integ_of_add, integ_of_minus])) 1); 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   329
qed "eq_integ_of_eq"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   330
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   331
Goalw [iszero_def] "iszero (integ_of(Pls))"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   332
by (Simp_tac 1); 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   333
qed "iszero_integ_of_Pls";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   334
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   335
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   336
Goalw [iszero_def] "~ iszero (integ_of(Min))"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   337
by (simp_tac (simpset() addsimps [zminus_equation]) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   338
qed "nonzero_integ_of_Min"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   339
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   340
Goalw [iszero_def]
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   341
     "[| w: bin; x: bool |] \
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   342
\     ==> iszero (integ_of (w BIT x)) <-> (x=0 & iszero (integ_of(w)))"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   343
by (Simp_tac 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   344
by (subgoal_tac "integ_of(w) : int" 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   345
by (Asm_simp_tac 2);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   346
by (dtac int_cases 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   347
by (auto_tac (claset() addSEs [boolE], 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   348
              simpset() addsimps [int_of_add RS sym]));  
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   349
by (ALLGOALS (asm_full_simp_tac 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   350
	      (simpset() addsimps zcompare_rls @ 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   351
			  [zminus_zadd_distrib RS sym, int_of_add RS sym])));
12152
46f128d8133c Renamed some bound variables due to changes in simplifier.
berghofe
parents: 11381
diff changeset
   352
by (subgoal_tac "znegative ($- $# succ(n)) <-> znegative ($# succ(n))" 1);
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   353
by (Asm_simp_tac 2);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   354
by (Full_simp_tac 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   355
qed "iszero_integ_of_BIT"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   356
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   357
Goal "w: bin ==> iszero (integ_of (w BIT 0)) <-> iszero (integ_of(w))"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   358
by (asm_simp_tac (ZF_ss addsimps [iszero_integ_of_BIT]) 1); 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   359
qed "iszero_integ_of_0"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   360
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   361
Goal "w: bin ==> ~ iszero (integ_of (w BIT 1))"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   362
by (asm_simp_tac (ZF_ss addsimps [iszero_integ_of_BIT]) 1); 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   363
qed "iszero_integ_of_1"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   364
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   365
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   366
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   367
(** Less-than (<) **)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   368
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   369
Goalw [zless_def,zdiff_def] 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   370
     "[| v: bin;  w: bin |]   \
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   371
\     ==> integ_of(v) $< integ_of(w) \
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   372
\         <-> znegative (integ_of (bin_add (v, bin_minus(w))))";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   373
by (asm_simp_tac (simpset() addsimps [integ_of_minus, integ_of_add]) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   374
qed "less_integ_of_eq_neg"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   375
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   376
Goal "~ znegative (integ_of(Pls))"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   377
by (Simp_tac 1); 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   378
qed "not_neg_integ_of_Pls"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   379
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   380
Goal "znegative (integ_of(Min))"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   381
by (Simp_tac 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   382
qed "neg_integ_of_Min"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   383
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   384
Goal "[| w: bin; x: bool |] \
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   385
\     ==> znegative (integ_of (w BIT x)) <-> znegative (integ_of(w))"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   386
by (Asm_simp_tac 1); 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   387
by (subgoal_tac "integ_of(w) : int" 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   388
by (Asm_simp_tac 2);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   389
by (dtac int_cases 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   390
by (auto_tac (claset() addSEs [boolE], 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   391
              simpset() addsimps [int_of_add RS sym] @ zcompare_rls));  
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   392
by (ALLGOALS (asm_full_simp_tac 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   393
	      (simpset() addsimps [zminus_zadd_distrib RS sym, zdiff_def,
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   394
				   int_of_add RS sym])));
12152
46f128d8133c Renamed some bound variables due to changes in simplifier.
berghofe
parents: 11381
diff changeset
   395
by (subgoal_tac "$#1 $- $# succ(succ(n #+ n)) = $- $# succ(n #+ n)" 1);
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   396
by (asm_full_simp_tac (simpset() addsimps [zdiff_def])1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   397
by (asm_simp_tac (simpset() addsimps [equation_zminus, int_of_diff RS sym])1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   398
qed "neg_integ_of_BIT"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   399
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   400
(** Less-than-or-equals (<=) **)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   401
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   402
Goal "(integ_of(x) $<= (integ_of(w))) <-> ~ (integ_of(w) $< (integ_of(x)))";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   403
by (simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym]) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   404
qed "le_integ_of_eq_not_less"; 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   405
9548
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9207
diff changeset
   406
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   407
(*Delete the original rewrites, with their clumsy conditional expressions*)
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   408
Delsimps [bin_succ_BIT, bin_pred_BIT, bin_minus_BIT, 
9207
0c294bd701ea removed the mutual recursion from "bin_add"
paulson
parents: 6153
diff changeset
   409
          NCons_Pls, NCons_Min, bin_adder_BIT, bin_mult_BIT];
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   410
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   411
(*Hide the binary representation of integer constants*)
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   412
Delsimps [integ_of_Pls, integ_of_Min, integ_of_BIT];
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 6112
diff changeset
   413
5528
4896b4e4077b new directory for Integers
paulson
parents:
diff changeset
   414
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   415
bind_thms ("NCons_simps", 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   416
	   [NCons_Pls_0, NCons_Pls_1, NCons_Min_0, NCons_Min_1, NCons_BIT]);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   417
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   418
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   419
bind_thms ("bin_arith_extra_simps",
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   420
    [integ_of_add RS sym,   (*invoke bin_add*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   421
     integ_of_minus RS sym, (*invoke bin_minus*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   422
     integ_of_mult RS sym,  (*invoke bin_mult*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   423
     bin_succ_1, bin_succ_0, 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   424
     bin_pred_1, bin_pred_0, 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   425
     bin_minus_1, bin_minus_0,  
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   426
     bin_add_Pls_right, bin_add_Min_right,
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   427
     bin_add_BIT_0, bin_add_BIT_10, bin_add_BIT_11,
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   428
     diff_integ_of_eq,
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   429
     bin_mult_1, bin_mult_0] @ NCons_simps);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   430
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   431
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   432
(*For making a minimal simpset, one must include these default simprules
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   433
  of thy.  Also include simp_thms, or at least (~False)=True*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   434
bind_thms ("bin_arith_simps",
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   435
    [bin_pred_Pls, bin_pred_Min,
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   436
     bin_succ_Pls, bin_succ_Min,
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   437
     bin_add_Pls, bin_add_Min,
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   438
     bin_minus_Pls, bin_minus_Min,
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   439
     bin_mult_Pls, bin_mult_Min] @ bin_arith_extra_simps);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   440
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   441
(*Simplification of relational operations*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   442
bind_thms ("bin_rel_simps",
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   443
    [eq_integ_of_eq, iszero_integ_of_Pls, nonzero_integ_of_Min,
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   444
     iszero_integ_of_0, iszero_integ_of_1,
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   445
     less_integ_of_eq_neg,
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   446
     not_neg_integ_of_Pls, neg_integ_of_Min, neg_integ_of_BIT,
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   447
     le_integ_of_eq_not_less]);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   448
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   449
Addsimps bin_arith_simps;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   450
Addsimps bin_rel_simps;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   451
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   452
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   453
(** Simplification of arithmetic when nested to the right **)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   454
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   455
Goal "[| v: bin;  w: bin |]   \
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   456
\     ==> integ_of(v) $+ (integ_of(w) $+ z) = (integ_of(bin_add(v,w)) $+ z)";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   457
by (asm_simp_tac (simpset() addsimps [zadd_assoc RS sym]) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   458
qed "add_integ_of_left";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   459
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   460
Goal "[| v: bin;  w: bin |]   \
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   461
\     ==> integ_of(v) $* (integ_of(w) $* z) = (integ_of(bin_mult(v,w)) $* z)";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   462
by (asm_simp_tac (simpset() addsimps [zmult_assoc RS sym]) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   463
qed "mult_integ_of_left";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   464
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   465
Goalw [zdiff_def]
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   466
    "[| v: bin;  w: bin |]   \
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   467
\     ==> integ_of(v) $+ (integ_of(w) $- c) = integ_of(bin_add(v,w)) $- (c)";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   468
by (rtac add_integ_of_left 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   469
by Auto_tac;  
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   470
qed "add_integ_of_diff1";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   471
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   472
Goal "[| v: bin;  w: bin |]   \
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   473
\     ==> integ_of(v) $+ (c $- integ_of(w)) = \
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   474
\         integ_of (bin_add (v, bin_minus(w))) $+ (c)";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   475
by (stac (diff_integ_of_eq RS sym) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   476
by (ALLGOALS (asm_simp_tac (simpset() addsimps zdiff_def::zadd_ac)));
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   477
qed "add_integ_of_diff2";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   478
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   479
Addsimps [add_integ_of_left, mult_integ_of_left,
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
   480
	  add_integ_of_diff1, add_integ_of_diff2]; 
9576
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   481
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   482
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   483
(** More for integer constants **)
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   484
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   485
Addsimps [int_of_0, int_of_succ];
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   486
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   487
Goal "#0 $- x = $-x";
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   488
by (simp_tac (simpset() addsimps [zdiff_def]) 1);
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   489
qed "zdiff0";
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   490
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   491
Goal "x $- #0 = intify(x)";
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   492
by (simp_tac (simpset() addsimps [zdiff_def]) 1);
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   493
qed "zdiff0_right";
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   494
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   495
Goal "x $- x = #0";
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   496
by (simp_tac (simpset() addsimps [zdiff_def]) 1);
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   497
qed "zdiff_self";
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   498
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   499
Addsimps [zdiff0, zdiff0_right, zdiff_self];
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   500
9883
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   501
Goal "k: int ==> znegative(k) <-> k $< #0";
9576
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   502
by (asm_simp_tac (simpset() addsimps [zless_def]) 1);
9883
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   503
qed "znegative_iff_zless_0";
9576
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   504
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   505
Goal "[| #0 $< k; k: int |] ==> znegative($-k)";
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   506
by (asm_full_simp_tac (simpset() addsimps [zless_def]) 1);
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   507
qed "zero_zless_imp_znegative_zminus";
3df14e0a3a51 interim working version: more improvements to the integers
paulson
parents: 9570
diff changeset
   508
9883
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   509
Goal "#0 $<= $# n";
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   510
by (simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym, 
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   511
                                  znegative_iff_zless_0 RS iff_sym]) 1); 
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   512
qed "zero_zle_int_of";
11321
01cbbf33779b the rest of integer division
paulson
parents: 10716
diff changeset
   513
Addsimps [zero_zle_int_of];
9883
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   514
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   515
Goal "nat_of(#0) = 0";
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   516
by (simp_tac (ZF_ss addsimps [natify_0, int_of_0 RS sym, nat_of_int_of]) 1);
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   517
qed "nat_of_0";
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   518
Addsimps [nat_of_0];
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   519
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   520
Goal "[| z $<= $#0; z: int |] ==> nat_of(z) = 0"; 
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   521
by (auto_tac (claset(), 
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   522
	      simpset() addsimps [znegative_iff_zless_0 RS iff_sym, 
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   523
				  zle_def, zneg_nat_of])); 
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   524
val lemma = result();
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   525
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   526
Goal "z $<= $#0 ==> nat_of(z) = 0"; 
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   527
by (subgoal_tac "nat_of(intify(z)) = 0" 1);
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   528
by (rtac lemma 2);
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   529
by Auto_tac;  
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   530
qed "nat_le_int0";
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   531
10635
b115460e5c50 unsymbolize;
wenzelm
parents: 9909
diff changeset
   532
Goal "$# n = #0 ==> natify(n) = 0";
9883
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   533
by (rtac not_znegative_imp_zero 1);
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   534
by Auto_tac;  
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   535
qed "int_of_eq_0_imp_natify_eq_0";
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   536
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   537
Goalw [nat_of_def, raw_nat_of_def] "nat_of($- $# n) = 0";
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   538
by (auto_tac((claset() addSDs [not_znegative_imp_zero, natify_int_of_eq], 
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   539
              simpset())     delIffs [int_of_eq]));
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   540
by (rtac the_equality 1);
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   541
by Auto_tac;  
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   542
by (blast_tac (claset() addIs [int_of_eq_0_imp_natify_eq_0, sym]) 1); 
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   543
qed "nat_of_zminus_int_of";
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   544
10635
b115460e5c50 unsymbolize;
wenzelm
parents: 9909
diff changeset
   545
Goal "#0 $<= z ==> $# nat_of(z) = intify(z)";
9883
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   546
by (rtac not_zneg_nat_of_intify 1);
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   547
by (asm_simp_tac (simpset() addsimps [znegative_iff_zless_0, 
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   548
                                      not_zless_iff_zle]) 1); 
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   549
qed "int_of_nat_of";
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   550
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   551
Addsimps [int_of_nat_of, nat_of_zminus_int_of];
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   552
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   553
Goal "$# nat_of(z) = (if #0 $<= z then intify(z) else #0)";
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   554
by (simp_tac (simpset() addsimps [int_of_nat_of,
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   555
                              znegative_iff_zless_0, not_zle_iff_zless]) 1);
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   556
qed "int_of_nat_of_if";
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   557
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   558
Goal "[| m: nat; z: int |] ==> (m < nat_of(z)) <-> ($#m $< z)";
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   559
by (case_tac "znegative(z)" 1);
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   560
by (etac (not_zneg_nat_of RS subst) 2);
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   561
by (auto_tac (claset() addDs [zless_trans]
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   562
		       addSDs [zero_zle_int_of RS zle_zless_trans], 
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   563
	      simpset() addsimps [znegative_iff_zless_0])); 
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   564
qed "zless_nat_iff_int_zless";
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   565
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   566
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   567
(** nat_of and zless **)
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   568
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   569
(*An alternative condition is  $#0 <= w  *)
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   570
Goal "$#0 $< z ==> (nat_of(w) < nat_of(z)) <-> (w $< z)";
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   571
by (rtac iff_trans 1);
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   572
by (rtac (zless_int_of RS iff_sym) 1);
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   573
by (auto_tac (claset(), 
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   574
       simpset() addsimps [int_of_nat_of_if] delsimps [zless_int_of]));  
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   575
by (auto_tac (claset() addEs [zless_asym],
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   576
              simpset() addsimps [not_zle_iff_zless]));  
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   577
by (blast_tac (claset() addIs [zless_zle_trans]) 1); 
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   578
val lemma = result();
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   579
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   580
Goal "(nat_of(w) < nat_of(z)) <-> ($#0 $< z & w $< z)";
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   581
by (case_tac "$#0 $< z" 1);
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   582
by (auto_tac (claset(), 
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   583
	      simpset() addsimps [lemma, nat_le_int0, not_zless_iff_zle])); 
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   584
qed "zless_nat_conj";
c1c8647af477 a number of new theorems
paulson
parents: 9578
diff changeset
   585
10716
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   586
(*This simprule cannot be added unless we can find a way to make eq_integ_of_eq
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   587
  unconditional!
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   588
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   589
  (*The condition "True" is a hack to prevent looping.
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   590
    Conditional rewrite rules are tried after unconditional ones, so a rule
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   591
    like eq_nat_number_of will be tried first to eliminate #mm=#nn. *)
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   592
  Goal "True ==> (integ_of(w) = x) <-> (x = integ_of(w))";
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   593
  by Auto_tac;  
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   594
  qed "integ_of_reorient";
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   595
  Addsimps [integ_of_reorient];
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   596
*)
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   597
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   598
Goal "(integ_of(w) = $- x) <-> ($- x = integ_of(w))";
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   599
by Auto_tac;  
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   600
qed "integ_of_minus_reorient";
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   601
Addsimps [integ_of_minus_reorient];
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   602
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   603
Goal "(integ_of(w) = x $+ y) <-> (x $+ y = integ_of(w))";
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   604
by Auto_tac;  
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   605
qed "integ_of_add_reorient";
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   606
Addsimps [integ_of_add_reorient];
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   607
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   608
Goal "(integ_of(w) = x $- y) <-> (x $- y = integ_of(w))";
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   609
by Auto_tac;  
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   610
qed "integ_of_diff_reorient";
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   611
Addsimps [integ_of_diff_reorient];
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   612
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   613
Goal "(integ_of(w) = x $* y) <-> (x $* y = integ_of(w))";
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   614
by Auto_tac;  
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   615
qed "integ_of_mult_reorient";
01aec27d4c45 re-orientation of integer literals
paulson
parents: 10635
diff changeset
   616
Addsimps [integ_of_mult_reorient];