src/HOL/Tools/nat_numeral_simprocs.ML
author nipkow
Tue, 05 Nov 2019 14:57:41 +0100
changeset 71033 c1b63124245c
parent 69593 3dda49e08b9d
child 78800 0b3700d31758
permissions -rw-r--r--
tuned
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 30685
diff changeset
     1
(* Author: Lawrence C Paulson, Cambridge University Computer Laboratory
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     2
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     3
Simprocs for nat numerals.
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     4
*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     5
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 30685
diff changeset
     6
signature NAT_NUMERAL_SIMPROCS =
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 30685
diff changeset
     7
sig
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
     8
  val combine_numerals: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
     9
  val eq_cancel_numerals: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
    10
  val less_cancel_numerals: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
    11
  val le_cancel_numerals: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
    12
  val diff_cancel_numerals: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
    13
  val eq_cancel_numeral_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
    14
  val less_cancel_numeral_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
    15
  val le_cancel_numeral_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
    16
  val div_cancel_numeral_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
    17
  val dvd_cancel_numeral_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
    18
  val eq_cancel_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
    19
  val less_cancel_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
    20
  val le_cancel_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
    21
  val div_cancel_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
    22
  val dvd_cancel_factor: Proof.context -> cterm -> thm option
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 30685
diff changeset
    23
end;
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 30685
diff changeset
    24
45462
aba629d6cee5 use simproc_setup for more nat_numeral simprocs; add simproc tests
huffman
parents: 45436
diff changeset
    25
structure Nat_Numeral_Simprocs : NAT_NUMERAL_SIMPROCS =
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    26
struct
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    27
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45668
diff changeset
    28
(*Maps n to #n for n = 1, 2*)
61694
6571c78c9667 Removed some legacy theorems; minor adjustments to simplification rules; new material on homotopic paths
paulson <lp15@cam.ac.uk>
parents: 61144
diff changeset
    29
val numeral_syms = [@{thm numeral_One} RS sym, @{thm numeral_2_eq_2} RS sym];
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
    30
val numeral_sym_ss =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
    31
  simpset_of (put_simpset HOL_basic_ss \<^context> addsimps numeral_syms);
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    32
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    33
(*Utilities*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    34
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45668
diff changeset
    35
fun mk_number 1 = HOLogic.numeral_const HOLogic.natT $ HOLogic.one_const
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45668
diff changeset
    36
  | mk_number n = HOLogic.mk_number HOLogic.natT n;
24630
351a308ab58d simplified type int (eliminated IntInf.int, integer);
wenzelm
parents: 24431
diff changeset
    37
fun dest_number t = Int.max (0, snd (HOLogic.dest_number t));
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    38
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    39
fun find_first_numeral past (t::terms) =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    40
        ((dest_number t, t, rev past @ terms)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    41
         handle TERM _ => find_first_numeral (t::past) terms)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    42
  | find_first_numeral past [] = raise TERM("find_first_numeral", []);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    43
66811
aa288270732a dropped duplicates
haftmann
parents: 64244
diff changeset
    44
val mk_sum = Arith_Data.mk_sum HOLogic.natT;
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    45
66811
aa288270732a dropped duplicates
haftmann
parents: 64244
diff changeset
    46
val long_mk_sum = Arith_Data.long_mk_sum HOLogic.natT;
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    47
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
    48
val dest_plus = HOLogic.dest_bin \<^const_name>\<open>Groups.plus\<close> HOLogic.natT;
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    49
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    50
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    51
(** Other simproc items **)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    52
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    53
val bin_simps =
61694
6571c78c9667 Removed some legacy theorems; minor adjustments to simplification rules; new material on homotopic paths
paulson <lp15@cam.ac.uk>
parents: 61144
diff changeset
    54
     [@{thm numeral_One} RS sym,
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45668
diff changeset
    55
      @{thm numeral_plus_numeral}, @{thm add_numeral_left},
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45668
diff changeset
    56
      @{thm diff_nat_numeral}, @{thm diff_0_eq_0}, @{thm diff_0},
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45668
diff changeset
    57
      @{thm numeral_times_numeral}, @{thm mult_numeral_left(1)},
45668
0ea1c705eebb use HOL_basic_ss instead of HOL_ss for internal simproc proofs (cf. b36eedcd1633)
huffman
parents: 45463
diff changeset
    58
      @{thm if_True}, @{thm if_False}, @{thm not_False_eq_True},
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45668
diff changeset
    59
      @{thm nat_0}, @{thm nat_numeral}, @{thm nat_neg_numeral}] @
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45668
diff changeset
    60
     @{thms arith_simps} @ @{thms rel_simps};
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    61
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    62
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    63
(*** CancelNumerals simprocs ***)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    64
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    65
val one = mk_number 1;
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
    66
val mk_times = HOLogic.mk_binop \<^const_name>\<open>Groups.times\<close>;
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    67
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    68
fun mk_prod [] = one
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    69
  | mk_prod [t] = t
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    70
  | mk_prod (t :: ts) = if t = one then mk_prod ts
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    71
                        else mk_times (t, mk_prod ts);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    72
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
    73
val dest_times = HOLogic.dest_bin \<^const_name>\<open>Groups.times\<close> HOLogic.natT;
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    74
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    75
fun dest_prod t =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    76
      let val (t,u) = dest_times t
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    77
      in  dest_prod t @ dest_prod u  end
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    78
      handle TERM _ => [t];
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    79
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    80
(*DON'T do the obvious simplifications; that would create special cases*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    81
fun mk_coeff (k,t) = mk_times (mk_number k, t);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    82
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    83
(*Express t as a product of (possibly) a numeral with other factors, sorted*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    84
fun dest_coeff t =
35408
b48ab741683b modernized structure Term_Ord;
wenzelm
parents: 35267
diff changeset
    85
    let val ts = sort Term_Ord.term_ord (dest_prod t)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    86
        val (n, _, ts') = find_first_numeral [] ts
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    87
                          handle TERM _ => (1, one, ts)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    88
    in (n, mk_prod ts') end;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    89
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    90
(*Find first coefficient-term THAT MATCHES u*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    91
fun find_first_coeff past u [] = raise TERM("find_first_coeff", [])
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    92
  | find_first_coeff past u (t::terms) =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    93
        let val (n,u') = dest_coeff t
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    94
        in  if u aconv u' then (n, rev past @ terms)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    95
                          else find_first_coeff (t::past) u terms
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    96
        end
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    97
        handle TERM _ => find_first_coeff (t::past) u terms;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    98
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    99
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   100
(*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
   101
  Sucs and counting them.*)
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   102
fun dest_Suc_sum (Const (\<^const_name>\<open>Suc\<close>, _) $ t, (k,ts)) = dest_Suc_sum (t, (k+1,ts))
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   103
  | dest_Suc_sum (t, (k,ts)) = 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   104
      let val (t1,t2) = dest_plus t
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   105
      in  dest_Suc_sum (t1, dest_Suc_sum (t2, (k,ts)))  end
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   106
      handle TERM _ => (k, t::ts);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   107
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   108
(*Code for testing whether numerals are already used in the goal*)
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   109
fun is_numeral (Const(\<^const_name>\<open>Num.numeral\<close>, _) $ w) = true
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   110
  | is_numeral _ = false;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   111
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   112
fun prod_has_numeral t = exists is_numeral (dest_prod t);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   113
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   114
(*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
   115
  an exception is raised unless the original expression contains at least one
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   116
  numeral in a coefficient position.  This prevents nat_combine_numerals from 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   117
  introducing numerals to goals.*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   118
fun dest_Sucs_sum relaxed t = 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   119
  let val (k,ts) = dest_Suc_sum (t,(0,[]))
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   120
  in
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   121
     if relaxed orelse exists prod_has_numeral ts then 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   122
       if k=0 then ts
24630
351a308ab58d simplified type int (eliminated IntInf.int, integer);
wenzelm
parents: 24431
diff changeset
   123
       else mk_number k :: ts
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   124
     else raise TERM("Nat_Numeral_Simprocs.dest_Sucs_sum", [t])
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   125
  end;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   126
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   127
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   128
(* FIXME !? *)
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   129
val rename_numerals = simplify (put_simpset numeral_sym_ss \<^context>) o Thm.transfer \<^theory>;
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   130
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   131
(*Simplify 1*n and n*1 to n*)
35064
1bdef0c013d3 hide fact names clashing with fact names from Group.thy
haftmann
parents: 35050
diff changeset
   132
val add_0s  = map rename_numerals [@{thm Nat.add_0}, @{thm Nat.add_0_right}];
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   133
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
   134
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   135
(*Final simplification: cancel + and *; replace Numeral0 by 0 and Numeral1 by 1*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   136
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   137
(*And these help the simproc return False when appropriate, which helps
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   138
  the arith prover.*)
23881
851c74f1bb69 moved class ord from Orderings.thy to HOL.thy
haftmann
parents: 23471
diff changeset
   139
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
   140
  @{thm Suc_not_Zero}, @{thm le_0_eq}];
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   141
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   142
val simplify_meta_eq =
30518
07b45c1aa788 moved some generic nonsense to arith_data.ML
haftmann
parents: 30496
diff changeset
   143
    Arith_Data.simplify_meta_eq
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45668
diff changeset
   144
        ([@{thm numeral_1_eq_Suc_0}, @{thm Nat.add_0}, @{thm Nat.add_0_right},
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   145
          @{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
   146
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   147
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   148
(*** Applying CancelNumeralsFun ***)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   149
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   150
structure CancelNumeralsCommon =
44945
haftmann
parents: 40878
diff changeset
   151
struct
haftmann
parents: 40878
diff changeset
   152
  val mk_sum = (fn T : typ => mk_sum)
haftmann
parents: 40878
diff changeset
   153
  val dest_sum = dest_Sucs_sum true
haftmann
parents: 40878
diff changeset
   154
  val mk_coeff = mk_coeff
haftmann
parents: 40878
diff changeset
   155
  val dest_coeff = dest_coeff
haftmann
parents: 40878
diff changeset
   156
  val find_first_coeff = find_first_coeff []
44947
8ae418dfe561 dropped unused argument – avoids problem with SML/NJ
haftmann
parents: 44945
diff changeset
   157
  val trans_tac = Numeral_Simprocs.trans_tac
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   158
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   159
  val norm_ss1 =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   160
    simpset_of (put_simpset Numeral_Simprocs.num_ss \<^context>
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   161
      addsimps numeral_syms @ add_0s @ mult_1s @
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 51717
diff changeset
   162
        [@{thm Suc_eq_plus1_left}] @ @{thms ac_simps})
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   163
  val norm_ss2 =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   164
    simpset_of (put_simpset Numeral_Simprocs.num_ss \<^context>
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 51717
diff changeset
   165
      addsimps bin_simps @ @{thms ac_simps} @ @{thms ac_simps})
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   166
  fun norm_tac ctxt = 
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   167
    ALLGOALS (simp_tac (put_simpset norm_ss1 ctxt))
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   168
    THEN ALLGOALS (simp_tac (put_simpset norm_ss2 ctxt))
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   169
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   170
  val numeral_simp_ss =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   171
    simpset_of (put_simpset HOL_basic_ss \<^context>
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   172
      addsimps add_0s @ bin_simps);
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   173
  fun numeral_simp_tac ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   174
    ALLGOALS (simp_tac (put_simpset numeral_simp_ss ctxt));
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   175
  val simplify_meta_eq  = simplify_meta_eq
44945
haftmann
parents: 40878
diff changeset
   176
  val prove_conv = Arith_Data.prove_conv
haftmann
parents: 40878
diff changeset
   177
end;
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   178
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   179
structure EqCancelNumerals = CancelNumeralsFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   180
 (open CancelNumeralsCommon
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   181
  val mk_bal   = HOLogic.mk_eq
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   182
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>HOL.eq\<close> HOLogic.natT
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   183
  val bal_add1 = @{thm nat_eq_add_iff1} RS trans
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   184
  val bal_add2 = @{thm nat_eq_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 LessCancelNumerals = CancelNumeralsFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   188
 (open CancelNumeralsCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   189
  val mk_bal   = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   190
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less\<close> HOLogic.natT
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   191
  val bal_add1 = @{thm nat_less_add_iff1} RS trans
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   192
  val bal_add2 = @{thm nat_less_add_iff2} RS trans
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   193
);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   194
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   195
structure LeCancelNumerals = CancelNumeralsFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   196
 (open CancelNumeralsCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   197
  val mk_bal   = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less_eq\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   198
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less_eq\<close> HOLogic.natT
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   199
  val bal_add1 = @{thm nat_le_add_iff1} RS trans
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   200
  val bal_add2 = @{thm nat_le_add_iff2} RS trans
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   201
);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   202
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   203
structure DiffCancelNumerals = CancelNumeralsFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   204
 (open CancelNumeralsCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   205
  val mk_bal   = HOLogic.mk_binop \<^const_name>\<open>Groups.minus\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   206
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Groups.minus\<close> HOLogic.natT
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   207
  val bal_add1 = @{thm nat_diff_add_eq1} RS trans
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   208
  val bal_add2 = @{thm nat_diff_add_eq2} RS trans
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   209
);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   210
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60352
diff changeset
   211
val eq_cancel_numerals = EqCancelNumerals.proc
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60352
diff changeset
   212
val less_cancel_numerals = LessCancelNumerals.proc
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60352
diff changeset
   213
val le_cancel_numerals = LeCancelNumerals.proc
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60352
diff changeset
   214
val diff_cancel_numerals = DiffCancelNumerals.proc
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   215
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   216
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   217
(*** Applying CombineNumeralsFun ***)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   218
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   219
structure CombineNumeralsData =
44945
haftmann
parents: 40878
diff changeset
   220
struct
haftmann
parents: 40878
diff changeset
   221
  type coeff = int
haftmann
parents: 40878
diff changeset
   222
  val iszero = (fn x => x = 0)
haftmann
parents: 40878
diff changeset
   223
  val add = op +
haftmann
parents: 40878
diff changeset
   224
  val mk_sum = (fn T : typ => long_mk_sum)  (*to work for 2*x + 3*x *)
haftmann
parents: 40878
diff changeset
   225
  val dest_sum = dest_Sucs_sum false
haftmann
parents: 40878
diff changeset
   226
  val mk_coeff = mk_coeff
haftmann
parents: 40878
diff changeset
   227
  val dest_coeff = dest_coeff
haftmann
parents: 40878
diff changeset
   228
  val left_distrib = @{thm left_add_mult_distrib} RS trans
haftmann
parents: 40878
diff changeset
   229
  val prove_conv = Arith_Data.prove_conv_nohyps
44947
8ae418dfe561 dropped unused argument – avoids problem with SML/NJ
haftmann
parents: 44945
diff changeset
   230
  val trans_tac = Numeral_Simprocs.trans_tac
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   231
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   232
  val norm_ss1 =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   233
    simpset_of (put_simpset Numeral_Simprocs.num_ss \<^context>
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 51717
diff changeset
   234
      addsimps numeral_syms @ add_0s @ mult_1s @ [@{thm Suc_eq_plus1}] @ @{thms ac_simps})
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   235
  val norm_ss2 =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   236
    simpset_of (put_simpset Numeral_Simprocs.num_ss \<^context>
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 51717
diff changeset
   237
      addsimps bin_simps @ @{thms ac_simps} @ @{thms ac_simps})
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   238
  fun norm_tac ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   239
    ALLGOALS (simp_tac (put_simpset norm_ss1 ctxt))
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   240
    THEN ALLGOALS (simp_tac (put_simpset norm_ss2 ctxt))
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   241
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   242
  val numeral_simp_ss =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   243
    simpset_of (put_simpset HOL_basic_ss \<^context>
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   244
      addsimps add_0s @ bin_simps);
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   245
  fun numeral_simp_tac ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   246
    ALLGOALS (simp_tac (put_simpset numeral_simp_ss ctxt))
44945
haftmann
parents: 40878
diff changeset
   247
  val simplify_meta_eq = simplify_meta_eq
haftmann
parents: 40878
diff changeset
   248
end;
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   249
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   250
structure CombineNumerals = CombineNumeralsFun(CombineNumeralsData);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   251
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60352
diff changeset
   252
val combine_numerals = CombineNumerals.proc
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   253
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   254
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   255
(*** Applying CancelNumeralFactorFun ***)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   256
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   257
structure CancelNumeralFactorCommon =
44945
haftmann
parents: 40878
diff changeset
   258
struct
haftmann
parents: 40878
diff changeset
   259
  val mk_coeff = mk_coeff
haftmann
parents: 40878
diff changeset
   260
  val dest_coeff = dest_coeff
44947
8ae418dfe561 dropped unused argument – avoids problem with SML/NJ
haftmann
parents: 44945
diff changeset
   261
  val trans_tac = Numeral_Simprocs.trans_tac
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   262
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   263
  val norm_ss1 =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   264
    simpset_of (put_simpset Numeral_Simprocs.num_ss \<^context>
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 51717
diff changeset
   265
      addsimps numeral_syms @ add_0s @ mult_1s @ [@{thm Suc_eq_plus1_left}] @ @{thms ac_simps})
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   266
  val norm_ss2 =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   267
    simpset_of (put_simpset Numeral_Simprocs.num_ss \<^context>
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 51717
diff changeset
   268
      addsimps bin_simps @ @{thms ac_simps} @ @{thms ac_simps})
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   269
  fun norm_tac ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   270
    ALLGOALS (simp_tac (put_simpset norm_ss1 ctxt))
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   271
    THEN ALLGOALS (simp_tac (put_simpset norm_ss2 ctxt))
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   272
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   273
  val numeral_simp_ss =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   274
    simpset_of (put_simpset HOL_basic_ss \<^context> addsimps bin_simps)
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   275
  fun numeral_simp_tac ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   276
    ALLGOALS (simp_tac (put_simpset numeral_simp_ss ctxt))
44945
haftmann
parents: 40878
diff changeset
   277
  val simplify_meta_eq = simplify_meta_eq
haftmann
parents: 40878
diff changeset
   278
  val prove_conv = Arith_Data.prove_conv
haftmann
parents: 40878
diff changeset
   279
end;
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   280
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   281
structure DivCancelNumeralFactor = CancelNumeralFactorFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   282
 (open CancelNumeralFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   283
  val mk_bal   = HOLogic.mk_binop \<^const_name>\<open>Rings.divide\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   284
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Rings.divide\<close> HOLogic.natT
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   285
  val cancel = @{thm nat_mult_div_cancel1} RS trans
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   286
  val neg_exchanges = false
44945
haftmann
parents: 40878
diff changeset
   287
);
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   288
23969
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   289
structure DvdCancelNumeralFactor = CancelNumeralFactorFun
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   290
 (open CancelNumeralFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   291
  val mk_bal   = HOLogic.mk_binrel \<^const_name>\<open>Rings.dvd\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   292
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Rings.dvd\<close> HOLogic.natT
23969
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   293
  val cancel = @{thm nat_mult_dvd_cancel1} RS trans
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   294
  val neg_exchanges = false
44945
haftmann
parents: 40878
diff changeset
   295
);
23969
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   296
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   297
structure EqCancelNumeralFactor = CancelNumeralFactorFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   298
 (open CancelNumeralFactorCommon
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   299
  val mk_bal   = HOLogic.mk_eq
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   300
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>HOL.eq\<close> HOLogic.natT
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   301
  val cancel = @{thm nat_mult_eq_cancel1} RS trans
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   302
  val neg_exchanges = false
44945
haftmann
parents: 40878
diff changeset
   303
);
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   304
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   305
structure LessCancelNumeralFactor = CancelNumeralFactorFun
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60352
diff changeset
   306
(
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60352
diff changeset
   307
  open CancelNumeralFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   308
  val mk_bal   = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   309
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less\<close> HOLogic.natT
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   310
  val cancel = @{thm nat_mult_less_cancel1} RS trans
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   311
  val neg_exchanges = true
44945
haftmann
parents: 40878
diff changeset
   312
);
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   313
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   314
structure LeCancelNumeralFactor = CancelNumeralFactorFun
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60352
diff changeset
   315
(
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60352
diff changeset
   316
  open CancelNumeralFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   317
  val mk_bal   = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less_eq\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   318
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less_eq\<close> HOLogic.natT
23471
08e6c03b2a72 add thm antiquotations
huffman
parents: 23164
diff changeset
   319
  val cancel = @{thm nat_mult_le_cancel1} RS trans
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   320
  val neg_exchanges = true
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   321
)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   322
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60352
diff changeset
   323
val eq_cancel_numeral_factor = EqCancelNumeralFactor.proc
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60352
diff changeset
   324
val less_cancel_numeral_factor = LessCancelNumeralFactor.proc
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60352
diff changeset
   325
val le_cancel_numeral_factor = LeCancelNumeralFactor.proc
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60352
diff changeset
   326
val div_cancel_numeral_factor = DivCancelNumeralFactor.proc
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60352
diff changeset
   327
val dvd_cancel_numeral_factor = DvdCancelNumeralFactor.proc
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   328
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   329
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   330
(*** Applying ExtractCommonTermFun ***)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   331
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   332
(*this version ALWAYS includes a trailing one*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   333
fun long_mk_prod []        = one
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   334
  | long_mk_prod (t :: ts) = mk_times (t, mk_prod ts);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   335
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   336
(*Find first term that matches u*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   337
fun find_first_t past u []         = raise TERM("find_first_t", [])
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   338
  | find_first_t past u (t::terms) =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   339
        if u aconv t then (rev past @ terms)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   340
        else find_first_t (t::past) u terms
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   341
        handle TERM _ => find_first_t (t::past) u terms;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   342
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   343
(** Final simplification for the CancelFactor simprocs **)
30518
07b45c1aa788 moved some generic nonsense to arith_data.ML
haftmann
parents: 30496
diff changeset
   344
val simplify_one = Arith_Data.simplify_meta_eq  
64244
e7102c40783c clarified theorem names
haftmann
parents: 61694
diff changeset
   345
  [@{thm mult_1_left}, @{thm mult_1_right}, @{thm div_by_Suc_0}, @{thm numeral_1_eq_Suc_0}];
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   346
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   347
fun cancel_simplify_meta_eq ctxt cancel_th th =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   348
    simplify_one ctxt (([th, cancel_th]) MRS trans);
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   349
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   350
structure CancelFactorCommon =
44945
haftmann
parents: 40878
diff changeset
   351
struct
haftmann
parents: 40878
diff changeset
   352
  val mk_sum = (fn T : typ => long_mk_prod)
haftmann
parents: 40878
diff changeset
   353
  val dest_sum = dest_prod
haftmann
parents: 40878
diff changeset
   354
  val mk_coeff = mk_coeff
haftmann
parents: 40878
diff changeset
   355
  val dest_coeff = dest_coeff
haftmann
parents: 40878
diff changeset
   356
  val find_first = find_first_t []
44947
8ae418dfe561 dropped unused argument – avoids problem with SML/NJ
haftmann
parents: 44945
diff changeset
   357
  val trans_tac = Numeral_Simprocs.trans_tac
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   358
  val norm_ss =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   359
    simpset_of (put_simpset HOL_basic_ss \<^context>
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 51717
diff changeset
   360
      addsimps mult_1s @ @{thms ac_simps})
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   361
  fun norm_tac ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47108
diff changeset
   362
    ALLGOALS (simp_tac (put_simpset norm_ss ctxt))
30649
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   363
  val simplify_meta_eq  = cancel_simplify_meta_eq
45270
d5b5c9259afd fix bug in cancel_factor simprocs so they will work on goals like 'x * y < x * z' where the common term is already on the left
huffman
parents: 44947
diff changeset
   364
  fun mk_eq (a, b) = HOLogic.mk_Trueprop (HOLogic.mk_eq (a, b))
44945
haftmann
parents: 40878
diff changeset
   365
end;
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   366
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   367
structure EqCancelFactor = ExtractCommonTermFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   368
 (open CancelFactorCommon
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   369
  val mk_bal   = HOLogic.mk_eq
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   370
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>HOL.eq\<close> HOLogic.natT
31368
763f4b0fd579 made SML/NJ happy;
wenzelm
parents: 31068
diff changeset
   371
  fun simp_conv _ _ = SOME @{thm nat_mult_eq_cancel_disj}
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   372
);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   373
44945
haftmann
parents: 40878
diff changeset
   374
structure LeCancelFactor = ExtractCommonTermFun
haftmann
parents: 40878
diff changeset
   375
 (open CancelFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   376
  val mk_bal   = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less_eq\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   377
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less_eq\<close> HOLogic.natT
44945
haftmann
parents: 40878
diff changeset
   378
  fun simp_conv _ _ = SOME @{thm nat_mult_le_cancel_disj}
haftmann
parents: 40878
diff changeset
   379
);
haftmann
parents: 40878
diff changeset
   380
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   381
structure LessCancelFactor = ExtractCommonTermFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   382
 (open CancelFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   383
  val mk_bal   = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   384
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less\<close> HOLogic.natT
31368
763f4b0fd579 made SML/NJ happy;
wenzelm
parents: 31068
diff changeset
   385
  fun simp_conv _ _ = SOME @{thm nat_mult_less_cancel_disj}
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   386
);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   387
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   388
structure DivideCancelFactor = ExtractCommonTermFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   389
 (open CancelFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   390
  val mk_bal   = HOLogic.mk_binop \<^const_name>\<open>Rings.divide\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   391
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Rings.divide\<close> HOLogic.natT
31368
763f4b0fd579 made SML/NJ happy;
wenzelm
parents: 31068
diff changeset
   392
  fun simp_conv _ _ = SOME @{thm nat_mult_div_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
23969
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   395
structure DvdCancelFactor = ExtractCommonTermFun
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   396
 (open CancelFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   397
  val mk_bal   = HOLogic.mk_binrel \<^const_name>\<open>Rings.dvd\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 66811
diff changeset
   398
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Rings.dvd\<close> HOLogic.natT
31368
763f4b0fd579 made SML/NJ happy;
wenzelm
parents: 31068
diff changeset
   399
  fun simp_conv _ _ = SOME @{thm nat_mult_dvd_cancel_disj}
23969
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   400
);
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   401
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 57514
diff changeset
   402
fun eq_cancel_factor ctxt ct = EqCancelFactor.proc ctxt (Thm.term_of ct)
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 57514
diff changeset
   403
fun less_cancel_factor ctxt ct = LessCancelFactor.proc ctxt (Thm.term_of ct)
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 57514
diff changeset
   404
fun le_cancel_factor ctxt ct = LeCancelFactor.proc ctxt (Thm.term_of ct)
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 57514
diff changeset
   405
fun div_cancel_factor ctxt ct = DivideCancelFactor.proc ctxt (Thm.term_of ct)
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 57514
diff changeset
   406
fun dvd_cancel_factor ctxt ct = DvdCancelFactor.proc ctxt (Thm.term_of ct)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   407
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   408
end;