src/HOL/Hyperreal/EvenOdd.ML
author nipkow
Fri, 23 Aug 2002 07:41:05 +0200
changeset 13517 42efec18f5b2
parent 13153 4b052946b41c
child 13524 604d0f3622d6
permissions -rw-r--r--
Added div+mod cancelling simproc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     1
(*  Title       : Even.ML
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     2
    Author      : Jacques D. Fleuriot  
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     3
    Copyright   : 1999  University of Edinburgh
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     4
    Description : Even numbers defined
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     5
*)
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     6
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     7
Goal "even(Suc(Suc n)) = (even(n))";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     8
by (Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     9
qed "even_Suc_Suc";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    10
Addsimps [even_Suc_Suc];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    11
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    12
Goal "(even(n)) = (~odd(n))";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    13
by (induct_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    14
by (Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    15
qed "even_not_odd";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    16
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    17
Goal "(odd(n)) = (~even(n))";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    18
by (simp_tac (simpset() addsimps [even_not_odd]) 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    19
qed "odd_not_even";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    20
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    21
Goal "even(2*n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    22
by (induct_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    23
by (Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    24
qed "even_mult_two";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    25
Addsimps [even_mult_two];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    26
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    27
Goal "even(n*2)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    28
by (induct_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    29
by (Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    30
qed "even_mult_two'";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    31
Addsimps [even_mult_two'];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    32
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    33
Goal "even(n + n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    34
by (induct_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    35
by (Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    36
qed "even_sum_self";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    37
Addsimps [even_sum_self];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    38
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    39
Goal "~odd(2*n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    40
by (induct_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    41
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    42
qed "not_odd_self_mult2";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    43
Addsimps [not_odd_self_mult2];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    44
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    45
Goal "~odd(n + n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    46
by (induct_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    47
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    48
qed "not_odd_sum_self";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    49
Addsimps [not_odd_sum_self];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    50
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    51
Goal "~even(Suc(n + n))";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    52
by (induct_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    53
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    54
qed "not_even_Suc_sum_self";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    55
Addsimps [not_even_Suc_sum_self];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    56
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    57
Goal "odd(Suc(2*n))";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    58
by (induct_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    59
by (Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    60
qed "odd_mult_two_add_one";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    61
Addsimps [odd_mult_two_add_one];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    62
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    63
Goal "odd(Suc(n + n))";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    64
by (induct_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    65
by (Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    66
qed "odd_sum_Suc_self";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    67
Addsimps [odd_sum_Suc_self];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    68
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    69
Goal "even(Suc n) = odd(n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    70
by (induct_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    71
by (Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    72
qed "even_Suc_odd_iff";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    73
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    74
Goal "odd(Suc n) = even(n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    75
by (induct_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    76
by (Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    77
qed "odd_Suc_even_iff";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    78
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    79
Goal "even n | odd n";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    80
by (simp_tac (simpset() addsimps [even_not_odd]) 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    81
qed "even_odd_disj";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    82
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    83
(* could be proved automatically before: spoiled by numeral arith! *)
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    84
Goal "EX m. (n = 2*m | n = Suc(2*m))";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    85
by (induct_tac "n" 1 THEN Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    86
by (res_inst_tac [("x","Suc m")] exI 1 THEN Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    87
qed "nat_mult_two_Suc_disj";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    88
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    89
Goal "even(n) = (EX m. n = 2*m)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    90
by (cut_inst_tac [("n","n")] nat_mult_two_Suc_disj 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    91
by (Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    92
qed "even_mult_two_ex";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    93
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    94
Goal "odd(n) = (EX m. n = Suc (2*m))";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    95
by (cut_inst_tac [("n","n")] nat_mult_two_Suc_disj 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    96
by (Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    97
qed "odd_Suc_mult_two_ex";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    98
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    99
Goal "even(n) ==> even(m*n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   100
by (auto_tac (claset(),
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   101
              simpset() addsimps [add_mult_distrib2, even_mult_two_ex]));
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   102
qed "even_mult_even";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   103
Addsimps [even_mult_even];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   104
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   105
Goal "(m + m) div 2 = (m::nat)";
13153
4b052946b41c arith can now deal with div 2 and mod 2.
nipkow
parents: 13151
diff changeset
   106
by (arith_tac 1);
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   107
qed "div_add_self_two_is_m";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   108
Addsimps [div_add_self_two_is_m];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   109
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   110
Goal "Suc(Suc(m*2)) div 2 = Suc m";
13153
4b052946b41c arith can now deal with div 2 and mod 2.
nipkow
parents: 13151
diff changeset
   111
by (arith_tac 1);
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   112
qed "div_mult_self_Suc_Suc";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   113
Addsimps [div_mult_self_Suc_Suc];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   114
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   115
Goal "Suc(Suc(2*m)) div 2 = Suc m";
13153
4b052946b41c arith can now deal with div 2 and mod 2.
nipkow
parents: 13151
diff changeset
   116
by (arith_tac 1);
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   117
qed "div_mult_self_Suc_Suc2";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   118
Addsimps [div_mult_self_Suc_Suc2];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   119
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   120
Goal "Suc(Suc(m + m)) div 2 = Suc m";
13153
4b052946b41c arith can now deal with div 2 and mod 2.
nipkow
parents: 13151
diff changeset
   121
by (arith_tac 1);
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   122
qed "div_add_self_Suc_Suc";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   123
Addsimps [div_add_self_Suc_Suc];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   124
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   125
Goal "~ even n ==> (Suc n) div 2 = Suc((n - 1) div 2)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   126
by (auto_tac (claset(),simpset() addsimps [odd_not_even RS sym,
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   127
    odd_Suc_mult_two_ex]));
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   128
qed "not_even_imp_Suc_Suc_diff_one_eq";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   129
Addsimps [not_even_imp_Suc_Suc_diff_one_eq];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   130
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   131
Goal "even(m + n) = (even m = even n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   132
by (induct_tac "m" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   133
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   134
qed "even_add";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   135
AddIffs [even_add];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   136
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   137
Goal "even(m * n) = (even m | even n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   138
by (induct_tac "m" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   139
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   140
qed "even_mult";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   141
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   142
Goal "even (m ^ n) = (even m & n ~= 0)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   143
by (induct_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   144
by (auto_tac (claset(),simpset() addsimps [even_mult]));
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   145
qed "even_pow";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   146
AddIffs [even_pow];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   147
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   148
Goal "odd(m + n) = (odd m ~= odd n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   149
by (induct_tac "m" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   150
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   151
qed "odd_add";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   152
AddIffs [odd_add];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   153
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   154
Goal "odd(m * n) = (odd m & odd n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   155
by (induct_tac "m" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   156
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   157
qed "odd_mult";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   158
AddIffs [odd_mult];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   159
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   160
Goal "odd (m ^ n) = (odd m | n = 0)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   161
by (induct_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   162
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   163
qed "odd_pow";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   164
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   165
Goal "0 < n --> ~even (n + n - 1)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   166
by (induct_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   167
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   168
qed_spec_mp "not_even_2n_minus_1";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   169
Addsimps [not_even_2n_minus_1];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   170
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   171
Goal "Suc (2 * m) mod 2 = 1";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   172
by (induct_tac "m" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   173
by (auto_tac (claset(),simpset() addsimps [mod_Suc]));
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   174
qed "mod_two_Suc_2m";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   175
Addsimps [mod_two_Suc_2m];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   176
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   177
Goal "(Suc (Suc (2 * m)) div 2) = Suc m";
13153
4b052946b41c arith can now deal with div 2 and mod 2.
nipkow
parents: 13151
diff changeset
   178
by (arith_tac 1);
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   179
qed "div_two_Suc_Suc_2m";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   180
Addsimps [div_two_Suc_Suc_2m];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   181
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   182
Goal "even n ==> 2 * ((n + 1) div 2) = n";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   183
by (auto_tac (claset(),simpset() addsimps [mult_div_cancel,
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   184
    even_mult_two_ex]));
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   185
qed "lemma_even_div";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   186
Addsimps [lemma_even_div];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   187
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   188
Goal "~even n ==> 2 * ((n + 1) div 2) = Suc n";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   189
by (auto_tac (claset(),simpset() addsimps [even_not_odd,
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   190
    odd_Suc_mult_two_ex]));
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   191
qed "lemma_not_even_div";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   192
Addsimps [lemma_not_even_div];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   193
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   194
Goal "Suc n div 2 <= Suc (Suc n) div 2";
13153
4b052946b41c arith can now deal with div 2 and mod 2.
nipkow
parents: 13151
diff changeset
   195
by (arith_tac 1);
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   196
qed "Suc_n_le_Suc_Suc_n_div_2";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   197
Addsimps [Suc_n_le_Suc_Suc_n_div_2];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   198
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   199
Goal "(0::nat) < n --> 0 < (n + 1) div 2";
13153
4b052946b41c arith can now deal with div 2 and mod 2.
nipkow
parents: 13151
diff changeset
   200
by (arith_tac 1);
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   201
qed_spec_mp "Suc_n_div_2_gt_zero";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   202
Addsimps [Suc_n_div_2_gt_zero];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   203
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   204
Goal "0 < n & even n --> 1 < n";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   205
by (induct_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   206
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   207
qed_spec_mp "even_gt_zero_gt_one";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   208
bind_thm ("even_gt_zero_gt_one",conjI RS even_gt_zero_gt_one);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   209
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   210
(* more general *)
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   211
Goal "n div 2 <= (Suc n) div 2";
13153
4b052946b41c arith can now deal with div 2 and mod 2.
nipkow
parents: 13151
diff changeset
   212
by (arith_tac 1);
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   213
qed "le_Suc_n_div_2";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   214
Addsimps [le_Suc_n_div_2];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   215
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   216
Goal "(1::nat) < n --> 0 < n div 2";
13153
4b052946b41c arith can now deal with div 2 and mod 2.
nipkow
parents: 13151
diff changeset
   217
by (arith_tac 1);
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   218
qed_spec_mp "div_2_gt_zero";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   219
Addsimps [div_2_gt_zero];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   220
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   221
Goal "even n ==> (n + 1) div 2 = n div 2";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   222
by (rtac (CLAIM "2 * x = 2 * y ==> x = (y::nat)") 1);
12486
0ed8bdd883e0 isatool expandshort;
wenzelm
parents: 12196
diff changeset
   223
by (stac lemma_even_div 1);
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   224
by (auto_tac (claset(),simpset() addsimps [even_mult_two_ex]));
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   225
qed "lemma_even_div2";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   226
Addsimps [lemma_even_div2];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   227
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   228
Goal "~even n ==> (n + 1) div 2 = Suc (n div 2)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   229
by (rtac (CLAIM "2 * x = 2 * y ==> x = (y::nat)") 1);
12486
0ed8bdd883e0 isatool expandshort;
wenzelm
parents: 12196
diff changeset
   230
by (stac lemma_not_even_div 1);
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   231
by (auto_tac (claset(),simpset() addsimps [even_not_odd,
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   232
    odd_Suc_mult_two_ex])); 
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   233
by (cut_inst_tac [("m","Suc(2*m)"),("n","2")] mod_div_equality 1); 
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   234
by Auto_tac; 
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   235
qed "lemma_not_even_div2";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   236
Addsimps [lemma_not_even_div2];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   237
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   238
Goal "(Suc n) div 2 = 0 ==> even n";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   239
by (rtac ccontr 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   240
by (dtac lemma_not_even_div2 1 THEN Auto_tac);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   241
qed "Suc_n_div_two_zero_even";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   242
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   243
Goal "0 < n ==> even n = (~ even(n - 1))";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   244
by (case_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   245
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   246
qed "even_num_iff";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   247
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   248
Goal "0 < n ==> odd n = (~ odd(n - 1))";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   249
by (case_tac "n" 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   250
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   251
qed "odd_num_iff";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   252
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   253
(* Some mod and div stuff *)
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   254
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   255
Goal "n ~= (0::nat) ==> (m = m div n * n + m mod n) & m mod n < n";
13517
42efec18f5b2 Added div+mod cancelling simproc
nipkow
parents: 13153
diff changeset
   256
by (auto_tac (claset() addIs [mod_less_divisor],simpset()));
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   257
qed "mod_div_eq_less";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   258
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   259
Goal "(k*n + m) mod n = m mod (n::nat)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   260
by (simp_tac (simpset() addsimps mult_ac @ add_ac) 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   261
qed "mod_mult_self3";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   262
Addsimps [mod_mult_self3];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   263
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   264
Goal "Suc (k*n + m) mod n = Suc m mod n";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   265
by (rtac (CLAIM "Suc (m + n) = (m + Suc n)" RS ssubst) 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   266
by (rtac mod_mult_self3 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   267
qed "mod_mult_self4";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   268
Addsimps [mod_mult_self4];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   269
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   270
Goal "Suc m mod n = Suc (m mod n) mod n";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   271
by (cut_inst_tac [("d'","Suc (m mod n) mod n")] (CLAIM "EX d. d' = d") 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   272
by (etac exE 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   273
by (Asm_simp_tac 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   274
by (res_inst_tac [("t","m"),("n1","n")] (mod_div_equality RS subst) 1);
13517
42efec18f5b2 Added div+mod cancelling simproc
nipkow
parents: 13153
diff changeset
   275
by (auto_tac (claset(),simpset() delsimprocs [cancel_div_mod_proc]));
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   276
qed "mod_Suc_eq_Suc_mod";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   277
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   278
Goal "even n = (even (n mod 4))";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   279
by (cut_inst_tac [("d'","(even (n mod 4))")] (CLAIM "EX d. d' = d") 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   280
by (etac exE 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   281
by (Asm_simp_tac 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   282
by (res_inst_tac [("t","n"),("n1","4")] (mod_div_equality RS subst) 1);
13517
42efec18f5b2 Added div+mod cancelling simproc
nipkow
parents: 13153
diff changeset
   283
by (auto_tac (claset(),simpset() addsimps [even_mult,even_num_iff] delsimprocs [cancel_div_mod_proc]));
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   284
qed "even_even_mod_4_iff";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   285
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   286
Goal "odd n = (odd (n mod 4))";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   287
by (auto_tac (claset(),simpset() addsimps [odd_not_even,
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   288
    even_even_mod_4_iff RS sym]));
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   289
qed "odd_odd_mod_4_iff";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   290
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   291
Goal "odd n ==> ((-1) ^ n) = (-1::real)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   292
by (auto_tac (claset(),simpset() addsimps [odd_Suc_mult_two_ex]));
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   293
qed "odd_realpow_minus_one";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   294
Addsimps [odd_realpow_minus_one];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   295
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   296
Goal "even(4*n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   297
by (auto_tac (claset(),simpset() addsimps [even_mult_two_ex]));
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   298
qed "even_4n";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   299
Addsimps [even_4n];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   300
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   301
Goal "n mod 4 = 0 ==> even(n div 2)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   302
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   303
qed "lemma_even_div_2";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   304
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   305
Goal "n mod 4 = 0 ==> even(n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   306
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   307
qed "lemma_mod_4_even_n";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   308
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   309
Goal "n mod 4 = 1 ==> odd(n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   310
by (res_inst_tac [("t","n"),("n1","4")] (mod_div_equality RS subst) 1);
13517
42efec18f5b2 Added div+mod cancelling simproc
nipkow
parents: 13153
diff changeset
   311
by (auto_tac (claset(),simpset() addsimps [odd_num_iff] delsimprocs [cancel_div_mod_proc]));
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   312
qed "lemma_mod_4_odd_n";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   313
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   314
Goal "n mod 4 = 2 ==> even(n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   315
by (res_inst_tac [("t","n"),("n1","4")] (mod_div_equality RS subst) 1);
13517
42efec18f5b2 Added div+mod cancelling simproc
nipkow
parents: 13153
diff changeset
   316
by (auto_tac (claset(),simpset() addsimps [even_num_iff] delsimprocs [cancel_div_mod_proc]));
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   317
qed "lemma_mod_4_even_n2";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   318
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   319
Goal "n mod 4 = 3 ==> odd(n)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   320
by (res_inst_tac [("t","n"),("n1","4")] (mod_div_equality RS subst) 1);
13517
42efec18f5b2 Added div+mod cancelling simproc
nipkow
parents: 13153
diff changeset
   321
by (auto_tac (claset(),simpset() addsimps [odd_num_iff] delsimprocs [cancel_div_mod_proc]));
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   322
qed "lemma_mod_4_odd_n2";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   323
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   324
Goal "even n ==> ((-1) ^ n) = (1::real)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   325
by (auto_tac (claset(),simpset() addsimps [even_mult_two_ex]));
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   326
qed "even_realpow_minus_one";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   327
Addsimps [even_realpow_minus_one];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   328
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   329
Goal "((4 * n) + 2) div 2 = (2::nat) * n + 1";
13153
4b052946b41c arith can now deal with div 2 and mod 2.
nipkow
parents: 13151
diff changeset
   330
by (arith_tac 1);
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   331
qed "lemma_4n_add_2_div_2_eq";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   332
Addsimps [lemma_4n_add_2_div_2_eq];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   333
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   334
Goal "(Suc(Suc(4 * n))) div 2 = (2::nat) * n + 1";
13153
4b052946b41c arith can now deal with div 2 and mod 2.
nipkow
parents: 13151
diff changeset
   335
by (arith_tac 1);
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   336
qed "lemma_Suc_Suc_4n_div_2_eq";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   337
Addsimps [lemma_Suc_Suc_4n_div_2_eq];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   338
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   339
Goal "(Suc(Suc(n * 4))) div 2 = (2::nat) * n + 1";
13153
4b052946b41c arith can now deal with div 2 and mod 2.
nipkow
parents: 13151
diff changeset
   340
by (arith_tac 1);
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   341
qed "lemma_Suc_Suc_4n_div_2_eq2";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   342
Addsimps [lemma_Suc_Suc_4n_div_2_eq2];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   343
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   344
Goal "n mod 4 = 3 ==> odd((n - 1) div 2)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   345
by (res_inst_tac [("t","n"),("n1","4")] (mod_div_equality RS subst) 1);
13517
42efec18f5b2 Added div+mod cancelling simproc
nipkow
parents: 13153
diff changeset
   346
by (asm_full_simp_tac (simpset() addsimps [odd_num_iff] delsimprocs [cancel_div_mod_proc]) 1);
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   347
val lemma_odd_mod_4_div_2 = result();
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   348
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   349
Goal "(4 * n) div 2 = (2::nat) * n";
13153
4b052946b41c arith can now deal with div 2 and mod 2.
nipkow
parents: 13151
diff changeset
   350
by (arith_tac 1);
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   351
qed "lemma_4n_div_2_eq";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   352
Addsimps [lemma_4n_div_2_eq];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   353
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   354
Goal "(n  * 4) div 2 = (2::nat) * n";
13153
4b052946b41c arith can now deal with div 2 and mod 2.
nipkow
parents: 13151
diff changeset
   355
by (arith_tac 1);
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   356
qed "lemma_4n_div_2_eq2";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   357
Addsimps [lemma_4n_div_2_eq2];
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   358
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   359
Goal "n mod 4 = 1 ==> even ((n - 1) div 2)";
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   360
by (res_inst_tac [("t","n"),("n1","4")] (mod_div_equality RS subst) 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   361
by (dtac ssubst 1 THEN assume_tac 2);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   362
by (rtac ((CLAIM "(n::nat) + 1 - 1 = n") RS ssubst) 1);
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   363
by Auto_tac;
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   364
val lemma_even_mod_4_div_2 = result();
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   365
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   366