src/HOL/Hyperreal/EvenOdd.thy
author obua
Sun, 09 May 2004 23:04:36 +0200
changeset 14722 8e739a6eaf11
parent 14435 9e22eeccf129
child 15131 c69542757a4d
permissions -rw-r--r--
replaced apply-style proof for instance Multiset :: plus_ac0 by recommended Isar proof style
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     1
(*  Title       : EvenOdd.thy
14435
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
     2
    ID:         $Id$
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     3
    Author      : Jacques D. Fleuriot  
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     4
    Copyright   : 1999  University of Edinburgh
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     5
*)
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
     6
14435
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
     7
header{*Even and Odd Numbers: Compatibility file for Parity*}
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
     8
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
     9
theory EvenOdd = NthRoot:
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    10
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    11
subsection{*General Lemmas About Division*}
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    12
14435
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    13
lemma Suc_times_mod_eq: "1<k ==> Suc (k * m) mod k = 1" 
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    14
apply (induct_tac "m")
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    15
apply (simp_all add: mod_Suc)
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    16
done
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    17
14435
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    18
declare Suc_times_mod_eq [of "number_of w", standard, simp]
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    19
14435
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    20
lemma [simp]: "n div k \<le> (Suc n) div k"
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    21
by (simp add: div_le_mono) 
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    22
14435
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    23
lemma Suc_n_div_2_gt_zero [simp]: "(0::nat) < n ==> 0 < (n + 1) div 2"
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    24
by arith
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    25
14435
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    26
lemma div_2_gt_zero [simp]: "(1::nat) < n ==> 0 < n div 2" 
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    27
by arith
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    28
14435
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    29
lemma mod_mult_self3 [simp]: "(k*n + m) mod n = m mod (n::nat)"
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    30
by (simp add: mult_ac add_ac)
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    31
14435
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    32
lemma mod_mult_self4 [simp]: "Suc (k*n + m) mod n = Suc m mod n"
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    33
proof -
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    34
  have "Suc (k * n + m) mod n = (k * n + Suc m) mod n" by simp
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    35
  also have "... = Suc m mod n" by (rule mod_mult_self3) 
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    36
  finally show ?thesis .
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    37
qed
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    38
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    39
lemma mod_Suc_eq_Suc_mod: "Suc m mod n = Suc (m mod n) mod n"
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    40
apply (subst mod_Suc [of m]) 
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    41
apply (subst mod_Suc [of "m mod n"], simp) 
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    42
done
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    43
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    44
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    45
subsection{*More Even/Odd Results*}
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    46
 
14435
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    47
lemma even_mult_two_ex: "even(n) = (\<exists>m::nat. n = 2*m)"
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    48
by (simp add: even_nat_equiv_def2 numeral_2_eq_2)
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    49
14435
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    50
lemma odd_Suc_mult_two_ex: "odd(n) = (\<exists>m. n = Suc (2*m))"
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    51
by (simp add: odd_nat_equiv_def2 numeral_2_eq_2)
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    52
14435
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    53
lemma even_add [simp]: "even(m + n::nat) = (even m = even n)" 
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    54
by auto
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    55
14435
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    56
lemma odd_add [simp]: "odd(m + n::nat) = (odd m \<noteq> odd n)"
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    57
by auto
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    58
14435
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    59
lemma lemma_even_div2 [simp]: "even (n::nat) ==> (n + 1) div 2 = n div 2"
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    60
apply (simp add: numeral_2_eq_2) 
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    61
apply (subst div_Suc)  
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    62
apply (simp add: even_nat_mod_two_eq_zero) 
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    63
done
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    64
14435
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    65
lemma lemma_not_even_div2 [simp]: "~even n ==> (n + 1) div 2 = Suc (n div 2)"
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    66
apply (simp add: numeral_2_eq_2) 
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    67
apply (subst div_Suc)  
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    68
apply (simp add: odd_nat_mod_two_eq_one) 
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    69
done
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    70
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    71
lemma even_num_iff: "0 < n ==> even n = (~ even(n - 1 :: nat))" 
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    72
by (case_tac "n", auto)
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    73
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    74
lemma even_even_mod_4_iff: "even (n::nat) = even (n mod 4)"
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    75
apply (induct n, simp)
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    76
apply (subst mod_Suc, simp) 
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    77
done
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
    78
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    79
lemma lemma_odd_mod_4_div_2: "n mod 4 = (3::nat) ==> odd((n - 1) div 2)"
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    80
apply (rule_tac t = n and n1 = 4 in mod_div_equality [THEN subst])
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    81
apply (simp add: even_num_iff)
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    82
done
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    83
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    84
lemma lemma_even_mod_4_div_2: "n mod 4 = (1::nat) ==> even ((n - 1) div 2)"
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    85
by (rule_tac t = n and n1 = 4 in mod_div_equality [THEN subst], simp)
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    86
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    87
ML
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    88
{*
14435
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    89
val even_nat_Suc = thm"Parity.even_nat_Suc";
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    90
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    91
val even_mult_two_ex = thm "even_mult_two_ex";
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    92
val odd_Suc_mult_two_ex = thm "odd_Suc_mult_two_ex";
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    93
val even_add = thm "even_add";
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    94
val odd_add = thm "odd_add";
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    95
val Suc_n_div_2_gt_zero = thm "Suc_n_div_2_gt_zero";
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    96
val div_2_gt_zero = thm "div_2_gt_zero";
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
    97
val even_num_iff = thm "even_num_iff";
14435
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    98
val nat_mod_div_trivial = thm "nat_mod_div_trivial";
9e22eeccf129 Conversion of Poly to Isar script, and other tidying of HOL/Hyperreal
paulson
parents: 14430
diff changeset
    99
val nat_mod_mod_trivial = thm "nat_mod_mod_trivial";
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
   100
val mod_Suc_eq_Suc_mod = thm "mod_Suc_eq_Suc_mod";
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
   101
val even_even_mod_4_iff = thm "even_even_mod_4_iff";
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
   102
val lemma_odd_mod_4_div_2 = thm "lemma_odd_mod_4_div_2";
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
   103
val lemma_even_mod_4_div_2 = thm "lemma_even_mod_4_div_2";
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 12196
diff changeset
   104
*}
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   105
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   106
end
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents:
diff changeset
   107