src/HOL/Tools/numeral_simprocs.ML
author haftmann
Fri, 19 Aug 2022 05:49:10 +0000
changeset 75879 24b17460ee60
parent 74282 c2ee8d993d6a
child 77879 dd222e2af01a
permissions -rw-r--r--
streamlined simpset building, avoiding duplicated rewrite rules
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: 31067
diff changeset
     1
(* Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
     2
   Copyright   2000  University of Cambridge
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     3
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
     4
Simprocs for the (integer) numerals.
23164
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
(*To quote from Provers/Arith/cancel_numeral_factor.ML:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     8
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     9
Cancels common coefficients in balanced expressions:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    10
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    11
     u*#m ~~ u'*#m'  ==  #n*u ~~ #n'*u'
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    12
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    13
where ~~ is an appropriate balancing operation (e.g. =, <=, <, div, /)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    14
and d = gcd(m,m') and n=m/d and n'=m'/d.
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    15
*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    16
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    17
signature NUMERAL_SIMPROCS =
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    18
sig
59530
2a20354c0877 proper context;
wenzelm
parents: 58512
diff changeset
    19
  val trans_tac: Proof.context -> thm option -> tactic
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    20
  val assoc_fold: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    21
  val combine_numerals: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    22
  val eq_cancel_numerals: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    23
  val less_cancel_numerals: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    24
  val le_cancel_numerals: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    25
  val eq_cancel_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    26
  val le_cancel_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    27
  val less_cancel_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    28
  val div_cancel_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    29
  val mod_cancel_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    30
  val dvd_cancel_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    31
  val divide_cancel_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    32
  val eq_cancel_numeral_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    33
  val less_cancel_numeral_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    34
  val le_cancel_numeral_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    35
  val div_cancel_numeral_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    36
  val divide_cancel_numeral_factor: Proof.context -> cterm -> thm option
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    37
  val field_combine_numerals: Proof.context -> cterm -> thm option
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
    38
  val field_divide_cancel_numeral_factor: simproc
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    39
  val num_ss: simpset
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
    40
  val field_comp_conv: Proof.context -> conv
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    41
end;
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    42
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    43
structure Numeral_Simprocs : NUMERAL_SIMPROCS =
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    44
struct
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    45
59530
2a20354c0877 proper context;
wenzelm
parents: 58512
diff changeset
    46
fun trans_tac _ NONE  = all_tac
2a20354c0877 proper context;
wenzelm
parents: 58512
diff changeset
    47
  | trans_tac ctxt (SOME th) = ALLGOALS (resolve_tac ctxt [th RS trans]);
44945
haftmann
parents: 44064
diff changeset
    48
33359
8b673ae1bf39 dedicated theory for loading numeral simprocs
haftmann
parents: 32957
diff changeset
    49
val mk_number = Arith_Data.mk_number;
8b673ae1bf39 dedicated theory for loading numeral simprocs
haftmann
parents: 32957
diff changeset
    50
val mk_sum = Arith_Data.mk_sum;
8b673ae1bf39 dedicated theory for loading numeral simprocs
haftmann
parents: 32957
diff changeset
    51
val long_mk_sum = Arith_Data.long_mk_sum;
8b673ae1bf39 dedicated theory for loading numeral simprocs
haftmann
parents: 32957
diff changeset
    52
val dest_sum = Arith_Data.dest_sum;
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    53
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
    54
val mk_times = HOLogic.mk_binop \<^const_name>\<open>Groups.times\<close>;
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    55
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
    56
fun one_of T = Const(\<^const_name>\<open>Groups.one\<close>, T);
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    57
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    58
(* build product with trailing 1 rather than Numeral 1 in order to avoid the
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    59
   unnecessary restriction to type class number_ring
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    60
   which is not required for cancellation of common factors in divisions.
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
    61
   UPDATE: this reasoning no longer applies (number_ring is gone)
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    62
*)
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
    63
fun mk_prod T =
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    64
  let val one = one_of T
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    65
  fun mk [] = one
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    66
    | mk [t] = t
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    67
    | mk (t :: ts) = if t = one then mk ts else mk_times (t, mk ts)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    68
  in mk end;
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    69
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    70
(*This version ALWAYS includes a trailing one*)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    71
fun long_mk_prod T []        = one_of T
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    72
  | long_mk_prod T (t :: ts) = mk_times (t, mk_prod T ts);
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    73
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
    74
val dest_times = HOLogic.dest_bin \<^const_name>\<open>Groups.times\<close> dummyT;
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    75
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    76
fun dest_prod t =
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    77
      let val (t,u) = dest_times t
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    78
      in dest_prod t @ dest_prod u end
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    79
      handle TERM _ => [t];
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    80
33359
8b673ae1bf39 dedicated theory for loading numeral simprocs
haftmann
parents: 32957
diff changeset
    81
fun find_first_numeral past (t::terms) =
8b673ae1bf39 dedicated theory for loading numeral simprocs
haftmann
parents: 32957
diff changeset
    82
        ((snd (HOLogic.dest_number t), rev past @ terms)
8b673ae1bf39 dedicated theory for loading numeral simprocs
haftmann
parents: 32957
diff changeset
    83
         handle TERM _ => find_first_numeral (t::past) terms)
8b673ae1bf39 dedicated theory for loading numeral simprocs
haftmann
parents: 32957
diff changeset
    84
  | find_first_numeral past [] = raise TERM("find_first_numeral", []);
8b673ae1bf39 dedicated theory for loading numeral simprocs
haftmann
parents: 32957
diff changeset
    85
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    86
(*DON'T do the obvious simplifications; that would create special cases*)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    87
fun mk_coeff (k, t) = mk_times (mk_number (Term.fastype_of t) k, t);
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    88
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    89
(*Express t as a product of (possibly) a numeral with other sorted terms*)
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
    90
fun dest_coeff sign (Const (\<^const_name>\<open>Groups.uminus\<close>, _) $ t) = dest_coeff (~sign) t
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    91
  | dest_coeff sign t =
35408
b48ab741683b modernized structure Term_Ord;
wenzelm
parents: 35267
diff changeset
    92
    let val ts = sort Term_Ord.term_ord (dest_prod t)
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    93
        val (n, ts') = find_first_numeral [] ts
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    94
                          handle TERM _ => (1, ts)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    95
    in (sign*n, mk_prod (Term.fastype_of t) ts') end;
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    96
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    97
(*Find first coefficient-term THAT MATCHES u*)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    98
fun find_first_coeff past u [] = raise TERM("find_first_coeff", [])
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
    99
  | find_first_coeff past u (t::terms) =
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   100
        let val (n,u') = dest_coeff 1 t
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   101
        in if u aconv u' then (n, rev past @ terms)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   102
                         else find_first_coeff (t::past) u terms
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   103
        end
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   104
        handle TERM _ => find_first_coeff (t::past) u terms;
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   105
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   106
(*Fractions as pairs of ints. Can't use Rat.rat because the representation
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   107
  needs to preserve negative values in the denominator.*)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   108
fun mk_frac (p, q) = if q = 0 then raise Div else (p, q);
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   109
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   110
(*Don't reduce fractions; sums must be proved by rule add_frac_eq.
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   111
  Fractions are reduced later by the cancel_numeral_factor simproc.*)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   112
fun add_frac ((p1, q1), (p2, q2)) = (p1 * q2 + p2 * q1, q1 * q2);
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   113
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   114
val mk_divide = HOLogic.mk_binop \<^const_name>\<open>Rings.divide\<close>;
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   115
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   116
(*Build term (p / q) * t*)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   117
fun mk_fcoeff ((p, q), t) =
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   118
  let val T = Term.fastype_of t
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   119
  in mk_times (mk_divide (mk_number T p, mk_number T q), t) end;
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   120
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   121
(*Express t as a product of a fraction with other sorted terms*)
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   122
fun dest_fcoeff sign (Const (\<^const_name>\<open>Groups.uminus\<close>, _) $ t) = dest_fcoeff (~sign) t
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   123
  | dest_fcoeff sign (Const (\<^const_name>\<open>Rings.divide\<close>, _) $ t $ u) =
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   124
    let val (p, t') = dest_coeff sign t
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   125
        val (q, u') = dest_coeff 1 u
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   126
    in (mk_frac (p, q), mk_divide (t', u')) end
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   127
  | dest_fcoeff sign t =
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   128
    let val (p, t') = dest_coeff sign t
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   129
        val T = Term.fastype_of t
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   130
    in (mk_frac (p, 1), mk_divide (t', one_of T)) end;
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   131
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   132
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   133
(** New term ordering so that AC-rewriting brings numerals to the front **)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   134
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   135
(*Order integers by absolute value and then by sign. The standard integer
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   136
  ordering is not well-founded.*)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   137
fun num_ord (i,j) =
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   138
  (case int_ord (abs i, abs j) of
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   139
    EQUAL => int_ord (Int.sign i, Int.sign j)
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   140
  | ord => ord);
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   141
35408
b48ab741683b modernized structure Term_Ord;
wenzelm
parents: 35267
diff changeset
   142
(*This resembles Term_Ord.term_ord, but it puts binary numerals before other
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   143
  non-atomic terms.*)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   144
local open Term
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   145
in
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   146
fun numterm_ord (t, u) =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   147
    case (try HOLogic.dest_number t, try HOLogic.dest_number u) of
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   148
      (SOME (_, i), SOME (_, j)) => num_ord (i, j)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   149
    | (SOME _, NONE) => LESS
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   150
    | (NONE, SOME _) => GREATER
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   151
    | _ => (
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   152
      case (t, u) of
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   153
        (Abs (_, T, t), Abs(_, U, u)) =>
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   154
        (prod_ord numterm_ord Term_Ord.typ_ord ((t, T), (u, U)))
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   155
      | _ => (
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   156
        case int_ord (size_of_term t, size_of_term u) of
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   157
          EQUAL =>
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   158
          let val (f, ts) = strip_comb t and (g, us) = strip_comb u in
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   159
            (prod_ord Term_Ord.hd_ord numterms_ord ((f, ts), (g, us)))
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   160
          end
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   161
        | ord => ord))
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   162
and numterms_ord (ts, us) = list_ord numterm_ord (ts, us)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   163
end;
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   164
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   165
val num_ss =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   166
  simpset_of (put_simpset HOL_basic_ss \<^context> |> Simplifier.set_term_ord numterm_ord);
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   167
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   168
(*Maps 1 to Numeral1 so that arithmetic isn't complicated by the abstract 1.*)
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   169
val numeral_syms = @{thms numeral_One [symmetric]};
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   170
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   171
(*Simplify 0+n, n+0, Numeral1*n, n*Numeral1, 1*x, x*1, x/1 *)
59556
aa2deef7cf47 eliminated technical fact alias
haftmann
parents: 59530
diff changeset
   172
val add_0s =  @{thms add_0_left add_0_right};
64240
eabf80376aab more standardized names
haftmann
parents: 63950
diff changeset
   173
val mult_1s = @{thms mult_1s divide_numeral_1 mult_1_left mult_1_right mult_minus1 mult_minus1_right div_by_1};
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   174
45437
958d19d3405b tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
huffman
parents: 45306
diff changeset
   175
(* For post-simplification of the rhs of simproc-generated rules *)
958d19d3405b tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
huffman
parents: 45306
diff changeset
   176
val post_simps =
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   177
    @{thms numeral_One
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   178
      add_0_left add_0_right
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   179
      mult_zero_left mult_zero_right
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   180
      mult_1_left mult_1_right
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   181
      mult_minus1 mult_minus1_right}
45437
958d19d3405b tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
huffman
parents: 45306
diff changeset
   182
958d19d3405b tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
huffman
parents: 45306
diff changeset
   183
val field_post_simps =
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   184
    post_simps @ @{thms div_0 div_by_1}
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   185
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54230
diff changeset
   186
(*Simplify inverse Numeral1*)
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   187
val inverse_1s = @{thms inverse_numeral_1}
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   188
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   189
(*To perform binary arithmetic.  The "left" rewriting handles patterns
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   190
  created by the Numeral_Simprocs, such as 3 * (5 * x). *)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   191
val simps =
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   192
    @{thms numeral_One [symmetric]
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   193
      add_numeral_left
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   194
      add_neg_numeral_left
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   195
      mult_numeral_left
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   196
      arith_simps rel_simps}
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   197
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   198
(*Binary arithmetic BUT NOT ADDITION since it may collapse adjacent terms
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   199
  during re-arrangement*)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   200
val non_add_simps =
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46497
diff changeset
   201
  subtract Thm.eq_thm
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   202
    @{thms add_numeral_left
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   203
       add_neg_numeral_left
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   204
       numeral_plus_numeral
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   205
       add_neg_numeral_simps} simps;
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   206
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   207
(*To let us treat subtraction as addition*)
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   208
val diff_simps = @{thms diff_conv_add_uminus minus_add_distrib minus_minus};
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   209
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   210
(*To let us treat division as multiplication*)
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   211
val divide_simps = @{thms divide_inverse inverse_mult_distrib inverse_inverse_eq};
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   212
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   213
(*to extract again any uncancelled minuses*)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   214
val minus_from_mult_simps =
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   215
    @{thms minus_minus mult_minus_left mult_minus_right};
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   216
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   217
(*combine unary minus with numeric literals, however nested within a product*)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   218
val mult_minus_simps =
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   219
    @{thms mult.assoc minus_mult_right minus_mult_commute numeral_times_minus_swap};
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   220
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   221
val norm_ss1 =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   222
  simpset_of (put_simpset num_ss \<^context>
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   223
    addsimps numeral_syms @ add_0s @ mult_1s @
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   224
    diff_simps @ @{thms minus_zero ac_simps})
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   225
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   226
val norm_ss2 =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   227
  simpset_of (put_simpset num_ss \<^context>
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   228
    addsimps non_add_simps @ mult_minus_simps)
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   229
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   230
val norm_ss3 =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   231
  simpset_of (put_simpset num_ss \<^context>
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   232
    addsimps minus_from_mult_simps @ @{thms ac_simps minus_mult_commute})
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   233
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   234
structure CancelNumeralsCommon =
44945
haftmann
parents: 44064
diff changeset
   235
struct
haftmann
parents: 44064
diff changeset
   236
  val mk_sum = mk_sum
haftmann
parents: 44064
diff changeset
   237
  val dest_sum = dest_sum
haftmann
parents: 44064
diff changeset
   238
  val mk_coeff = mk_coeff
haftmann
parents: 44064
diff changeset
   239
  val dest_coeff = dest_coeff 1
haftmann
parents: 44064
diff changeset
   240
  val find_first_coeff = find_first_coeff []
44947
8ae418dfe561 dropped unused argument – avoids problem with SML/NJ
haftmann
parents: 44945
diff changeset
   241
  val trans_tac = trans_tac
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   242
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   243
  fun norm_tac ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   244
    ALLGOALS (simp_tac (put_simpset norm_ss1 ctxt))
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   245
    THEN ALLGOALS (simp_tac (put_simpset norm_ss2 ctxt))
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   246
    THEN ALLGOALS (simp_tac (put_simpset norm_ss3 ctxt))
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   247
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   248
  val numeral_simp_ss =
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   249
    simpset_of (put_simpset HOL_basic_ss \<^context> addsimps simps)
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   250
  fun numeral_simp_tac ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   251
    ALLGOALS (simp_tac (put_simpset numeral_simp_ss ctxt))
45437
958d19d3405b tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
huffman
parents: 45306
diff changeset
   252
  val simplify_meta_eq = Arith_Data.simplify_meta_eq post_simps
44945
haftmann
parents: 44064
diff changeset
   253
  val prove_conv = Arith_Data.prove_conv
haftmann
parents: 44064
diff changeset
   254
end;
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   255
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   256
structure EqCancelNumerals = CancelNumeralsFun
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   257
 (open CancelNumeralsCommon
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   258
  val mk_bal   = HOLogic.mk_eq
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   259
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>HOL.eq\<close> dummyT
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   260
  val bal_add1 = @{thm eq_add_iff1} RS trans
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   261
  val bal_add2 = @{thm eq_add_iff2} RS trans
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   262
);
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   263
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   264
structure LessCancelNumerals = CancelNumeralsFun
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   265
 (open CancelNumeralsCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   266
  val mk_bal   = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   267
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less\<close> dummyT
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   268
  val bal_add1 = @{thm less_add_iff1} RS trans
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   269
  val bal_add2 = @{thm less_add_iff2} RS trans
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   270
);
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   271
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   272
structure LeCancelNumerals = CancelNumeralsFun
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   273
 (open CancelNumeralsCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   274
  val mk_bal   = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less_eq\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   275
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less_eq\<close> dummyT
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   276
  val bal_add1 = @{thm le_add_iff1} RS trans
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   277
  val bal_add2 = @{thm le_add_iff2} RS trans
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   278
);
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   279
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   280
val eq_cancel_numerals = EqCancelNumerals.proc
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   281
val less_cancel_numerals = LessCancelNumerals.proc
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   282
val le_cancel_numerals = LeCancelNumerals.proc
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   283
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   284
structure CombineNumeralsData =
44945
haftmann
parents: 44064
diff changeset
   285
struct
haftmann
parents: 44064
diff changeset
   286
  type coeff = int
haftmann
parents: 44064
diff changeset
   287
  val iszero = (fn x => x = 0)
haftmann
parents: 44064
diff changeset
   288
  val add  = op +
haftmann
parents: 44064
diff changeset
   289
  val mk_sum = long_mk_sum    (*to work for e.g. 2*x + 3*x *)
haftmann
parents: 44064
diff changeset
   290
  val dest_sum = dest_sum
haftmann
parents: 44064
diff changeset
   291
  val mk_coeff = mk_coeff
haftmann
parents: 44064
diff changeset
   292
  val dest_coeff = dest_coeff 1
haftmann
parents: 44064
diff changeset
   293
  val left_distrib = @{thm combine_common_factor} RS trans
haftmann
parents: 44064
diff changeset
   294
  val prove_conv = Arith_Data.prove_conv_nohyps
44947
8ae418dfe561 dropped unused argument – avoids problem with SML/NJ
haftmann
parents: 44945
diff changeset
   295
  val trans_tac = trans_tac
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   296
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   297
  fun norm_tac ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   298
    ALLGOALS (simp_tac (put_simpset norm_ss1 ctxt))
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   299
    THEN ALLGOALS (simp_tac (put_simpset norm_ss2 ctxt))
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   300
    THEN ALLGOALS (simp_tac (put_simpset norm_ss3 ctxt))
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   301
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   302
  val numeral_simp_ss =
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   303
    simpset_of (put_simpset HOL_basic_ss \<^context> addsimps simps)
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   304
  fun numeral_simp_tac ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   305
    ALLGOALS (simp_tac (put_simpset numeral_simp_ss ctxt))
45437
958d19d3405b tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
huffman
parents: 45306
diff changeset
   306
  val simplify_meta_eq = Arith_Data.simplify_meta_eq post_simps
44945
haftmann
parents: 44064
diff changeset
   307
end;
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   308
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   309
structure CombineNumerals = CombineNumeralsFun(CombineNumeralsData);
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   310
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   311
(*Version for fields, where coefficients can be fractions*)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   312
structure FieldCombineNumeralsData =
44945
haftmann
parents: 44064
diff changeset
   313
struct
haftmann
parents: 44064
diff changeset
   314
  type coeff = int * int
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54230
diff changeset
   315
  val iszero = (fn (p, _) => p = 0)
44945
haftmann
parents: 44064
diff changeset
   316
  val add = add_frac
haftmann
parents: 44064
diff changeset
   317
  val mk_sum = long_mk_sum
haftmann
parents: 44064
diff changeset
   318
  val dest_sum = dest_sum
haftmann
parents: 44064
diff changeset
   319
  val mk_coeff = mk_fcoeff
haftmann
parents: 44064
diff changeset
   320
  val dest_coeff = dest_fcoeff 1
haftmann
parents: 44064
diff changeset
   321
  val left_distrib = @{thm combine_common_factor} RS trans
haftmann
parents: 44064
diff changeset
   322
  val prove_conv = Arith_Data.prove_conv_nohyps
44947
8ae418dfe561 dropped unused argument – avoids problem with SML/NJ
haftmann
parents: 44945
diff changeset
   323
  val trans_tac = trans_tac
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   324
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   325
  val norm_ss1a =
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   326
    simpset_of (put_simpset norm_ss1 \<^context> addsimps (inverse_1s @ divide_simps))
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   327
  fun norm_tac ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   328
    ALLGOALS (simp_tac (put_simpset norm_ss1a ctxt))
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   329
    THEN ALLGOALS (simp_tac (put_simpset norm_ss2 ctxt))
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   330
    THEN ALLGOALS (simp_tac (put_simpset norm_ss3 ctxt))
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   331
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   332
  val numeral_simp_ss =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   333
    simpset_of (put_simpset HOL_basic_ss \<^context>
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   334
      addsimps (simps @ @{thms add_frac_eq not_False_eq_True}))
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   335
  fun numeral_simp_tac ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   336
    ALLGOALS (simp_tac (put_simpset numeral_simp_ss ctxt))
45437
958d19d3405b tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
huffman
parents: 45306
diff changeset
   337
  val simplify_meta_eq = Arith_Data.simplify_meta_eq field_post_simps
44945
haftmann
parents: 44064
diff changeset
   338
end;
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   339
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   340
structure FieldCombineNumerals = CombineNumeralsFun(FieldCombineNumeralsData);
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   341
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   342
val combine_numerals = CombineNumerals.proc
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   343
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   344
val field_combine_numerals = FieldCombineNumerals.proc
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   345
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   346
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   347
(** Constant folding for multiplication in semirings **)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   348
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   349
(*We do not need folding for addition: combine_numerals does the same thing*)
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   350
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   351
structure Semiring_Times_Assoc_Data : ASSOC_FOLD_DATA =
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   352
struct
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   353
  val assoc_ss = simpset_of (put_simpset HOL_basic_ss \<^context> addsimps @{thms ac_simps minus_mult_commute})
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   354
  val eq_reflection = eq_reflection
35983
27e2fa7d4ce7 slightly more general simproc (avoids errors of linarith)
boehmes
parents: 35408
diff changeset
   355
  val is_numeral = can HOLogic.dest_number
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   356
end;
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   357
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   358
structure Semiring_Times_Assoc = Assoc_Fold (Semiring_Times_Assoc_Data);
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31067
diff changeset
   359
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59557
diff changeset
   360
fun assoc_fold ctxt ct = Semiring_Times_Assoc.proc ctxt (Thm.term_of ct)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   361
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   362
structure CancelNumeralFactorCommon =
44945
haftmann
parents: 44064
diff changeset
   363
struct
haftmann
parents: 44064
diff changeset
   364
  val mk_coeff = mk_coeff
haftmann
parents: 44064
diff changeset
   365
  val dest_coeff = dest_coeff 1
44947
8ae418dfe561 dropped unused argument – avoids problem with SML/NJ
haftmann
parents: 44945
diff changeset
   366
  val trans_tac = trans_tac
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   367
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   368
  val norm_ss1 =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   369
    simpset_of (put_simpset HOL_basic_ss \<^context> addsimps minus_from_mult_simps @ mult_1s)
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   370
  val norm_ss2 =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   371
    simpset_of (put_simpset HOL_basic_ss \<^context> addsimps simps @ mult_minus_simps)
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   372
  val norm_ss3 =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   373
    simpset_of (put_simpset HOL_basic_ss \<^context> addsimps @{thms ac_simps minus_mult_commute numeral_times_minus_swap})
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   374
  fun norm_tac ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   375
    ALLGOALS (simp_tac (put_simpset norm_ss1 ctxt))
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   376
    THEN ALLGOALS (simp_tac (put_simpset norm_ss2 ctxt))
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   377
    THEN ALLGOALS (simp_tac (put_simpset norm_ss3 ctxt))
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   378
45668
0ea1c705eebb use HOL_basic_ss instead of HOL_ss for internal simproc proofs (cf. b36eedcd1633)
huffman
parents: 45625
diff changeset
   379
  (* simp_thms are necessary because some of the cancellation rules below
0ea1c705eebb use HOL_basic_ss instead of HOL_ss for internal simproc proofs (cf. b36eedcd1633)
huffman
parents: 45625
diff changeset
   380
  (e.g. mult_less_cancel_left) introduce various logical connectives *)
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   381
  val numeral_simp_ss =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   382
    simpset_of (put_simpset HOL_basic_ss \<^context> addsimps simps @ @{thms simp_thms})
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   383
  fun numeral_simp_tac ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   384
    ALLGOALS (simp_tac (put_simpset numeral_simp_ss ctxt))
30518
07b45c1aa788 moved some generic nonsense to arith_data.ML
haftmann
parents: 30496
diff changeset
   385
  val simplify_meta_eq = Arith_Data.simplify_meta_eq
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   386
    (@{thms Nat.add_0 Nat.add_0_right} @ post_simps)
44945
haftmann
parents: 44064
diff changeset
   387
  val prove_conv = Arith_Data.prove_conv
haftmann
parents: 44064
diff changeset
   388
end
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   389
30931
86ca651da03e generalized some simprocs from int to semiring_div
haftmann
parents: 30685
diff changeset
   390
(*Version for semiring_div*)
86ca651da03e generalized some simprocs from int to semiring_div
haftmann
parents: 30685
diff changeset
   391
structure DivCancelNumeralFactor = CancelNumeralFactorFun
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   392
 (open CancelNumeralFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   393
  val mk_bal   = HOLogic.mk_binop \<^const_name>\<open>Rings.divide\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   394
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Rings.divide\<close> dummyT
30931
86ca651da03e generalized some simprocs from int to semiring_div
haftmann
parents: 30685
diff changeset
   395
  val cancel = @{thm div_mult_mult1} RS trans
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   396
  val neg_exchanges = false
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   397
)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   398
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   399
(*Version for fields*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   400
structure DivideCancelNumeralFactor = CancelNumeralFactorFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   401
 (open CancelNumeralFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   402
  val mk_bal   = HOLogic.mk_binop \<^const_name>\<open>Rings.divide\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   403
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Rings.divide\<close> dummyT
23413
5caa2710dd5b tuned laws for cancellation in divisions for fields.
nipkow
parents: 23401
diff changeset
   404
  val cancel = @{thm mult_divide_mult_cancel_left} RS trans
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   405
  val neg_exchanges = false
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   406
)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   407
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   408
structure EqCancelNumeralFactor = CancelNumeralFactorFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   409
 (open CancelNumeralFactorCommon
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   410
  val mk_bal   = HOLogic.mk_eq
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   411
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>HOL.eq\<close> dummyT
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   412
  val cancel = @{thm mult_cancel_left} RS trans
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   413
  val neg_exchanges = false
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   414
)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   415
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   416
structure LessCancelNumeralFactor = CancelNumeralFactorFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   417
 (open CancelNumeralFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   418
  val mk_bal   = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   419
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less\<close> dummyT
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   420
  val cancel = @{thm mult_less_cancel_left} RS trans
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   421
  val neg_exchanges = true
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   422
)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   423
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   424
structure LeCancelNumeralFactor = CancelNumeralFactorFun
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   425
(
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   426
  open CancelNumeralFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   427
  val mk_bal = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less_eq\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   428
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less_eq\<close> dummyT
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   429
  val cancel = @{thm mult_le_cancel_left} RS trans
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   430
  val neg_exchanges = true
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   431
)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   432
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   433
val eq_cancel_numeral_factor = EqCancelNumeralFactor.proc
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   434
val less_cancel_numeral_factor = LessCancelNumeralFactor.proc
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   435
val le_cancel_numeral_factor = LeCancelNumeralFactor.proc
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   436
val div_cancel_numeral_factor = DivCancelNumeralFactor.proc
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   437
val divide_cancel_numeral_factor = DivideCancelNumeralFactor.proc
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   438
57136
653e56c6c963 must not cancel common factors on both sides of (in)equations in linear arithmetic decicision procedure
nipkow
parents: 56282
diff changeset
   439
val field_divide_cancel_numeral_factor =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   440
  Simplifier.make_simproc \<^context> "field_divide_cancel_numeral_factor"
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   441
   {lhss =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   442
     [\<^term>\<open>((l::'a::field) * m) / n\<close>,
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   443
      \<^term>\<open>(l::'a::field) / (m * n)\<close>,
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   444
      \<^term>\<open>((numeral v)::'a::field) / (numeral w)\<close>,
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   445
      \<^term>\<open>((numeral v)::'a::field) / (- numeral w)\<close>,
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   446
      \<^term>\<open>((- numeral v)::'a::field) / (numeral w)\<close>,
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   447
      \<^term>\<open>((- numeral v)::'a::field) / (- numeral w)\<close>],
62913
13252110a6fe eliminated unused simproc identifier;
wenzelm
parents: 61694
diff changeset
   448
    proc = K DivideCancelNumeralFactor.proc}
57136
653e56c6c963 must not cancel common factors on both sides of (in)equations in linear arithmetic decicision procedure
nipkow
parents: 56282
diff changeset
   449
653e56c6c963 must not cancel common factors on both sides of (in)equations in linear arithmetic decicision procedure
nipkow
parents: 56282
diff changeset
   450
val field_cancel_numeral_factors =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   451
  [Simplifier.make_simproc \<^context> "field_eq_cancel_numeral_factor"
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   452
    {lhss =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   453
       [\<^term>\<open>(l::'a::field) * m = n\<close>,
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   454
        \<^term>\<open>(l::'a::field) = m * n\<close>],
62913
13252110a6fe eliminated unused simproc identifier;
wenzelm
parents: 61694
diff changeset
   455
      proc = K EqCancelNumeralFactor.proc},
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   456
   field_divide_cancel_numeral_factor]
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   457
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   458
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   459
(** Declarations for ExtractCommonTerm **)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   460
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   461
(*Find first term that matches u*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   462
fun find_first_t past u []         = raise TERM ("find_first_t", [])
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   463
  | find_first_t past u (t::terms) =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   464
        if u aconv t then (rev past @ terms)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   465
        else find_first_t (t::past) u terms
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   466
        handle TERM _ => find_first_t (t::past) u terms;
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   467
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   468
(** Final simplification for the CancelFactor simprocs **)
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   469
val simplify_one = Arith_Data.simplify_meta_eq
61694
6571c78c9667 Removed some legacy theorems; minor adjustments to simplification rules; new material on homotopic paths
paulson <lp15@cam.ac.uk>
parents: 61150
diff changeset
   470
  [@{thm mult_1_left}, @{thm mult_1_right}, @{thm div_by_1}, @{thm numeral_One}];
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   471
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   472
fun cancel_simplify_meta_eq ctxt cancel_th th =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   473
    simplify_one ctxt (([th, cancel_th]) MRS trans);
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   474
30649
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   475
local
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   476
  val Tp_Eq = Thm.reflexive (Thm.cterm_of \<^theory_context>\<open>HOL\<close> HOLogic.Trueprop)
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   477
  fun Eq_True_elim Eq =
30649
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   478
    Thm.equal_elim (Thm.combination Tp_Eq (Thm.symmetric Eq)) @{thm TrueI}
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   479
in
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   480
fun sign_conv pos_th neg_th ctxt t =
30649
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   481
  let val T = fastype_of t;
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   482
      val zero = Const(\<^const_name>\<open>Groups.zero\<close>, T);
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   483
      val less = Const(\<^const_name>\<open>Orderings.less\<close>, [T,T] ---> HOLogic.boolT);
30649
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   484
      val pos = less $ zero $ t and neg = less $ t $ zero
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   485
      fun prove p =
59642
929984c529d3 clarified context;
wenzelm
parents: 59621
diff changeset
   486
        SOME (Eq_True_elim (Simplifier.asm_rewrite ctxt (Thm.cterm_of ctxt p)))
30649
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   487
        handle THM _ => NONE
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   488
    in case prove pos of
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   489
         SOME th => SOME(th RS pos_th)
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   490
       | NONE => (case prove neg of
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   491
                    SOME th => SOME(th RS neg_th)
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   492
                  | NONE => NONE)
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   493
    end;
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   494
end
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   495
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   496
structure CancelFactorCommon =
44945
haftmann
parents: 44064
diff changeset
   497
struct
haftmann
parents: 44064
diff changeset
   498
  val mk_sum = long_mk_prod
haftmann
parents: 44064
diff changeset
   499
  val dest_sum = dest_prod
haftmann
parents: 44064
diff changeset
   500
  val mk_coeff = mk_coeff
haftmann
parents: 44064
diff changeset
   501
  val dest_coeff = dest_coeff
haftmann
parents: 44064
diff changeset
   502
  val find_first = find_first_t []
44947
8ae418dfe561 dropped unused argument – avoids problem with SML/NJ
haftmann
parents: 44945
diff changeset
   503
  val trans_tac = trans_tac
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   504
  val norm_ss =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   505
    simpset_of (put_simpset HOL_basic_ss \<^context> addsimps mult_1s @ @{thms ac_simps minus_mult_commute})
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   506
  fun norm_tac ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   507
    ALLGOALS (simp_tac (put_simpset norm_ss ctxt))
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   508
  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: 44984
diff changeset
   509
  fun mk_eq (a, b) = HOLogic.mk_Trueprop (HOLogic.mk_eq (a, b))
44945
haftmann
parents: 44064
diff changeset
   510
end;
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   511
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   512
(*mult_cancel_left requires a ring with no zero divisors.*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   513
structure EqCancelFactor = ExtractCommonTermFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   514
 (open CancelFactorCommon
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   515
  val mk_bal   = HOLogic.mk_eq
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   516
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>HOL.eq\<close> dummyT
31368
763f4b0fd579 made SML/NJ happy;
wenzelm
parents: 31101
diff changeset
   517
  fun simp_conv _ _ = SOME @{thm mult_cancel_left}
30649
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   518
);
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   519
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   520
(*for ordered rings*)
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   521
structure LeCancelFactor = ExtractCommonTermFun
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   522
 (open CancelFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   523
  val mk_bal   = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less_eq\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   524
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less_eq\<close> dummyT
30649
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   525
  val simp_conv = sign_conv
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   526
    @{thm mult_le_cancel_left_pos} @{thm mult_le_cancel_left_neg}
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   527
);
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   528
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   529
(*for ordered rings*)
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   530
structure LessCancelFactor = ExtractCommonTermFun
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   531
 (open CancelFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   532
  val mk_bal   = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   533
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less\<close> dummyT
30649
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   534
  val simp_conv = sign_conv
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 30518
diff changeset
   535
    @{thm mult_less_cancel_left_pos} @{thm mult_less_cancel_left_neg}
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   536
);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   537
30931
86ca651da03e generalized some simprocs from int to semiring_div
haftmann
parents: 30685
diff changeset
   538
(*for semirings with division*)
86ca651da03e generalized some simprocs from int to semiring_div
haftmann
parents: 30685
diff changeset
   539
structure DivCancelFactor = ExtractCommonTermFun
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   540
 (open CancelFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   541
  val mk_bal   = HOLogic.mk_binop \<^const_name>\<open>Rings.divide\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   542
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Rings.divide\<close> dummyT
31368
763f4b0fd579 made SML/NJ happy;
wenzelm
parents: 31101
diff changeset
   543
  fun simp_conv _ _ = SOME @{thm div_mult_mult1_if}
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   544
);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   545
30931
86ca651da03e generalized some simprocs from int to semiring_div
haftmann
parents: 30685
diff changeset
   546
structure ModCancelFactor = ExtractCommonTermFun
24395
8df021f79e0b Added mod cancellation simproc
nipkow
parents: 23969
diff changeset
   547
 (open CancelFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   548
  val mk_bal   = HOLogic.mk_binop \<^const_name>\<open>modulo\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   549
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>modulo\<close> dummyT
31368
763f4b0fd579 made SML/NJ happy;
wenzelm
parents: 31101
diff changeset
   550
  fun simp_conv _ _ = SOME @{thm mod_mult_mult1}
24395
8df021f79e0b Added mod cancellation simproc
nipkow
parents: 23969
diff changeset
   551
);
8df021f79e0b Added mod cancellation simproc
nipkow
parents: 23969
diff changeset
   552
30931
86ca651da03e generalized some simprocs from int to semiring_div
haftmann
parents: 30685
diff changeset
   553
(*for idoms*)
86ca651da03e generalized some simprocs from int to semiring_div
haftmann
parents: 30685
diff changeset
   554
structure DvdCancelFactor = ExtractCommonTermFun
23969
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   555
 (open CancelFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   556
  val mk_bal   = HOLogic.mk_binrel \<^const_name>\<open>Rings.dvd\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   557
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Rings.dvd\<close> dummyT
31368
763f4b0fd579 made SML/NJ happy;
wenzelm
parents: 31101
diff changeset
   558
  fun simp_conv _ _ = SOME @{thm dvd_mult_cancel_left}
23969
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   559
);
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23881
diff changeset
   560
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   561
(*Version for all fields, including unordered ones (type complex).*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   562
structure DivideCancelFactor = ExtractCommonTermFun
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   563
 (open CancelFactorCommon
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   564
  val mk_bal   = HOLogic.mk_binop \<^const_name>\<open>Rings.divide\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   565
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Rings.divide\<close> dummyT
31368
763f4b0fd579 made SML/NJ happy;
wenzelm
parents: 31101
diff changeset
   566
  fun simp_conv _ _ = SOME @{thm mult_divide_mult_cancel_left_if}
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   567
);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   568
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59557
diff changeset
   569
fun eq_cancel_factor ctxt ct = EqCancelFactor.proc ctxt (Thm.term_of ct)
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59557
diff changeset
   570
fun le_cancel_factor ctxt ct = LeCancelFactor.proc ctxt (Thm.term_of ct)
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59557
diff changeset
   571
fun less_cancel_factor ctxt ct = LessCancelFactor.proc ctxt (Thm.term_of ct)
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59557
diff changeset
   572
fun div_cancel_factor ctxt ct = DivCancelFactor.proc ctxt (Thm.term_of ct)
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59557
diff changeset
   573
fun mod_cancel_factor ctxt ct = ModCancelFactor.proc ctxt (Thm.term_of ct)
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59557
diff changeset
   574
fun dvd_cancel_factor ctxt ct = DvdCancelFactor.proc ctxt (Thm.term_of ct)
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59557
diff changeset
   575
fun divide_cancel_factor ctxt ct = DivideCancelFactor.proc ctxt (Thm.term_of ct)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   576
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   577
local
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   578
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   579
val cterm_of = Thm.cterm_of \<^context>;
61150
d85d8f5e921b tuned -- avoid slightly odd @{cpat};
wenzelm
parents: 61144
diff changeset
   580
fun tvar S = (("'a", 0), S);
d85d8f5e921b tuned -- avoid slightly odd @{cpat};
wenzelm
parents: 61144
diff changeset
   581
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   582
val zero_tvar = tvar \<^sort>\<open>zero\<close>;
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   583
val zero = cterm_of (Const (\<^const_name>\<open>zero_class.zero\<close>, TVar zero_tvar));
61150
d85d8f5e921b tuned -- avoid slightly odd @{cpat};
wenzelm
parents: 61144
diff changeset
   584
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   585
val type_tvar = tvar \<^sort>\<open>type\<close>;
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   586
val geq = cterm_of (Const (\<^const_name>\<open>HOL.eq\<close>, TVar type_tvar --> TVar type_tvar --> \<^typ>\<open>bool\<close>));
61150
d85d8f5e921b tuned -- avoid slightly odd @{cpat};
wenzelm
parents: 61144
diff changeset
   587
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   588
val add_frac_eq = mk_meta_eq @{thm add_frac_eq}
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   589
val add_frac_num = mk_meta_eq @{thm add_frac_num}
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   590
val add_num_frac = mk_meta_eq @{thm add_num_frac}
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   591
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   592
fun prove_nz ctxt T t =
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   593
  let
74282
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 69593
diff changeset
   594
    val z = Thm.instantiate_cterm (TVars.make [(zero_tvar, T)], Vars.empty) zero
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 69593
diff changeset
   595
    val eq = Thm.instantiate_cterm (TVars.make [(type_tvar, T)], Vars.empty) geq
61150
d85d8f5e921b tuned -- avoid slightly odd @{cpat};
wenzelm
parents: 61144
diff changeset
   596
    val th =
d85d8f5e921b tuned -- avoid slightly odd @{cpat};
wenzelm
parents: 61144
diff changeset
   597
      Simplifier.rewrite (ctxt addsimps @{thms simp_thms})
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   598
        (Thm.apply \<^cterm>\<open>Trueprop\<close> (Thm.apply \<^cterm>\<open>Not\<close>
61150
d85d8f5e921b tuned -- avoid slightly odd @{cpat};
wenzelm
parents: 61144
diff changeset
   599
          (Thm.apply (Thm.apply eq t) z)))
d85d8f5e921b tuned -- avoid slightly odd @{cpat};
wenzelm
parents: 61144
diff changeset
   600
  in Thm.equal_elim (Thm.symmetric th) TrueI end
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   601
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   602
fun proc ctxt ct =
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   603
  let
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   604
    val ((x,y),(w,z)) =
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   605
         (Thm.dest_binop #> (fn (a,b) => (Thm.dest_binop a, Thm.dest_binop b))) ct
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59557
diff changeset
   606
    val _ = map (HOLogic.dest_number o Thm.term_of) [x,y,z,w]
59586
ddf6deaadfe8 clarified signature;
wenzelm
parents: 59582
diff changeset
   607
    val T = Thm.ctyp_of_cterm x
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   608
    val [y_nz, z_nz] = map (prove_nz ctxt T) [y, z]
60801
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   609
    val th = Thm.instantiate' [SOME T] (map SOME [y,z,x,w]) add_frac_eq
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   610
  in SOME (Thm.implies_elim (Thm.implies_elim th y_nz) z_nz) end
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   611
  handle CTERM _ => NONE | TERM _ => NONE | THM _ => NONE
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   612
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   613
fun proc2 ctxt ct =
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   614
  let
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   615
    val (l,r) = Thm.dest_binop ct
59586
ddf6deaadfe8 clarified signature;
wenzelm
parents: 59582
diff changeset
   616
    val T = Thm.ctyp_of_cterm l
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59557
diff changeset
   617
  in (case (Thm.term_of l, Thm.term_of r) of
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   618
      (Const(\<^const_name>\<open>Rings.divide\<close>,_)$_$_, _) =>
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   619
        let val (x,y) = Thm.dest_binop l val z = r
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59557
diff changeset
   620
            val _ = map (HOLogic.dest_number o Thm.term_of) [x,y,z]
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   621
            val ynz = prove_nz ctxt T y
60801
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   622
        in SOME (Thm.implies_elim (Thm.instantiate' [SOME T] (map SOME [y,x,z]) add_frac_num) ynz)
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   623
        end
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   624
     | (_, Const (\<^const_name>\<open>Rings.divide\<close>,_)$_$_) =>
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   625
        let val (x,y) = Thm.dest_binop r val z = l
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59557
diff changeset
   626
            val _ = map (HOLogic.dest_number o Thm.term_of) [x,y,z]
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   627
            val ynz = prove_nz ctxt T y
60801
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   628
        in SOME (Thm.implies_elim (Thm.instantiate' [SOME T] (map SOME [y,z,x]) add_num_frac) ynz)
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   629
        end
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   630
     | _ => NONE)
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   631
  end
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   632
  handle CTERM _ => NONE | TERM _ => NONE | THM _ => NONE
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   633
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   634
fun is_number (Const(\<^const_name>\<open>Rings.divide\<close>,_)$a$b) = is_number a andalso is_number b
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   635
  | is_number t = can HOLogic.dest_number t
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   636
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   637
val is_number = is_number o Thm.term_of
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   638
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   639
fun proc3 ctxt ct =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59557
diff changeset
   640
  (case Thm.term_of ct of
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   641
    Const(\<^const_name>\<open>Orderings.less\<close>,_)$(Const(\<^const_name>\<open>Rings.divide\<close>,_)$_$_)$_ =>
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   642
      let
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   643
        val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   644
        val _ = map is_number [a,b,c]
59586
ddf6deaadfe8 clarified signature;
wenzelm
parents: 59582
diff changeset
   645
        val T = Thm.ctyp_of_cterm c
60801
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   646
        val th = Thm.instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_less_eq"}
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   647
      in SOME (mk_meta_eq th) end
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   648
  | Const(\<^const_name>\<open>Orderings.less_eq\<close>,_)$(Const(\<^const_name>\<open>Rings.divide\<close>,_)$_$_)$_ =>
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   649
      let
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   650
        val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   651
        val _ = map is_number [a,b,c]
59586
ddf6deaadfe8 clarified signature;
wenzelm
parents: 59582
diff changeset
   652
        val T = Thm.ctyp_of_cterm c
60801
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   653
        val th = Thm.instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_le_eq"}
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   654
      in SOME (mk_meta_eq th) end
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   655
  | Const(\<^const_name>\<open>HOL.eq\<close>,_)$(Const(\<^const_name>\<open>Rings.divide\<close>,_)$_$_)$_ =>
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   656
      let
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   657
        val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   658
        val _ = map is_number [a,b,c]
59586
ddf6deaadfe8 clarified signature;
wenzelm
parents: 59582
diff changeset
   659
        val T = Thm.ctyp_of_cterm c
60801
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   660
        val th = Thm.instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_eq_eq"}
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   661
      in SOME (mk_meta_eq th) end
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   662
  | Const(\<^const_name>\<open>Orderings.less\<close>,_)$_$(Const(\<^const_name>\<open>Rings.divide\<close>,_)$_$_) =>
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   663
    let
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   664
      val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   665
        val _ = map is_number [a,b,c]
59586
ddf6deaadfe8 clarified signature;
wenzelm
parents: 59582
diff changeset
   666
        val T = Thm.ctyp_of_cterm c
60801
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   667
        val th = Thm.instantiate' [SOME T] (map SOME [a,b,c]) @{thm "less_divide_eq"}
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   668
      in SOME (mk_meta_eq th) end
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   669
  | Const(\<^const_name>\<open>Orderings.less_eq\<close>,_)$_$(Const(\<^const_name>\<open>Rings.divide\<close>,_)$_$_) =>
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   670
    let
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   671
      val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   672
        val _ = map is_number [a,b,c]
59586
ddf6deaadfe8 clarified signature;
wenzelm
parents: 59582
diff changeset
   673
        val T = Thm.ctyp_of_cterm c
60801
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   674
        val th = Thm.instantiate' [SOME T] (map SOME [a,b,c]) @{thm "le_divide_eq"}
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   675
      in SOME (mk_meta_eq th) end
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   676
  | Const(\<^const_name>\<open>HOL.eq\<close>,_)$_$(Const(\<^const_name>\<open>Rings.divide\<close>,_)$_$_) =>
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   677
    let
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   678
      val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   679
        val _ = map is_number [a,b,c]
59586
ddf6deaadfe8 clarified signature;
wenzelm
parents: 59582
diff changeset
   680
        val T = Thm.ctyp_of_cterm c
60801
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   681
        val th = Thm.instantiate' [SOME T] (map SOME [a,b,c]) @{thm "eq_divide_eq"}
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   682
      in SOME (mk_meta_eq th) end
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   683
  | _ => NONE) handle TERM _ => NONE | CTERM _ => NONE | THM _ => NONE
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   684
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   685
val add_frac_frac_simproc =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   686
  Simplifier.make_simproc \<^context> "add_frac_frac_simproc"
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   687
   {lhss = [\<^term>\<open>(x::'a::field) / y + (w::'a::field) / z\<close>],
62913
13252110a6fe eliminated unused simproc identifier;
wenzelm
parents: 61694
diff changeset
   688
    proc = K proc}
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   689
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   690
val add_frac_num_simproc =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   691
  Simplifier.make_simproc \<^context> "add_frac_num_simproc"
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   692
   {lhss = [\<^term>\<open>(x::'a::field) / y + z\<close>, \<^term>\<open>z + (x::'a::field) / y\<close>],
62913
13252110a6fe eliminated unused simproc identifier;
wenzelm
parents: 61694
diff changeset
   693
    proc = K proc2}
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   694
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   695
val ord_frac_simproc =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   696
  Simplifier.make_simproc \<^context> "ord_frac_simproc"
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 60801
diff changeset
   697
   {lhss =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   698
     [\<^term>\<open>(a::'a::{field,ord}) / b < c\<close>,
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   699
      \<^term>\<open>(a::'a::{field,ord}) / b \<le> c\<close>,
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   700
      \<^term>\<open>c < (a::'a::{field,ord}) / b\<close>,
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   701
      \<^term>\<open>c \<le> (a::'a::{field,ord}) / b\<close>,
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   702
      \<^term>\<open>c = (a::'a::{field,ord}) / b\<close>,
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   703
      \<^term>\<open>(a::'a::{field, ord}) / b = c\<close>],
62913
13252110a6fe eliminated unused simproc identifier;
wenzelm
parents: 61694
diff changeset
   704
    proc = K proc3}
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   705
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   706
val field_comp_ss =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   707
  simpset_of
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67561
diff changeset
   708
    (put_simpset HOL_basic_ss \<^context>
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   709
      addsimps @{thms semiring_norm
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   710
        mult_numeral_1
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   711
        mult_numeral_1_right
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   712
        divide_numeral_1
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   713
        div_by_0
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   714
        div_0
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   715
        divide_divide_eq_left
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   716
        times_divide_eq_left
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   717
        times_divide_eq_right
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   718
        times_divide_times_eq
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   719
        divide_divide_eq_right
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   720
        diff_conv_add_uminus
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   721
        minus_divide_left
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   722
        add_divide_distrib [symmetric]
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   723
        Fields.field_divide_inverse [symmetric]
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   724
        inverse_divide
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   725
        divide_inverse_commute [symmetric]
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   726
        simp_thms}
45620
f2a587696afb modernized some old-style infix operations, which were left over from the time of ML proof scripts;
wenzelm
parents: 45437
diff changeset
   727
      addsimprocs field_cancel_numeral_factors
f2a587696afb modernized some old-style infix operations, which were left over from the time of ML proof scripts;
wenzelm
parents: 45437
diff changeset
   728
      addsimprocs [add_frac_frac_simproc, add_frac_num_simproc, ord_frac_simproc]
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   729
      |> Simplifier.add_cong @{thm if_weak_cong})
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   730
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   731
in
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   732
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   733
fun field_comp_conv ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 49323
diff changeset
   734
  Simplifier.rewrite (put_simpset field_comp_ss ctxt)
45620
f2a587696afb modernized some old-style infix operations, which were left over from the time of ML proof scripts;
wenzelm
parents: 45437
diff changeset
   735
  then_conv
75879
24b17460ee60 streamlined simpset building, avoiding duplicated rewrite rules
haftmann
parents: 74282
diff changeset
   736
  Simplifier.rewrite (put_simpset HOL_basic_ss ctxt addsimps @{thms numeral_One})
36751
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   737
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   738
end
7f1da69cacb3 split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
haftmann
parents: 36409
diff changeset
   739
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   740
end;