src/HOL/Numeral_Simprocs.thy
author haftmann
Thu, 11 Mar 2010 14:38:20 +0100
changeset 35724 178ad68f93ed
parent 33366 b0096ac3b731
child 37886 2f9d3fc1a8ac
permissions -rw-r--r--
fixed typo
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33366
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
     1
(* Author: Various *)
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
     2
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
     3
header {* Combination and Cancellation Simprocs for Numeral Expressions *}
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
     4
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
     5
theory Numeral_Simprocs
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
     6
imports Divides
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
     7
uses
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
     8
  "~~/src/Provers/Arith/assoc_fold.ML"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
     9
  "~~/src/Provers/Arith/cancel_numerals.ML"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    10
  "~~/src/Provers/Arith/combine_numerals.ML"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    11
  "~~/src/Provers/Arith/cancel_numeral_factor.ML"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    12
  "~~/src/Provers/Arith/extract_common_term.ML"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    13
  ("Tools/numeral_simprocs.ML")
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    14
  ("Tools/nat_numeral_simprocs.ML")
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    15
begin
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    16
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    17
declare split_div [of _ _ "number_of k", standard, arith_split]
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    18
declare split_mod [of _ _ "number_of k", standard, arith_split]
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    19
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    20
text {* For @{text combine_numerals} *}
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    21
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    22
lemma left_add_mult_distrib: "i*u + (j*u + k) = (i+j)*u + (k::nat)"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    23
by (simp add: add_mult_distrib)
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    24
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    25
text {* For @{text cancel_numerals} *}
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    26
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    27
lemma nat_diff_add_eq1:
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    28
     "j <= (i::nat) ==> ((i*u + m) - (j*u + n)) = (((i-j)*u + m) - n)"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    29
by (simp split add: nat_diff_split add: add_mult_distrib)
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    30
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    31
lemma nat_diff_add_eq2:
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    32
     "i <= (j::nat) ==> ((i*u + m) - (j*u + n)) = (m - ((j-i)*u + n))"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    33
by (simp split add: nat_diff_split add: add_mult_distrib)
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    34
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    35
lemma nat_eq_add_iff1:
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    36
     "j <= (i::nat) ==> (i*u + m = j*u + n) = ((i-j)*u + m = n)"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    37
by (auto split add: nat_diff_split simp add: add_mult_distrib)
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    38
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    39
lemma nat_eq_add_iff2:
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    40
     "i <= (j::nat) ==> (i*u + m = j*u + n) = (m = (j-i)*u + n)"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    41
by (auto split add: nat_diff_split simp add: add_mult_distrib)
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    42
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    43
lemma nat_less_add_iff1:
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    44
     "j <= (i::nat) ==> (i*u + m < j*u + n) = ((i-j)*u + m < n)"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    45
by (auto split add: nat_diff_split simp add: add_mult_distrib)
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    46
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    47
lemma nat_less_add_iff2:
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    48
     "i <= (j::nat) ==> (i*u + m < j*u + n) = (m < (j-i)*u + n)"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    49
by (auto split add: nat_diff_split simp add: add_mult_distrib)
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    50
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    51
lemma nat_le_add_iff1:
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    52
     "j <= (i::nat) ==> (i*u + m <= j*u + n) = ((i-j)*u + m <= n)"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    53
by (auto split add: nat_diff_split simp add: add_mult_distrib)
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    54
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    55
lemma nat_le_add_iff2:
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    56
     "i <= (j::nat) ==> (i*u + m <= j*u + n) = (m <= (j-i)*u + n)"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    57
by (auto split add: nat_diff_split simp add: add_mult_distrib)
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    58
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    59
text {* For @{text cancel_numeral_factors} *}
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    60
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    61
lemma nat_mult_le_cancel1: "(0::nat) < k ==> (k*m <= k*n) = (m<=n)"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    62
by auto
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    63
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    64
lemma nat_mult_less_cancel1: "(0::nat) < k ==> (k*m < k*n) = (m<n)"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    65
by auto
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    66
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    67
lemma nat_mult_eq_cancel1: "(0::nat) < k ==> (k*m = k*n) = (m=n)"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    68
by auto
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    69
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    70
lemma nat_mult_div_cancel1: "(0::nat) < k ==> (k*m) div (k*n) = (m div n)"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    71
by auto
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    72
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    73
lemma nat_mult_dvd_cancel_disj[simp]:
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    74
  "(k*m) dvd (k*n) = (k=0 | m dvd (n::nat))"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    75
by(auto simp: dvd_eq_mod_eq_0 mod_mult_distrib2[symmetric])
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    76
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    77
lemma nat_mult_dvd_cancel1: "0 < k \<Longrightarrow> (k*m) dvd (k*n::nat) = (m dvd n)"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    78
by(auto)
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    79
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    80
text {* For @{text cancel_factor} *}
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    81
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    82
lemma nat_mult_le_cancel_disj: "(k*m <= k*n) = ((0::nat) < k --> m<=n)"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    83
by auto
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    84
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    85
lemma nat_mult_less_cancel_disj: "(k*m < k*n) = ((0::nat) < k & m<n)"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    86
by auto
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    87
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    88
lemma nat_mult_eq_cancel_disj: "(k*m = k*n) = (k = (0::nat) | m=n)"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    89
by auto
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    90
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    91
lemma nat_mult_div_cancel_disj[simp]:
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    92
     "(k*m) div (k*n) = (if k = (0::nat) then 0 else m div n)"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    93
by (simp add: nat_mult_div_cancel1)
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    94
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    95
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    96
use "Tools/numeral_simprocs.ML"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    97
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    98
use "Tools/nat_numeral_simprocs.ML"
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
    99
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   100
declaration {* 
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   101
  K (Lin_Arith.add_simps (@{thms neg_simps} @ [@{thm Suc_nat_number_of}, @{thm int_nat_number_of}])
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   102
  #> Lin_Arith.add_simps (@{thms ring_distribs} @ [@{thm Let_number_of}, @{thm Let_0}, @{thm Let_1},
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   103
     @{thm nat_0}, @{thm nat_1},
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   104
     @{thm add_nat_number_of}, @{thm diff_nat_number_of}, @{thm mult_nat_number_of},
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   105
     @{thm eq_nat_number_of}, @{thm less_nat_number_of}, @{thm le_number_of_eq_not_less},
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   106
     @{thm le_Suc_number_of}, @{thm le_number_of_Suc},
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   107
     @{thm less_Suc_number_of}, @{thm less_number_of_Suc},
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   108
     @{thm Suc_eq_number_of}, @{thm eq_number_of_Suc},
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   109
     @{thm mult_Suc}, @{thm mult_Suc_right},
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   110
     @{thm add_Suc}, @{thm add_Suc_right},
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   111
     @{thm eq_number_of_0}, @{thm eq_0_number_of}, @{thm less_0_number_of},
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   112
     @{thm of_int_number_of_eq}, @{thm of_nat_number_of_eq}, @{thm nat_number_of},
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   113
     @{thm if_True}, @{thm if_False}])
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   114
  #> Lin_Arith.add_simprocs (Numeral_Simprocs.assoc_fold_simproc
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   115
      :: Numeral_Simprocs.combine_numerals
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   116
      :: Numeral_Simprocs.cancel_numerals)
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   117
  #> Lin_Arith.add_simprocs (Nat_Numeral_Simprocs.combine_numerals :: Nat_Numeral_Simprocs.cancel_numerals))
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   118
*}
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   119
b0096ac3b731 dedicated theory for loading numeral simprocs
haftmann
parents:
diff changeset
   120
end