src/HOL/Tools/nat_simprocs.ML
author nipkow
Sun, 22 Mar 2009 19:36:04 +0100
changeset 30649 57753e0ec1d4
parent 30518 07b45c1aa788
child 30685 dd5fe091ff04
permissions -rw-r--r--
1. New cancellation simprocs for common factors in inequations 2. Updated the documentation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents: 29039
diff changeset
     1
(*  Title:      HOL/Tools/nat_simprocs.ML
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     3
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     4
Simprocs for nat numerals.
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     5
*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     6
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     7
structure Nat_Numeral_Simprocs =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     8
struct
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     9
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    10
(*Maps n to #n for n = 0, 1, 2*)
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
    11
val numeral_syms = [@{thm nat_numeral_0_eq_0} RS sym, @{thm nat_numeral_1_eq_1} RS sym, @{thm numeral_2_eq_2} RS sym];
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    12
val numeral_sym_ss = HOL_ss addsimps numeral_syms;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    13
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    14
fun rename_numerals th =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    15
    simplify numeral_sym_ss (Thm.transfer (the_context ()) th);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    16
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    17
(*Utilities*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    18
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    19
fun mk_number n = HOLogic.number_of_const HOLogic.natT $ HOLogic.mk_numeral n;
24630
351a308ab58d simplified type int (eliminated IntInf.int, integer);
wenzelm
parents: 24431
diff changeset
    20
fun dest_number t = Int.max (0, snd (HOLogic.dest_number t));
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    21
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    22
fun find_first_numeral past (t::terms) =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    23
        ((dest_number t, t, rev past @ terms)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    24
         handle TERM _ => find_first_numeral (t::past) terms)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    25
  | find_first_numeral past [] = raise TERM("find_first_numeral", []);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    26
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    27
val zero = mk_number 0;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    28
val mk_plus = HOLogic.mk_binop @{const_name HOL.plus};
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    29
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    30
(*Thus mk_sum[t] yields t+0; longer sums don't have a trailing zero*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    31
fun mk_sum []        = zero
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    32
  | mk_sum [t,u]     = mk_plus (t, u)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    33
  | mk_sum (t :: ts) = mk_plus (t, mk_sum ts);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    34
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    35
(*this version ALWAYS includes a trailing zero*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    36
fun long_mk_sum []        = HOLogic.zero
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    37
  | long_mk_sum (t :: ts) = mk_plus (t, mk_sum ts);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    38
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    39
val dest_plus = HOLogic.dest_bin @{const_name HOL.plus} HOLogic.natT;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    40
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    41
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    42
(** Other simproc items **)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    43
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    44
val bin_simps =
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
    45
     [@{thm nat_numeral_0_eq_0} RS sym, @{thm nat_numeral_1_eq_1} RS sym,
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
    46
      @{thm add_nat_number_of}, @{thm nat_number_of_add_left}, 
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
    47
      @{thm diff_nat_number_of}, @{thm le_number_of_eq_not_less},
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
    48
      @{thm mult_nat_number_of}, @{thm nat_number_of_mult_left}, 
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
    49
      @{thm less_nat_number_of}, 
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
    50
      @{thm Let_number_of}, @{thm nat_number_of}] @
29039
8b9207f82a78 separate neg_simps from rel_simps
huffman
parents: 28952
diff changeset
    51
     @{thms arith_simps} @ @{thms rel_simps} @ @{thms neg_simps};
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    52
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    53
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    54
(*** CancelNumerals simprocs ***)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    55
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    56
val one = mk_number 1;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    57
val mk_times = HOLogic.mk_binop @{const_name HOL.times};
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    58
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    59
fun mk_prod [] = one
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    60
  | mk_prod [t] = t
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    61
  | mk_prod (t :: ts) = if t = one then mk_prod ts
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    62
                        else mk_times (t, mk_prod ts);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    63
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    64
val dest_times = HOLogic.dest_bin @{const_name HOL.times} HOLogic.natT;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    65
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    66
fun dest_prod t =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    67
      let val (t,u) = dest_times t
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    68
      in  dest_prod t @ dest_prod u  end
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    69
      handle TERM _ => [t];
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    70
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    71
(*DON'T do the obvious simplifications; that would create special cases*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    72
fun mk_coeff (k,t) = mk_times (mk_number k, t);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    73
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    74
(*Express t as a product of (possibly) a numeral with other factors, sorted*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    75
fun dest_coeff t =
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents: 29039
diff changeset
    76
    let val ts = sort TermOrd.term_ord (dest_prod t)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    77
        val (n, _, ts') = find_first_numeral [] ts
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    78
                          handle TERM _ => (1, one, ts)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    79
    in (n, mk_prod ts') end;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    80
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    81
(*Find first coefficient-term THAT MATCHES u*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    82
fun find_first_coeff past u [] = raise TERM("find_first_coeff", [])
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    83
  | find_first_coeff past u (t::terms) =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    84
        let val (n,u') = dest_coeff t
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    85
        in  if u aconv u' then (n, rev past @ terms)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    86
                          else find_first_coeff (t::past) u terms
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    87
        end
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    88
        handle TERM _ => find_first_coeff (t::past) u terms;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    89
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    90
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    91
(*Split up a sum into the list of its constituent terms, on the way removing any
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    92
  Sucs and counting them.*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    93
fun dest_Suc_sum (Const ("Suc", _) $ t, (k,ts)) = dest_Suc_sum (t, (k+1,ts))
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    94
  | dest_Suc_sum (t, (k,ts)) = 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    95
      let val (t1,t2) = dest_plus t
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    96
      in  dest_Suc_sum (t1, dest_Suc_sum (t2, (k,ts)))  end
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    97
      handle TERM _ => (k, t::ts);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    98
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    99
(*Code for testing whether numerals are already used in the goal*)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25481
diff changeset
   100
fun is_numeral (Const(@{const_name Int.number_of}, _) $ w) = true
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   101
  | is_numeral _ = false;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   102
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   103
fun prod_has_numeral t = exists is_numeral (dest_prod t);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   104
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   105
(*The Sucs found in the term are converted to a binary numeral. If relaxed is false,
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   106
  an exception is raised unless the original expression contains at least one
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   107
  numeral in a coefficient position.  This prevents nat_combine_numerals from 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   108
  introducing numerals to goals.*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   109
fun dest_Sucs_sum relaxed t = 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   110
  let val (k,ts) = dest_Suc_sum (t,(0,[]))
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   111
  in
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   112
     if relaxed orelse exists prod_has_numeral ts then 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   113
       if k=0 then ts
24630
351a308ab58d simplified type int (eliminated IntInf.int, integer);
wenzelm
parents: 24431
diff changeset
   114
       else mk_number k :: ts
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   115
     else raise TERM("Nat_Numeral_Simprocs.dest_Sucs_sum", [t])
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   116
  end;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   117
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   118
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   119
(*Simplify 1*n and n*1 to n*)
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   120
val add_0s  = map rename_numerals [@{thm add_0}, @{thm add_0_right}];
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   121
val mult_1s = map rename_numerals [@{thm nat_mult_1}, @{thm nat_mult_1_right}];
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   122
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   123
(*Final simplification: cancel + and *; replace Numeral0 by 0 and Numeral1 by 1*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   124
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   125
(*And these help the simproc return False when appropriate, which helps
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   126
  the arith prover.*)
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   127
val contra_rules = [@{thm add_Suc}, @{thm add_Suc_right}, @{thm Zero_not_Suc},
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   128
  @{thm Suc_not_Zero}, @{thm le_0_eq}];
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   129
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   130
val simplify_meta_eq =
30518
07b45c1aa788 moved some generic nonsense to arith_data.ML
haftmann
parents: 30496
diff changeset
   131
    Arith_Data.simplify_meta_eq
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   132
        ([@{thm nat_numeral_0_eq_0}, @{thm numeral_1_eq_Suc_0}, @{thm add_0}, @{thm add_0_right},
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   133
          @{thm mult_0}, @{thm mult_0_right}, @{thm mult_1}, @{thm mult_1_right}] @ contra_rules);
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   134
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   135
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   136
(*** Applying CancelNumeralsFun ***)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   137
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   138
structure CancelNumeralsCommon =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   139
  struct
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   140
  val mk_sum            = (fn T:typ => mk_sum)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   141
  val dest_sum          = dest_Sucs_sum true
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   142
  val mk_coeff          = mk_coeff
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   143
  val dest_coeff        = dest_coeff
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   144
  val find_first_coeff  = find_first_coeff []
30518
07b45c1aa788 moved some generic nonsense to arith_data.ML
haftmann
parents: 30496
diff changeset
   145
  val trans_tac         = K Arith_Data.trans_tac
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   146
30518
07b45c1aa788 moved some generic nonsense to arith_data.ML
haftmann
parents: 30496
diff changeset
   147
  val norm_ss1 = Int_Numeral_Simprocs.num_ss addsimps numeral_syms @ add_0s @ mult_1s @
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   148
    [@{thm Suc_eq_add_numeral_1_left}] @ @{thms add_ac}
30518
07b45c1aa788 moved some generic nonsense to arith_data.ML
haftmann
parents: 30496
diff changeset
   149
  val norm_ss2 = Int_Numeral_Simprocs.num_ss addsimps bin_simps @ @{thms add_ac} @ @{thms mult_ac}
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   150
  fun norm_tac ss = 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   151
    ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss1))
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   152
    THEN ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss2))
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   153
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   154
  val numeral_simp_ss = HOL_ss addsimps add_0s @ bin_simps;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   155
  fun numeral_simp_tac ss = ALLGOALS (simp_tac (Simplifier.inherit_context ss numeral_simp_ss));
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   156
  val simplify_meta_eq  = simplify_meta_eq
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   157
  end;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   158
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   159
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   160
structure EqCancelNumerals = CancelNumeralsFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   161
 (open CancelNumeralsCommon
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   162
  val prove_conv = Arith_Data.prove_conv
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   163
  val mk_bal   = HOLogic.mk_eq
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   164
  val dest_bal = HOLogic.dest_bin "op =" HOLogic.natT
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   165
  val bal_add1 = @{thm nat_eq_add_iff1} RS trans
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   166
  val bal_add2 = @{thm nat_eq_add_iff2} RS trans
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   167
);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   168
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   169
structure LessCancelNumerals = CancelNumeralsFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   170
 (open CancelNumeralsCommon
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   171
  val prove_conv = Arith_Data.prove_conv
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   172
  val mk_bal   = HOLogic.mk_binrel @{const_name HOL.less}
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   173
  val dest_bal = HOLogic.dest_bin @{const_name HOL.less} HOLogic.natT
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   174
  val bal_add1 = @{thm nat_less_add_iff1} RS trans
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   175
  val bal_add2 = @{thm nat_less_add_iff2} RS trans
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   176
);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   177
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   178
structure LeCancelNumerals = CancelNumeralsFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   179
 (open CancelNumeralsCommon
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   180
  val prove_conv = Arith_Data.prove_conv
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   181
  val mk_bal   = HOLogic.mk_binrel @{const_name HOL.less_eq}
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   182
  val dest_bal = HOLogic.dest_bin @{const_name HOL.less_eq} HOLogic.natT
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   183
  val bal_add1 = @{thm nat_le_add_iff1} RS trans
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   184
  val bal_add2 = @{thm nat_le_add_iff2} RS trans
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   185
);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   186
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   187
structure DiffCancelNumerals = CancelNumeralsFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   188
 (open CancelNumeralsCommon
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   189
  val prove_conv = Arith_Data.prove_conv
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   190
  val mk_bal   = HOLogic.mk_binop @{const_name HOL.minus}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   191
  val dest_bal = HOLogic.dest_bin @{const_name HOL.minus} HOLogic.natT
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   192
  val bal_add1 = @{thm nat_diff_add_eq1} RS trans
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   193
  val bal_add2 = @{thm nat_diff_add_eq2} RS trans
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   194
);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   195
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   196
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   197
val cancel_numerals =
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   198
  map Arith_Data.prep_simproc
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   199
   [("nateq_cancel_numerals",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   200
     ["(l::nat) + m = n", "(l::nat) = m + n",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   201
      "(l::nat) * m = n", "(l::nat) = m * n",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   202
      "Suc m = n", "m = Suc n"],
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   203
     K EqCancelNumerals.proc),
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   204
    ("natless_cancel_numerals",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   205
     ["(l::nat) + m < n", "(l::nat) < m + n",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   206
      "(l::nat) * m < n", "(l::nat) < m * n",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   207
      "Suc m < n", "m < Suc n"],
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   208
     K LessCancelNumerals.proc),
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   209
    ("natle_cancel_numerals",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   210
     ["(l::nat) + m <= n", "(l::nat) <= m + n",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   211
      "(l::nat) * m <= n", "(l::nat) <= m * n",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   212
      "Suc m <= n", "m <= Suc n"],
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   213
     K LeCancelNumerals.proc),
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   214
    ("natdiff_cancel_numerals",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   215
     ["((l::nat) + m) - n", "(l::nat) - (m + n)",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   216
      "(l::nat) * m - n", "(l::nat) - m * n",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   217
      "Suc m - n", "m - Suc n"],
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   218
     K DiffCancelNumerals.proc)];
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   219
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   220
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   221
(*** Applying CombineNumeralsFun ***)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   222
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   223
structure CombineNumeralsData =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   224
  struct
24630
351a308ab58d simplified type int (eliminated IntInf.int, integer);
wenzelm
parents: 24431
diff changeset
   225
  type coeff            = int
351a308ab58d simplified type int (eliminated IntInf.int, integer);
wenzelm
parents: 24431
diff changeset
   226
  val iszero            = (fn x => x = 0)
351a308ab58d simplified type int (eliminated IntInf.int, integer);
wenzelm
parents: 24431
diff changeset
   227
  val add               = op +
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   228
  val mk_sum            = (fn T:typ => long_mk_sum)  (*to work for 2*x + 3*x *)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   229
  val dest_sum          = dest_Sucs_sum false
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   230
  val mk_coeff          = mk_coeff
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   231
  val dest_coeff        = dest_coeff
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   232
  val left_distrib      = @{thm left_add_mult_distrib} RS trans
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   233
  val prove_conv        = Arith_Data.prove_conv_nohyps
30518
07b45c1aa788 moved some generic nonsense to arith_data.ML
haftmann
parents: 30496
diff changeset
   234
  val trans_tac         = K Arith_Data.trans_tac
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   235
30518
07b45c1aa788 moved some generic nonsense to arith_data.ML
haftmann
parents: 30496
diff changeset
   236
  val norm_ss1 = Int_Numeral_Simprocs.num_ss addsimps numeral_syms @ add_0s @ mult_1s @ [@{thm Suc_eq_add_numeral_1}] @ @{thms add_ac}
07b45c1aa788 moved some generic nonsense to arith_data.ML
haftmann
parents: 30496
diff changeset
   237
  val norm_ss2 = Int_Numeral_Simprocs.num_ss addsimps bin_simps @ @{thms add_ac} @ @{thms mult_ac}
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   238
  fun norm_tac ss =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   239
    ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss1))
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   240
    THEN ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss2))
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   241
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   242
  val numeral_simp_ss = HOL_ss addsimps add_0s @ bin_simps;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   243
  fun numeral_simp_tac ss = ALLGOALS (simp_tac (Simplifier.inherit_context ss numeral_simp_ss))
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   244
  val simplify_meta_eq  = simplify_meta_eq
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   245
  end;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   246
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   247
structure CombineNumerals = CombineNumeralsFun(CombineNumeralsData);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   248
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   249
val combine_numerals =
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   250
  Arith_Data.prep_simproc ("nat_combine_numerals", ["(i::nat) + j", "Suc (i + j)"], K CombineNumerals.proc);
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   251
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   252
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   253
(*** Applying CancelNumeralFactorFun ***)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   254
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   255
structure CancelNumeralFactorCommon =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   256
  struct
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   257
  val mk_coeff          = mk_coeff
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   258
  val dest_coeff        = dest_coeff
30518
07b45c1aa788 moved some generic nonsense to arith_data.ML
haftmann
parents: 30496
diff changeset
   259
  val trans_tac         = K Arith_Data.trans_tac
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   260
30518
07b45c1aa788 moved some generic nonsense to arith_data.ML
haftmann
parents: 30496
diff changeset
   261
  val norm_ss1 = Int_Numeral_Simprocs.num_ss addsimps
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   262
    numeral_syms @ add_0s @ mult_1s @ [@{thm Suc_eq_add_numeral_1_left}] @ @{thms add_ac}
30518
07b45c1aa788 moved some generic nonsense to arith_data.ML
haftmann
parents: 30496
diff changeset
   263
  val norm_ss2 = Int_Numeral_Simprocs.num_ss addsimps bin_simps @ @{thms add_ac} @ @{thms mult_ac}
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   264
  fun norm_tac ss =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   265
    ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss1))
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   266
    THEN ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss2))
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   267
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   268
  val numeral_simp_ss = HOL_ss addsimps bin_simps
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   269
  fun numeral_simp_tac ss = ALLGOALS (simp_tac (Simplifier.inherit_context ss numeral_simp_ss))
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   270
  val simplify_meta_eq  = simplify_meta_eq
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   271
  end
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   272
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   273
structure DivCancelNumeralFactor = CancelNumeralFactorFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   274
 (open CancelNumeralFactorCommon
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   275
  val prove_conv = Arith_Data.prove_conv
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   276
  val mk_bal   = HOLogic.mk_binop @{const_name Divides.div}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   277
  val dest_bal = HOLogic.dest_bin @{const_name Divides.div} HOLogic.natT
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   278
  val cancel = @{thm nat_mult_div_cancel1} RS trans
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   279
  val neg_exchanges = false
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   280
)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   281
23969
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   282
structure DvdCancelNumeralFactor = CancelNumeralFactorFun
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   283
 (open CancelNumeralFactorCommon
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   284
  val prove_conv = Arith_Data.prove_conv
27651
16a26996c30e moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents: 25919
diff changeset
   285
  val mk_bal   = HOLogic.mk_binrel @{const_name Ring_and_Field.dvd}
16a26996c30e moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents: 25919
diff changeset
   286
  val dest_bal = HOLogic.dest_bin @{const_name Ring_and_Field.dvd} HOLogic.natT
23969
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   287
  val cancel = @{thm nat_mult_dvd_cancel1} RS trans
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   288
  val neg_exchanges = false
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   289
)
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   290
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   291
structure EqCancelNumeralFactor = CancelNumeralFactorFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   292
 (open CancelNumeralFactorCommon
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   293
  val prove_conv = Arith_Data.prove_conv
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   294
  val mk_bal   = HOLogic.mk_eq
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   295
  val dest_bal = HOLogic.dest_bin "op =" HOLogic.natT
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   296
  val cancel = @{thm nat_mult_eq_cancel1} RS trans
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   297
  val neg_exchanges = false
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   298
)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   299
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   300
structure LessCancelNumeralFactor = CancelNumeralFactorFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   301
 (open CancelNumeralFactorCommon
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   302
  val prove_conv = Arith_Data.prove_conv
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   303
  val mk_bal   = HOLogic.mk_binrel @{const_name HOL.less}
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   304
  val dest_bal = HOLogic.dest_bin @{const_name HOL.less} HOLogic.natT
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   305
  val cancel = @{thm nat_mult_less_cancel1} RS trans
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   306
  val neg_exchanges = true
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   307
)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   308
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   309
structure LeCancelNumeralFactor = CancelNumeralFactorFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   310
 (open CancelNumeralFactorCommon
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   311
  val prove_conv = Arith_Data.prove_conv
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   312
  val mk_bal   = HOLogic.mk_binrel @{const_name HOL.less_eq}
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   313
  val dest_bal = HOLogic.dest_bin @{const_name HOL.less_eq} HOLogic.natT
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   314
  val cancel = @{thm nat_mult_le_cancel1} RS trans
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   315
  val neg_exchanges = true
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   316
)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   317
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   318
val cancel_numeral_factors =
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   319
  map Arith_Data.prep_simproc
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   320
   [("nateq_cancel_numeral_factors",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   321
     ["(l::nat) * m = n", "(l::nat) = m * n"],
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   322
     K EqCancelNumeralFactor.proc),
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   323
    ("natless_cancel_numeral_factors",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   324
     ["(l::nat) * m < n", "(l::nat) < m * n"],
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   325
     K LessCancelNumeralFactor.proc),
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   326
    ("natle_cancel_numeral_factors",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   327
     ["(l::nat) * m <= n", "(l::nat) <= m * n"],
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   328
     K LeCancelNumeralFactor.proc),
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   329
    ("natdiv_cancel_numeral_factors",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   330
     ["((l::nat) * m) div n", "(l::nat) div (m * n)"],
23969
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   331
     K DivCancelNumeralFactor.proc),
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   332
    ("natdvd_cancel_numeral_factors",
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   333
     ["((l::nat) * m) dvd n", "(l::nat) dvd (m * n)"],
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   334
     K DvdCancelNumeralFactor.proc)];
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   335
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   336
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   337
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   338
(*** Applying ExtractCommonTermFun ***)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   339
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   340
(*this version ALWAYS includes a trailing one*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   341
fun long_mk_prod []        = one
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   342
  | long_mk_prod (t :: ts) = mk_times (t, mk_prod ts);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   343
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   344
(*Find first term that matches u*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   345
fun find_first_t past u []         = raise TERM("find_first_t", [])
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   346
  | find_first_t past u (t::terms) =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   347
        if u aconv t then (rev past @ terms)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   348
        else find_first_t (t::past) u terms
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   349
        handle TERM _ => find_first_t (t::past) u terms;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   350
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   351
(** Final simplification for the CancelFactor simprocs **)
30518
07b45c1aa788 moved some generic nonsense to arith_data.ML
haftmann
parents: 30496
diff changeset
   352
val simplify_one = Arith_Data.simplify_meta_eq  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   353
  [@{thm mult_1_left}, @{thm mult_1_right}, @{thm div_1}, @{thm numeral_1_eq_Suc_0}];
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   354
30649
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   355
fun cancel_simplify_meta_eq ss cancel_th th =
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   356
    simplify_one ss (([th, cancel_th]) MRS trans);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   357
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   358
structure CancelFactorCommon =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   359
  struct
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   360
  val mk_sum            = (fn T:typ => long_mk_prod)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   361
  val dest_sum          = dest_prod
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   362
  val mk_coeff          = mk_coeff
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   363
  val dest_coeff        = dest_coeff
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   364
  val find_first        = find_first_t []
30518
07b45c1aa788 moved some generic nonsense to arith_data.ML
haftmann
parents: 30496
diff changeset
   365
  val trans_tac         = K Arith_Data.trans_tac
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   366
  val norm_ss = HOL_ss addsimps mult_1s @ @{thms mult_ac}
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   367
  fun norm_tac ss = ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss))
30649
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   368
  val simplify_meta_eq  = cancel_simplify_meta_eq
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   369
  end;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   370
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   371
structure EqCancelFactor = ExtractCommonTermFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   372
 (open CancelFactorCommon
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   373
  val prove_conv = Arith_Data.prove_conv
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   374
  val mk_bal   = HOLogic.mk_eq
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   375
  val dest_bal = HOLogic.dest_bin "op =" HOLogic.natT
30649
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   376
  val simp_conv = K(K (SOME @{thm nat_mult_eq_cancel_disj}))
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   377
);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   378
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   379
structure LessCancelFactor = ExtractCommonTermFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   380
 (open CancelFactorCommon
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   381
  val prove_conv = Arith_Data.prove_conv
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   382
  val mk_bal   = HOLogic.mk_binrel @{const_name HOL.less}
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   383
  val dest_bal = HOLogic.dest_bin @{const_name HOL.less} HOLogic.natT
30649
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   384
  val simp_conv = K(K (SOME @{thm nat_mult_less_cancel_disj}))
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   385
);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   386
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   387
structure LeCancelFactor = ExtractCommonTermFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   388
 (open CancelFactorCommon
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   389
  val prove_conv = Arith_Data.prove_conv
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   390
  val mk_bal   = HOLogic.mk_binrel @{const_name HOL.less_eq}
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   391
  val dest_bal = HOLogic.dest_bin @{const_name HOL.less_eq} HOLogic.natT
30649
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   392
  val simp_conv = K(K (SOME @{thm nat_mult_le_cancel_disj}))
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   393
);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   394
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   395
structure DivideCancelFactor = ExtractCommonTermFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   396
 (open CancelFactorCommon
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   397
  val prove_conv = Arith_Data.prove_conv
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   398
  val mk_bal   = HOLogic.mk_binop @{const_name Divides.div}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   399
  val dest_bal = HOLogic.dest_bin @{const_name Divides.div} HOLogic.natT
30649
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   400
  val simp_conv = K(K (SOME @{thm nat_mult_div_cancel_disj}))
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   401
);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   402
23969
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   403
structure DvdCancelFactor = ExtractCommonTermFun
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   404
 (open CancelFactorCommon
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   405
  val prove_conv = Arith_Data.prove_conv
27651
16a26996c30e moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents: 25919
diff changeset
   406
  val mk_bal   = HOLogic.mk_binrel @{const_name Ring_and_Field.dvd}
16a26996c30e moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents: 25919
diff changeset
   407
  val dest_bal = HOLogic.dest_bin @{const_name Ring_and_Field.dvd} HOLogic.natT
30649
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   408
  val simp_conv = K(K (SOME @{thm nat_mult_dvd_cancel_disj}))
23969
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   409
);
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   410
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   411
val cancel_factor =
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 29269
diff changeset
   412
  map Arith_Data.prep_simproc
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   413
   [("nat_eq_cancel_factor",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   414
     ["(l::nat) * m = n", "(l::nat) = m * n"],
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   415
     K EqCancelFactor.proc),
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   416
    ("nat_less_cancel_factor",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   417
     ["(l::nat) * m < n", "(l::nat) < m * n"],
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   418
     K LessCancelFactor.proc),
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   419
    ("nat_le_cancel_factor",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   420
     ["(l::nat) * m <= n", "(l::nat) <= m * n"],
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   421
     K LeCancelFactor.proc),
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   422
    ("nat_divide_cancel_factor",
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   423
     ["((l::nat) * m) div n", "(l::nat) div (m * n)"],
23969
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   424
     K DivideCancelFactor.proc),
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   425
    ("nat_dvd_cancel_factor",
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   426
     ["((l::nat) * m) dvd n", "(l::nat) dvd (m * n)"],
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   427
     K DvdCancelFactor.proc)];
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   428
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   429
end;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   430
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   431
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   432
Addsimprocs Nat_Numeral_Simprocs.cancel_numerals;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   433
Addsimprocs [Nat_Numeral_Simprocs.combine_numerals];
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   434
Addsimprocs Nat_Numeral_Simprocs.cancel_numeral_factors;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   435
Addsimprocs Nat_Numeral_Simprocs.cancel_factor;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   436
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   437
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   438
(*examples:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   439
print_depth 22;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   440
set timing;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   441
set trace_simp;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   442
fun test s = (Goal s; by (Simp_tac 1));
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   443
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   444
(*cancel_numerals*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   445
test "l +( 2) + (2) + 2 + (l + 2) + (oo  + 2) = (uu::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   446
test "(2*length xs < 2*length xs + j)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   447
test "(2*length xs < length xs * 2 + j)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   448
test "2*u = (u::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   449
test "2*u = Suc (u)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   450
test "(i + j + 12 + (k::nat)) - 15 = y";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   451
test "(i + j + 12 + (k::nat)) - 5 = y";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   452
test "Suc u - 2 = y";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   453
test "Suc (Suc (Suc u)) - 2 = y";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   454
test "(i + j + 2 + (k::nat)) - 1 = y";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   455
test "(i + j + 1 + (k::nat)) - 2 = y";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   456
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   457
test "(2*x + (u*v) + y) - v*3*u = (w::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   458
test "(2*x*u*v + 5 + (u*v)*4 + y) - v*u*4 = (w::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   459
test "(2*x*u*v + (u*v)*4 + y) - v*u = (w::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   460
test "Suc (Suc (2*x*u*v + u*4 + y)) - u = w";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   461
test "Suc ((u*v)*4) - v*3*u = w";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   462
test "Suc (Suc ((u*v)*3)) - v*3*u = w";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   463
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   464
test "(i + j + 12 + (k::nat)) = u + 15 + y";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   465
test "(i + j + 32 + (k::nat)) - (u + 15 + y) = zz";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   466
test "(i + j + 12 + (k::nat)) = u + 5 + y";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   467
(*Suc*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   468
test "(i + j + 12 + k) = Suc (u + y)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   469
test "Suc (Suc (Suc (Suc (Suc (u + y))))) <= ((i + j) + 41 + k)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   470
test "(i + j + 5 + k) < Suc (Suc (Suc (Suc (Suc (u + y)))))";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   471
test "Suc (Suc (Suc (Suc (Suc (u + y))))) - 5 = v";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   472
test "(i + j + 5 + k) = Suc (Suc (Suc (Suc (Suc (Suc (Suc (u + y)))))))";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   473
test "2*y + 3*z + 2*u = Suc (u)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   474
test "2*y + 3*z + 6*w + 2*y + 3*z + 2*u = Suc (u)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   475
test "2*y + 3*z + 6*w + 2*y + 3*z + 2*u = 2*y' + 3*z' + 6*w' + 2*y' + 3*z' + u + (vv::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   476
test "6 + 2*y + 3*z + 4*u = Suc (vv + 2*u + z)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   477
test "(2*n*m) < (3*(m*n)) + (u::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   478
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   479
test "(Suc (Suc (Suc (Suc (Suc (Suc (case length (f c) of 0 => 0 | Suc k => k)))))) <= Suc 0)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   480
 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   481
test "Suc (Suc (Suc (Suc (Suc (Suc (length l1 + length l2)))))) <= length l1";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   482
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   483
test "( (Suc (Suc (Suc (Suc (Suc (length (compT P E A ST mxr e) + length l3)))))) <= length (compT P E A ST mxr e))";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   484
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   485
test "( (Suc (Suc (Suc (Suc (Suc (length (compT P E A ST mxr e) + length (compT P E (A Un \<A> e) ST mxr c))))))) <= length (compT P E A ST mxr e))";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   486
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   487
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   488
(*negative numerals: FAIL*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   489
test "(i + j + -23 + (k::nat)) < u + 15 + y";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   490
test "(i + j + 3 + (k::nat)) < u + -15 + y";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   491
test "(i + j + -12 + (k::nat)) - 15 = y";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   492
test "(i + j + 12 + (k::nat)) - -15 = y";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   493
test "(i + j + -12 + (k::nat)) - -15 = y";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   494
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   495
(*combine_numerals*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   496
test "k + 3*k = (u::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   497
test "Suc (i + 3) = u";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   498
test "Suc (i + j + 3 + k) = u";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   499
test "k + j + 3*k + j = (u::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   500
test "Suc (j*i + i + k + 5 + 3*k + i*j*4) = (u::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   501
test "(2*n*m) + (3*(m*n)) = (u::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   502
(*negative numerals: FAIL*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   503
test "Suc (i + j + -3 + k) = u";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   504
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   505
(*cancel_numeral_factors*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   506
test "9*x = 12 * (y::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   507
test "(9*x) div (12 * (y::nat)) = z";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   508
test "9*x < 12 * (y::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   509
test "9*x <= 12 * (y::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   510
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   511
(*cancel_factor*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   512
test "x*k = k*(y::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   513
test "k = k*(y::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   514
test "a*(b*c) = (b::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   515
test "a*(b*c) = d*(b::nat)*(x*a)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   516
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   517
test "x*k < k*(y::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   518
test "k < k*(y::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   519
test "a*(b*c) < (b::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   520
test "a*(b*c) < d*(b::nat)*(x*a)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   521
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   522
test "x*k <= k*(y::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   523
test "k <= k*(y::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   524
test "a*(b*c) <= (b::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   525
test "a*(b*c) <= d*(b::nat)*(x*a)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   526
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   527
test "(x*k) div (k*(y::nat)) = (uu::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   528
test "(k) div (k*(y::nat)) = (uu::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   529
test "(a*(b*c)) div ((b::nat)) = (uu::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   530
test "(a*(b*c)) div (d*(b::nat)*(x*a)) = (uu::nat)";
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   531
*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   532
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   533
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   534
(*** Prepare linear arithmetic for nat numerals ***)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   535
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   536
local
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   537
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   538
(* reduce contradictory <= to False *)
24431
02d29baa42ff tuned linear arith (once again) with ring_distribs
nipkow
parents: 24093
diff changeset
   539
val add_rules = @{thms ring_distribs} @
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   540
  [@{thm Let_number_of}, @{thm Let_0}, @{thm Let_1}, @{thm nat_0}, @{thm nat_1},
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   541
   @{thm add_nat_number_of}, @{thm diff_nat_number_of}, @{thm mult_nat_number_of},
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   542
   @{thm eq_nat_number_of}, @{thm less_nat_number_of}, @{thm le_number_of_eq_not_less},
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   543
   @{thm le_Suc_number_of}, @{thm le_number_of_Suc},
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   544
   @{thm less_Suc_number_of}, @{thm less_number_of_Suc},
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   545
   @{thm Suc_eq_number_of}, @{thm eq_number_of_Suc},
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   546
   @{thm mult_Suc}, @{thm mult_Suc_right},
24431
02d29baa42ff tuned linear arith (once again) with ring_distribs
nipkow
parents: 24093
diff changeset
   547
   @{thm add_Suc}, @{thm add_Suc_right},
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   548
   @{thm eq_number_of_0}, @{thm eq_0_number_of}, @{thm less_0_number_of},
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   549
   @{thm of_int_number_of_eq}, @{thm of_nat_number_of_eq}, @{thm nat_number_of}, @{thm if_True}, @{thm if_False}];
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   550
24431
02d29baa42ff tuned linear arith (once again) with ring_distribs
nipkow
parents: 24093
diff changeset
   551
(* Products are multiplied out during proof (re)construction via
02d29baa42ff tuned linear arith (once again) with ring_distribs
nipkow
parents: 24093
diff changeset
   552
ring_distribs. Ideally they should remain atomic. But that is
02d29baa42ff tuned linear arith (once again) with ring_distribs
nipkow
parents: 24093
diff changeset
   553
currently not possible because 1 is replaced by Suc 0, and then some
02d29baa42ff tuned linear arith (once again) with ring_distribs
nipkow
parents: 24093
diff changeset
   554
simprocs start to mess around with products like (n+1)*m. The rule
02d29baa42ff tuned linear arith (once again) with ring_distribs
nipkow
parents: 24093
diff changeset
   555
1 == Suc 0 is necessary for early parts of HOL where numerals and
02d29baa42ff tuned linear arith (once again) with ring_distribs
nipkow
parents: 24093
diff changeset
   556
simprocs are not yet available. But then it is difficult to remove
02d29baa42ff tuned linear arith (once again) with ring_distribs
nipkow
parents: 24093
diff changeset
   557
that rule later on, because it may find its way back in when theories
02d29baa42ff tuned linear arith (once again) with ring_distribs
nipkow
parents: 24093
diff changeset
   558
(and thus lin-arith simpsets) are merged. Otherwise one could turn the
02d29baa42ff tuned linear arith (once again) with ring_distribs
nipkow
parents: 24093
diff changeset
   559
rule around (Suc n = n+1) and see if that helps products being left
02d29baa42ff tuned linear arith (once again) with ring_distribs
nipkow
parents: 24093
diff changeset
   560
alone. *)
02d29baa42ff tuned linear arith (once again) with ring_distribs
nipkow
parents: 24093
diff changeset
   561
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   562
val simprocs = Nat_Numeral_Simprocs.combine_numerals
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   563
  :: Nat_Numeral_Simprocs.cancel_numerals;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   564
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   565
in
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   566
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   567
val nat_simprocs_setup =
24093
5d0ecd0c8f3c tuned LinArith setup;
wenzelm
parents: 23969
diff changeset
   568
  LinArith.map_data (fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, neqE, simpset} =>
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   569
   {add_mono_thms = add_mono_thms, mult_mono_thms = mult_mono_thms,
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   570
    inj_thms = inj_thms, lessD = lessD, neqE = neqE,
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   571
    simpset = simpset addsimps add_rules
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   572
                      addsimprocs simprocs});
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   573
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   574
end;