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