src/HOL/Tools/Groebner_Basis/normalizer.ML
author chaieb
Sun, 05 Apr 2009 05:07:10 +0100
changeset 30866 dd5117e2d73e
parent 29269 5c25a2012975
child 31790 05c92381363c
permissions -rw-r--r--
now deals with devision in fields
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Tools/Groebner_Basis/normalizer.ML
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
     2
    Author:     Amine Chaieb, TU Muenchen
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
     3
*)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
     4
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
     5
signature NORMALIZER = 
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
     6
sig
23485
881b04972953 made type conv pervasive;
wenzelm
parents: 23407
diff changeset
     7
 val semiring_normalize_conv : Proof.context -> conv
881b04972953 made type conv pervasive;
wenzelm
parents: 23407
diff changeset
     8
 val semiring_normalize_ord_conv : Proof.context -> (cterm -> cterm -> bool) -> conv
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
     9
 val semiring_normalize_tac : Proof.context -> int -> tactic
23485
881b04972953 made type conv pervasive;
wenzelm
parents: 23407
diff changeset
    10
 val semiring_normalize_wrapper :  Proof.context -> NormalizerData.entry -> conv
27222
b08abdb8f499 Export a wrapper for all semiring_normalizers
chaieb
parents: 25481
diff changeset
    11
 val semiring_normalizers_ord_wrapper :  
b08abdb8f499 Export a wrapper for all semiring_normalizers
chaieb
parents: 25481
diff changeset
    12
     Proof.context -> NormalizerData.entry -> (cterm -> cterm -> bool) ->
b08abdb8f499 Export a wrapper for all semiring_normalizers
chaieb
parents: 25481
diff changeset
    13
      {add: conv, mul: conv, neg: conv, main: conv, pow: conv, sub: conv}
23485
881b04972953 made type conv pervasive;
wenzelm
parents: 23407
diff changeset
    14
 val semiring_normalize_ord_wrapper :  Proof.context -> NormalizerData.entry ->
881b04972953 made type conv pervasive;
wenzelm
parents: 23407
diff changeset
    15
   (cterm -> cterm -> bool) -> conv
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    16
 val semiring_normalizers_conv :
30866
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
    17
     cterm list -> cterm list * thm list -> cterm list * thm list -> cterm list * thm list ->
23485
881b04972953 made type conv pervasive;
wenzelm
parents: 23407
diff changeset
    18
     (cterm -> bool) * conv * conv * conv -> (cterm -> cterm -> bool) ->
881b04972953 made type conv pervasive;
wenzelm
parents: 23407
diff changeset
    19
       {add: conv, mul: conv, neg: conv, main: conv, pow: conv, sub: conv}
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    20
end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    21
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    22
structure Normalizer: NORMALIZER = 
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    23
struct
23559
wenzelm
parents: 23485
diff changeset
    24
25253
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    25
open Conv;
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    26
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    27
(* Very basic stuff for terms *)
25253
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    28
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    29
fun is_comb ct =
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    30
  (case Thm.term_of ct of
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    31
    _ $ _ => true
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    32
  | _ => false);
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    33
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    34
val concl = Thm.cprop_of #> Thm.dest_arg;
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    35
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    36
fun is_binop ct ct' =
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    37
  (case Thm.term_of ct' of
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    38
    c $ _ $ _ => term_of ct aconv c
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    39
  | _ => false);
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    40
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    41
fun dest_binop ct ct' =
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    42
  if is_binop ct ct' then Thm.dest_binop ct'
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    43
  else raise CTERM ("dest_binop: bad binop", [ct, ct'])
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    44
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    45
fun inst_thm inst = Thm.instantiate ([], inst);
c642b36f2bec changed signature according to normalizer_data.ML
chaieb
parents: 23880
diff changeset
    46
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    47
val dest_numeral = term_of #> HOLogic.dest_number #> snd;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    48
val is_numeral = can dest_numeral;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    49
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    50
val numeral01_conv = Simplifier.rewrite
25481
aa16cd919dcc dropped legacy ml bindings
haftmann
parents: 25253
diff changeset
    51
                         (HOL_basic_ss addsimps [@{thm numeral_1_eq_1}, @{thm numeral_0_eq_0}]);
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    52
val zero1_numeral_conv = 
25481
aa16cd919dcc dropped legacy ml bindings
haftmann
parents: 25253
diff changeset
    53
 Simplifier.rewrite (HOL_basic_ss addsimps [@{thm numeral_1_eq_1} RS sym, @{thm numeral_0_eq_0} RS sym]);
23580
998a6fda9bb6 moved mk_cnumeral/mk_cnumber to Tools/numeral.ML;
wenzelm
parents: 23559
diff changeset
    54
fun zerone_conv cv = zero1_numeral_conv then_conv cv then_conv numeral01_conv;
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    55
val natarith = [@{thm "add_nat_number_of"}, @{thm "diff_nat_number_of"},
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    56
                @{thm "mult_nat_number_of"}, @{thm "eq_nat_number_of"}, 
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    57
                @{thm "less_nat_number_of"}];
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    58
val nat_add_conv = 
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    59
 zerone_conv 
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    60
  (Simplifier.rewrite 
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    61
    (HOL_basic_ss 
25481
aa16cd919dcc dropped legacy ml bindings
haftmann
parents: 25253
diff changeset
    62
       addsimps @{thms arith_simps} @ natarith @ @{thms rel_simps}
aa16cd919dcc dropped legacy ml bindings
haftmann
parents: 25253
diff changeset
    63
             @ [if_False, if_True, @{thm add_0}, @{thm add_Suc},
aa16cd919dcc dropped legacy ml bindings
haftmann
parents: 25253
diff changeset
    64
                 @{thm add_number_of_left}, @{thm Suc_eq_add_numeral_1}]
aa16cd919dcc dropped legacy ml bindings
haftmann
parents: 25253
diff changeset
    65
             @ map (fn th => th RS sym) @{thms numerals}));
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    66
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    67
val nat_mul_conv = nat_add_conv;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    68
val zeron_tm = @{cterm "0::nat"};
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    69
val onen_tm  = @{cterm "1::nat"};
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    70
val true_tm = @{cterm "True"};
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    71
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    72
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    73
(* The main function! *)
30866
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
    74
fun semiring_normalizers_conv vars (sr_ops, sr_rules) (r_ops, r_rules) (f_ops, f_rules)
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    75
  (is_semiring_constant, semiring_add_conv, semiring_mul_conv, semiring_pow_conv) =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    76
let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    77
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    78
val [pthm_02, pthm_03, pthm_04, pthm_05, pthm_07, pthm_08,
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    79
     pthm_09, pthm_10, pthm_11, pthm_12, pthm_13, pthm_14, pthm_15, pthm_16,
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    80
     pthm_17, pthm_18, pthm_19, pthm_21, pthm_22, pthm_23, pthm_24,
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    81
     pthm_25, pthm_26, pthm_27, pthm_28, pthm_29, pthm_30, pthm_31, pthm_32,
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    82
     pthm_33, pthm_34, pthm_35, pthm_36, pthm_37, pthm_38,pthm_39,pthm_40] = sr_rules;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    83
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    84
val [ca, cb, cc, cd, cm, cn, cp, cq, cx, cy, cz, clx, crx, cly, cry] = vars;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    85
val [add_pat, mul_pat, pow_pat, zero_tm, one_tm] = sr_ops;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    86
val [add_tm, mul_tm, pow_tm] = map (Thm.dest_fun o Thm.dest_fun) [add_pat, mul_pat, pow_pat];
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    87
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    88
val dest_add = dest_binop add_tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    89
val dest_mul = dest_binop mul_tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    90
fun dest_pow tm =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    91
 let val (l,r) = dest_binop pow_tm tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    92
 in if is_numeral r then (l,r) else raise CTERM ("dest_pow",[tm])
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    93
 end;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    94
val is_add = is_binop add_tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    95
val is_mul = is_binop mul_tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    96
fun is_pow tm = is_binop pow_tm tm andalso is_numeral(Thm.dest_arg tm);
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    97
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    98
val (neg_mul,sub_add,sub_tm,neg_tm,dest_sub,is_sub,cx',cy') =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
    99
  (case (r_ops, r_rules) of
30866
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   100
    ([sub_pat, neg_pat], [neg_mul, sub_add]) =>
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   101
      let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   102
        val sub_tm = Thm.dest_fun (Thm.dest_fun sub_pat)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   103
        val neg_tm = Thm.dest_fun neg_pat
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   104
        val dest_sub = dest_binop sub_tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   105
        val is_sub = is_binop sub_tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   106
      in (neg_mul,sub_add,sub_tm,neg_tm,dest_sub,is_sub, neg_mul |> concl |> Thm.dest_arg,
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   107
          sub_add |> concl |> Thm.dest_arg |> Thm.dest_arg)
30866
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   108
      end
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   109
    | _ => (TrueI, TrueI, true_tm, true_tm, (fn t => (t,t)), K false, true_tm, true_tm));
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   110
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   111
val (divide_inverse, inverse_divide, divide_tm, inverse_tm, is_divide) = 
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   112
  (case (f_ops, f_rules) of 
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   113
   ([divide_pat, inverse_pat], [div_inv, inv_div]) => 
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   114
     let val div_tm = funpow 2 Thm.dest_fun divide_pat
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   115
         val inv_tm = Thm.dest_fun inverse_pat
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   116
     in (div_inv, inv_div, div_tm, inv_tm, is_binop div_tm)
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   117
     end
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   118
   | _ => (TrueI, TrueI, true_tm, true_tm, K false));
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   119
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   120
in fn variable_order =>
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   121
 let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   122
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   123
(* Conversion for "x^n * x^m", with either x^n = x and/or x^m = x possible.  *)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   124
(* Also deals with "const * const", but both terms must involve powers of    *)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   125
(* the same variable, or both be constants, or behaviour may be incorrect.   *)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   126
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   127
 fun powvar_mul_conv tm =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   128
  let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   129
  val (l,r) = dest_mul tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   130
  in if is_semiring_constant l andalso is_semiring_constant r
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   131
     then semiring_mul_conv tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   132
     else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   133
      ((let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   134
         val (lx,ln) = dest_pow l
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   135
        in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   136
         ((let val (rx,rn) = dest_pow r
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   137
               val th1 = inst_thm [(cx,lx),(cp,ln),(cq,rn)] pthm_29
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   138
                val (tm1,tm2) = Thm.dest_comb(concl th1) in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   139
               transitive th1 (Drule.arg_cong_rule tm1 (nat_add_conv tm2)) end)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   140
           handle CTERM _ =>
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   141
            (let val th1 = inst_thm [(cx,lx),(cq,ln)] pthm_31
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   142
                 val (tm1,tm2) = Thm.dest_comb(concl th1) in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   143
               transitive th1 (Drule.arg_cong_rule tm1 (nat_add_conv tm2)) end)) end)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   144
       handle CTERM _ =>
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   145
           ((let val (rx,rn) = dest_pow r
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   146
                val th1 = inst_thm [(cx,rx),(cq,rn)] pthm_30
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   147
                val (tm1,tm2) = Thm.dest_comb(concl th1) in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   148
               transitive th1 (Drule.arg_cong_rule tm1 (nat_add_conv tm2)) end)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   149
           handle CTERM _ => inst_thm [(cx,l)] pthm_32
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   150
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   151
))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   152
 end;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   153
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   154
(* Remove "1 * m" from a monomial, and just leave m.                         *)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   155
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   156
 fun monomial_deone th =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   157
       (let val (l,r) = dest_mul(concl th) in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   158
           if l aconvc one_tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   159
          then transitive th (inst_thm [(ca,r)] pthm_13)  else th end)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   160
       handle CTERM _ => th;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   161
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   162
(* Conversion for "(monomial)^n", where n is a numeral.                      *)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   163
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   164
 val monomial_pow_conv =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   165
  let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   166
   fun monomial_pow tm bod ntm =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   167
    if not(is_comb bod)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   168
    then reflexive tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   169
    else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   170
     if is_semiring_constant bod
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   171
     then semiring_pow_conv tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   172
     else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   173
      let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   174
      val (lopr,r) = Thm.dest_comb bod
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   175
      in if not(is_comb lopr)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   176
         then reflexive tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   177
        else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   178
          let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   179
          val (opr,l) = Thm.dest_comb lopr
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   180
         in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   181
           if opr aconvc pow_tm andalso is_numeral r
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   182
          then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   183
            let val th1 = inst_thm [(cx,l),(cp,r),(cq,ntm)] pthm_34
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   184
                val (l,r) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   185
           in transitive th1 (Drule.arg_cong_rule l (nat_mul_conv r))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   186
           end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   187
           else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   188
            if opr aconvc mul_tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   189
            then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   190
             let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   191
              val th1 = inst_thm [(cx,l),(cy,r),(cq,ntm)] pthm_33
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   192
             val (xy,z) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   193
              val (x,y) = Thm.dest_comb xy
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   194
              val thl = monomial_pow y l ntm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   195
              val thr = monomial_pow z r ntm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   196
             in transitive th1 (combination (Drule.arg_cong_rule x thl) thr)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   197
             end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   198
             else reflexive tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   199
          end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   200
      end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   201
  in fn tm =>
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   202
   let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   203
    val (lopr,r) = Thm.dest_comb tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   204
    val (opr,l) = Thm.dest_comb lopr
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   205
   in if not (opr aconvc pow_tm) orelse not(is_numeral r)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   206
      then raise CTERM ("monomial_pow_conv", [tm])
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   207
      else if r aconvc zeron_tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   208
      then inst_thm [(cx,l)] pthm_35
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   209
      else if r aconvc onen_tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   210
      then inst_thm [(cx,l)] pthm_36
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   211
      else monomial_deone(monomial_pow tm l r)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   212
   end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   213
  end;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   214
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   215
(* Multiplication of canonical monomials.                                    *)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   216
 val monomial_mul_conv =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   217
  let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   218
   fun powvar tm =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   219
    if is_semiring_constant tm then one_tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   220
    else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   221
     ((let val (lopr,r) = Thm.dest_comb tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   222
           val (opr,l) = Thm.dest_comb lopr
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   223
       in if opr aconvc pow_tm andalso is_numeral r then l 
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   224
          else raise CTERM ("monomial_mul_conv",[tm]) end)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   225
     handle CTERM _ => tm)   (* FIXME !? *)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   226
   fun  vorder x y =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   227
    if x aconvc y then 0
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   228
    else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   229
     if x aconvc one_tm then ~1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   230
     else if y aconvc one_tm then 1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   231
      else if variable_order x y then ~1 else 1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   232
   fun monomial_mul tm l r =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   233
    ((let val (lx,ly) = dest_mul l val vl = powvar lx
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   234
      in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   235
      ((let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   236
        val (rx,ry) = dest_mul r
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   237
         val vr = powvar rx
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   238
         val ord = vorder vl vr
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   239
        in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   240
         if ord = 0
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   241
        then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   242
          let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   243
             val th1 = inst_thm [(clx,lx),(cly,ly),(crx,rx),(cry,ry)] pthm_15
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   244
             val (tm1,tm2) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   245
             val (tm3,tm4) = Thm.dest_comb tm1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   246
             val th2 = Drule.fun_cong_rule (Drule.arg_cong_rule tm3 (powvar_mul_conv tm4)) tm2
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   247
             val th3 = transitive th1 th2
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   248
              val  (tm5,tm6) = Thm.dest_comb(concl th3)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   249
              val  (tm7,tm8) = Thm.dest_comb tm6
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   250
             val  th4 = monomial_mul tm6 (Thm.dest_arg tm7) tm8
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   251
         in  transitive th3 (Drule.arg_cong_rule tm5 th4)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   252
         end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   253
         else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   254
          let val th0 = if ord < 0 then pthm_16 else pthm_17
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   255
             val th1 = inst_thm [(clx,lx),(cly,ly),(crx,rx),(cry,ry)] th0
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   256
             val (tm1,tm2) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   257
             val (tm3,tm4) = Thm.dest_comb tm2
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   258
         in transitive th1 (Drule.arg_cong_rule tm1 (monomial_mul tm2 (Thm.dest_arg tm3) tm4))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   259
         end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   260
        end)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   261
       handle CTERM _ =>
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   262
        (let val vr = powvar r val ord = vorder vl vr
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   263
        in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   264
          if ord = 0 then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   265
           let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   266
           val th1 = inst_thm [(clx,lx),(cly,ly),(crx,r)] pthm_18
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   267
                 val (tm1,tm2) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   268
           val (tm3,tm4) = Thm.dest_comb tm1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   269
           val th2 = Drule.fun_cong_rule (Drule.arg_cong_rule tm3 (powvar_mul_conv tm4)) tm2
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   270
          in transitive th1 th2
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   271
          end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   272
          else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   273
          if ord < 0 then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   274
            let val th1 = inst_thm [(clx,lx),(cly,ly),(crx,r)] pthm_19
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   275
                val (tm1,tm2) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   276
                val (tm3,tm4) = Thm.dest_comb tm2
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   277
           in transitive th1 (Drule.arg_cong_rule tm1 (monomial_mul tm2 (Thm.dest_arg tm3) tm4))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   278
           end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   279
           else inst_thm [(ca,l),(cb,r)] pthm_09
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   280
        end)) end)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   281
     handle CTERM _ =>
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   282
      (let val vl = powvar l in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   283
        ((let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   284
          val (rx,ry) = dest_mul r
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   285
          val vr = powvar rx
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   286
           val ord = vorder vl vr
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   287
         in if ord = 0 then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   288
              let val th1 = inst_thm [(clx,l),(crx,rx),(cry,ry)] pthm_21
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   289
                 val (tm1,tm2) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   290
                 val (tm3,tm4) = Thm.dest_comb tm1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   291
             in transitive th1 (Drule.fun_cong_rule (Drule.arg_cong_rule tm3 (powvar_mul_conv tm4)) tm2)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   292
             end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   293
             else if ord > 0 then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   294
                 let val th1 = inst_thm [(clx,l),(crx,rx),(cry,ry)] pthm_22
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   295
                     val (tm1,tm2) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   296
                    val (tm3,tm4) = Thm.dest_comb tm2
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   297
                in transitive th1 (Drule.arg_cong_rule tm1 (monomial_mul tm2 (Thm.dest_arg tm3) tm4))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   298
                end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   299
             else reflexive tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   300
         end)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   301
        handle CTERM _ =>
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   302
          (let val vr = powvar r
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   303
               val  ord = vorder vl vr
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   304
          in if ord = 0 then powvar_mul_conv tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   305
              else if ord > 0 then inst_thm [(ca,l),(cb,r)] pthm_09
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   306
              else reflexive tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   307
          end)) end))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   308
  in fn tm => let val (l,r) = dest_mul tm in monomial_deone(monomial_mul tm l r)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   309
             end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   310
  end;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   311
(* Multiplication by monomial of a polynomial.                               *)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   312
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   313
 val polynomial_monomial_mul_conv =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   314
  let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   315
   fun pmm_conv tm =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   316
    let val (l,r) = dest_mul tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   317
    in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   318
    ((let val (y,z) = dest_add r
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   319
          val th1 = inst_thm [(cx,l),(cy,y),(cz,z)] pthm_37
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   320
          val (tm1,tm2) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   321
          val (tm3,tm4) = Thm.dest_comb tm1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   322
          val th2 = combination (Drule.arg_cong_rule tm3 (monomial_mul_conv tm4)) (pmm_conv tm2)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   323
      in transitive th1 th2
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   324
      end)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   325
     handle CTERM _ => monomial_mul_conv tm)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   326
   end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   327
 in pmm_conv
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   328
 end;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   329
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   330
(* Addition of two monomials identical except for constant multiples.        *)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   331
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   332
fun monomial_add_conv tm =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   333
 let val (l,r) = dest_add tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   334
 in if is_semiring_constant l andalso is_semiring_constant r
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   335
    then semiring_add_conv tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   336
    else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   337
     let val th1 =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   338
           if is_mul l andalso is_semiring_constant(Thm.dest_arg1 l)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   339
           then if is_mul r andalso is_semiring_constant(Thm.dest_arg1 r) then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   340
                    inst_thm [(ca,Thm.dest_arg1 l),(cm,Thm.dest_arg r), (cb,Thm.dest_arg1 r)] pthm_02
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   341
                else inst_thm [(ca,Thm.dest_arg1 l),(cm,r)] pthm_03
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   342
           else if is_mul r andalso is_semiring_constant(Thm.dest_arg1 r)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   343
           then inst_thm [(cm,l),(ca,Thm.dest_arg1 r)] pthm_04
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   344
           else inst_thm [(cm,r)] pthm_05
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   345
         val (tm1,tm2) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   346
         val (tm3,tm4) = Thm.dest_comb tm1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   347
         val th2 = Drule.arg_cong_rule tm3 (semiring_add_conv tm4)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   348
         val th3 = transitive th1 (Drule.fun_cong_rule th2 tm2)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   349
         val tm5 = concl th3
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   350
      in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   351
      if (Thm.dest_arg1 tm5) aconvc zero_tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   352
      then transitive th3 (inst_thm [(ca,Thm.dest_arg tm5)] pthm_11)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   353
      else monomial_deone th3
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   354
     end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   355
 end;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   356
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   357
(* Ordering on monomials.                                                    *)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   358
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   359
fun striplist dest =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   360
 let fun strip x acc =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   361
   ((let val (l,r) = dest x in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   362
        strip l (strip r acc) end)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   363
    handle CTERM _ => x::acc)    (* FIXME !? *)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   364
 in fn x => strip x []
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   365
 end;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   366
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   367
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   368
fun powervars tm =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   369
 let val ptms = striplist dest_mul tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   370
 in if is_semiring_constant (hd ptms) then tl ptms else ptms
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   371
 end;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   372
val num_0 = 0;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   373
val num_1 = 1;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   374
fun dest_varpow tm =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   375
 ((let val (x,n) = dest_pow tm in (x,dest_numeral n) end)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   376
   handle CTERM _ =>
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   377
   (tm,(if is_semiring_constant tm then num_0 else num_1)));
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   378
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   379
val morder =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   380
 let fun lexorder l1 l2 =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   381
  case (l1,l2) of
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   382
    ([],[]) => 0
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   383
  | (vps,[]) => ~1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   384
  | ([],vps) => 1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   385
  | (((x1,n1)::vs1),((x2,n2)::vs2)) =>
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   386
     if variable_order x1 x2 then 1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   387
     else if variable_order x2 x1 then ~1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   388
     else if n1 < n2 then ~1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   389
     else if n2 < n1 then 1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   390
     else lexorder vs1 vs2
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   391
 in fn tm1 => fn tm2 =>
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   392
  let val vdegs1 = map dest_varpow (powervars tm1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   393
      val vdegs2 = map dest_varpow (powervars tm2)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   394
      val deg1 = fold_rev ((curry (op +)) o snd) vdegs1 num_0
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   395
      val deg2 = fold_rev ((curry (op +)) o snd) vdegs2 num_0
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   396
  in if deg1 < deg2 then ~1 else if deg1 > deg2 then 1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   397
                            else lexorder vdegs1 vdegs2
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   398
  end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   399
 end;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   400
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   401
(* Addition of two polynomials.                                              *)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   402
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   403
val polynomial_add_conv =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   404
 let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   405
 fun dezero_rule th =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   406
  let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   407
   val tm = concl th
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   408
  in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   409
   if not(is_add tm) then th else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   410
   let val (lopr,r) = Thm.dest_comb tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   411
       val l = Thm.dest_arg lopr
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   412
   in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   413
    if l aconvc zero_tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   414
    then transitive th (inst_thm [(ca,r)] pthm_07)   else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   415
        if r aconvc zero_tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   416
        then transitive th (inst_thm [(ca,l)] pthm_08)  else th
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   417
   end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   418
  end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   419
 fun padd tm =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   420
  let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   421
   val (l,r) = dest_add tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   422
  in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   423
   if l aconvc zero_tm then inst_thm [(ca,r)] pthm_07
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   424
   else if r aconvc zero_tm then inst_thm [(ca,l)] pthm_08
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   425
   else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   426
    if is_add l
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   427
    then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   428
     let val (a,b) = dest_add l
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   429
     in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   430
     if is_add r then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   431
      let val (c,d) = dest_add r
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   432
          val ord = morder a c
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   433
      in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   434
       if ord = 0 then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   435
        let val th1 = inst_thm [(ca,a),(cb,b),(cc,c),(cd,d)] pthm_23
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   436
            val (tm1,tm2) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   437
            val (tm3,tm4) = Thm.dest_comb tm1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   438
            val th2 = Drule.arg_cong_rule tm3 (monomial_add_conv tm4)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   439
        in dezero_rule (transitive th1 (combination th2 (padd tm2)))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   440
        end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   441
       else (* ord <> 0*)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   442
        let val th1 =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   443
                if ord > 0 then inst_thm [(ca,a),(cb,b),(cc,r)] pthm_24
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   444
                else inst_thm [(ca,l),(cc,c),(cd,d)] pthm_25
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   445
            val (tm1,tm2) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   446
        in dezero_rule (transitive th1 (Drule.arg_cong_rule tm1 (padd tm2)))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   447
        end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   448
      end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   449
     else (* not (is_add r)*)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   450
      let val ord = morder a r
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   451
      in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   452
       if ord = 0 then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   453
        let val th1 = inst_thm [(ca,a),(cb,b),(cc,r)] pthm_26
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   454
            val (tm1,tm2) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   455
            val (tm3,tm4) = Thm.dest_comb tm1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   456
            val th2 = Drule.fun_cong_rule (Drule.arg_cong_rule tm3 (monomial_add_conv tm4)) tm2
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   457
        in dezero_rule (transitive th1 th2)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   458
        end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   459
       else (* ord <> 0*)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   460
        if ord > 0 then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   461
          let val th1 = inst_thm [(ca,a),(cb,b),(cc,r)] pthm_24
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   462
              val (tm1,tm2) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   463
          in dezero_rule (transitive th1 (Drule.arg_cong_rule tm1 (padd tm2)))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   464
          end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   465
        else dezero_rule (inst_thm [(ca,l),(cc,r)] pthm_27)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   466
      end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   467
    end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   468
   else (* not (is_add l)*)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   469
    if is_add r then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   470
      let val (c,d) = dest_add r
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   471
          val  ord = morder l c
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   472
      in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   473
       if ord = 0 then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   474
         let val th1 = inst_thm [(ca,l),(cc,c),(cd,d)] pthm_28
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   475
             val (tm1,tm2) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   476
             val (tm3,tm4) = Thm.dest_comb tm1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   477
             val th2 = Drule.fun_cong_rule (Drule.arg_cong_rule tm3 (monomial_add_conv tm4)) tm2
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   478
         in dezero_rule (transitive th1 th2)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   479
         end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   480
       else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   481
        if ord > 0 then reflexive tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   482
        else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   483
         let val th1 = inst_thm [(ca,l),(cc,c),(cd,d)] pthm_25
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   484
             val (tm1,tm2) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   485
         in dezero_rule (transitive th1 (Drule.arg_cong_rule tm1 (padd tm2)))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   486
         end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   487
      end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   488
    else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   489
     let val ord = morder l r
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   490
     in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   491
      if ord = 0 then monomial_add_conv tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   492
      else if ord > 0 then dezero_rule(reflexive tm)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   493
      else dezero_rule (inst_thm [(ca,l),(cc,r)] pthm_27)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   494
     end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   495
  end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   496
 in padd
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   497
 end;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   498
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   499
(* Multiplication of two polynomials.                                        *)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   500
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   501
val polynomial_mul_conv =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   502
 let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   503
  fun pmul tm =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   504
   let val (l,r) = dest_mul tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   505
   in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   506
    if not(is_add l) then polynomial_monomial_mul_conv tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   507
    else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   508
     if not(is_add r) then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   509
      let val th1 = inst_thm [(ca,l),(cb,r)] pthm_09
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   510
      in transitive th1 (polynomial_monomial_mul_conv(concl th1))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   511
      end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   512
     else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   513
       let val (a,b) = dest_add l
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   514
           val th1 = inst_thm [(ca,a),(cb,b),(cc,r)] pthm_10
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   515
           val (tm1,tm2) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   516
           val (tm3,tm4) = Thm.dest_comb tm1
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   517
           val th2 = Drule.arg_cong_rule tm3 (polynomial_monomial_mul_conv tm4)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   518
           val th3 = transitive th1 (combination th2 (pmul tm2))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   519
       in transitive th3 (polynomial_add_conv (concl th3))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   520
       end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   521
   end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   522
 in fn tm =>
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   523
   let val (l,r) = dest_mul tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   524
   in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   525
    if l aconvc zero_tm then inst_thm [(ca,r)] pthm_11
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   526
    else if r aconvc zero_tm then inst_thm [(ca,l)] pthm_12
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   527
    else if l aconvc one_tm then inst_thm [(ca,r)] pthm_13
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   528
    else if r aconvc one_tm then inst_thm [(ca,l)] pthm_14
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   529
    else pmul tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   530
   end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   531
 end;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   532
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   533
(* Power of polynomial (optimized for the monomial and trivial cases).       *)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   534
23580
998a6fda9bb6 moved mk_cnumeral/mk_cnumber to Tools/numeral.ML;
wenzelm
parents: 23559
diff changeset
   535
fun num_conv n =
998a6fda9bb6 moved mk_cnumeral/mk_cnumber to Tools/numeral.ML;
wenzelm
parents: 23559
diff changeset
   536
  nat_add_conv (Thm.capply @{cterm Suc} (Numeral.mk_cnumber @{ctyp nat} (dest_numeral n - 1)))
998a6fda9bb6 moved mk_cnumeral/mk_cnumber to Tools/numeral.ML;
wenzelm
parents: 23559
diff changeset
   537
  |> Thm.symmetric;
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   538
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   539
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   540
val polynomial_pow_conv =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   541
 let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   542
  fun ppow tm =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   543
    let val (l,n) = dest_pow tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   544
    in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   545
     if n aconvc zeron_tm then inst_thm [(cx,l)] pthm_35
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   546
     else if n aconvc onen_tm then inst_thm [(cx,l)] pthm_36
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   547
     else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   548
         let val th1 = num_conv n
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   549
             val th2 = inst_thm [(cx,l),(cq,Thm.dest_arg (concl th1))] pthm_38
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   550
             val (tm1,tm2) = Thm.dest_comb(concl th2)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   551
             val th3 = transitive th2 (Drule.arg_cong_rule tm1 (ppow tm2))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   552
             val th4 = transitive (Drule.arg_cong_rule (Thm.dest_fun tm) th1) th3
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   553
         in transitive th4 (polynomial_mul_conv (concl th4))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   554
         end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   555
    end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   556
 in fn tm =>
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   557
       if is_add(Thm.dest_arg1 tm) then ppow tm else monomial_pow_conv tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   558
 end;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   559
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   560
(* Negation.                                                                 *)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   561
23580
998a6fda9bb6 moved mk_cnumeral/mk_cnumber to Tools/numeral.ML;
wenzelm
parents: 23559
diff changeset
   562
fun polynomial_neg_conv tm =
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   563
   let val (l,r) = Thm.dest_comb tm in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   564
        if not (l aconvc neg_tm) then raise CTERM ("polynomial_neg_conv",[tm]) else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   565
        let val th1 = inst_thm [(cx',r)] neg_mul
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   566
            val th2 = transitive th1 (arg1_conv semiring_mul_conv (concl th1))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   567
        in transitive th2 (polynomial_monomial_mul_conv (concl th2))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   568
        end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   569
   end;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   570
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   571
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   572
(* Subtraction.                                                              *)
23580
998a6fda9bb6 moved mk_cnumeral/mk_cnumber to Tools/numeral.ML;
wenzelm
parents: 23559
diff changeset
   573
fun polynomial_sub_conv tm =
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   574
  let val (l,r) = dest_sub tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   575
      val th1 = inst_thm [(cx',l),(cy',r)] sub_add
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   576
      val (tm1,tm2) = Thm.dest_comb(concl th1)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   577
      val th2 = Drule.arg_cong_rule tm1 (polynomial_neg_conv tm2)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   578
  in transitive th1 (transitive th2 (polynomial_add_conv (concl th2)))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   579
  end;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   580
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   581
(* Conversion from HOL term.                                                 *)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   582
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   583
fun polynomial_conv tm =
23407
0e4452fcbeb8 normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents: 23330
diff changeset
   584
 if is_semiring_constant tm then semiring_add_conv tm
0e4452fcbeb8 normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents: 23330
diff changeset
   585
 else if not(is_comb tm) then reflexive tm
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   586
 else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   587
  let val (lopr,r) = Thm.dest_comb tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   588
  in if lopr aconvc neg_tm then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   589
       let val th1 = Drule.arg_cong_rule lopr (polynomial_conv r)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   590
       in transitive th1 (polynomial_neg_conv (concl th1))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   591
       end
30866
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   592
     else if lopr aconvc inverse_tm then
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   593
       let val th1 = Drule.arg_cong_rule lopr (polynomial_conv r)
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   594
       in transitive th1 (semiring_mul_conv (concl th1))
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   595
       end
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   596
     else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   597
       if not(is_comb lopr) then reflexive tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   598
       else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   599
         let val (opr,l) = Thm.dest_comb lopr
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   600
         in if opr aconvc pow_tm andalso is_numeral r
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   601
            then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   602
              let val th1 = Drule.fun_cong_rule (Drule.arg_cong_rule opr (polynomial_conv l)) r
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   603
              in transitive th1 (polynomial_pow_conv (concl th1))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   604
              end
30866
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   605
         else if opr aconvc divide_tm 
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   606
            then
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   607
              let val th1 = combination (Drule.arg_cong_rule opr (polynomial_conv l)) 
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   608
                                        (polynomial_conv r)
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   609
                  val th2 = (rewr_conv divide_inverse then_conv polynomial_mul_conv) 
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   610
                              (Thm.rhs_of th1)
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   611
              in transitive th1 th2
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   612
              end
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   613
            else
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   614
              if opr aconvc add_tm orelse opr aconvc mul_tm orelse opr aconvc sub_tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   615
              then
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   616
               let val th1 = combination (Drule.arg_cong_rule opr (polynomial_conv l)) (polynomial_conv r)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   617
                   val f = if opr aconvc add_tm then polynomial_add_conv
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   618
                      else if opr aconvc mul_tm then polynomial_mul_conv
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   619
                      else polynomial_sub_conv
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   620
               in transitive th1 (f (concl th1))
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   621
               end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   622
              else reflexive tm
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   623
         end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   624
  end;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   625
 in
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   626
   {main = polynomial_conv,
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   627
    add = polynomial_add_conv,
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   628
    mul = polynomial_mul_conv,
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   629
    pow = polynomial_pow_conv,
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   630
    neg = polynomial_neg_conv,
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   631
    sub = polynomial_sub_conv}
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   632
 end
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   633
end;
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   634
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   635
val nat_arith = @{thms "nat_arith"};
25481
aa16cd919dcc dropped legacy ml bindings
haftmann
parents: 25253
diff changeset
   636
val nat_exp_ss = HOL_basic_ss addsimps (@{thms nat_number} @ nat_arith @ @{thms arith_simps} @ @{thms rel_simps})
23880
64b9806e160b dropped Nat.ML legacy bindings
haftmann
parents: 23580
diff changeset
   637
                              addsimps [Let_def, if_False, if_True, @{thm add_0}, @{thm add_Suc}];
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   638
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents: 27222
diff changeset
   639
fun simple_cterm_ord t u = TermOrd.term_ord (term_of t, term_of u) = LESS;
27222
b08abdb8f499 Export a wrapper for all semiring_normalizers
chaieb
parents: 25481
diff changeset
   640
30866
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   641
fun semiring_normalizers_ord_wrapper ctxt ({vars, semiring, ring, field, idom, ideal}, 
23407
0e4452fcbeb8 normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents: 23330
diff changeset
   642
                                     {conv, dest_const, mk_const, is_const}) ord =
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   643
  let
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   644
    val pow_conv =
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   645
      arg_conv (Simplifier.rewrite nat_exp_ss)
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   646
      then_conv Simplifier.rewrite
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   647
        (HOL_basic_ss addsimps [nth (snd semiring) 31, nth (snd semiring) 34])
23330
01c09922ce59 Conversion for computation on constants now depends on the context
chaieb
parents: 23259
diff changeset
   648
      then_conv conv ctxt
01c09922ce59 Conversion for computation on constants now depends on the context
chaieb
parents: 23259
diff changeset
   649
    val dat = (is_const, conv ctxt, conv ctxt, pow_conv)
30866
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   650
  in semiring_normalizers_conv vars semiring ring field dat ord end;
27222
b08abdb8f499 Export a wrapper for all semiring_normalizers
chaieb
parents: 25481
diff changeset
   651
30866
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   652
fun semiring_normalize_ord_wrapper ctxt ({vars, semiring, ring, field, idom, ideal}, {conv, dest_const, mk_const, is_const}) ord =
dd5117e2d73e now deals with devision in fields
chaieb
parents: 29269
diff changeset
   653
 #main (semiring_normalizers_ord_wrapper ctxt ({vars = vars, semiring = semiring, ring = ring, field = field, idom = idom, ideal = ideal},{conv = conv, dest_const = dest_const, mk_const = mk_const, is_const = is_const}) ord);
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   654
23407
0e4452fcbeb8 normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents: 23330
diff changeset
   655
fun semiring_normalize_wrapper ctxt data = 
0e4452fcbeb8 normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents: 23330
diff changeset
   656
  semiring_normalize_ord_wrapper ctxt data simple_cterm_ord;
0e4452fcbeb8 normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents: 23330
diff changeset
   657
0e4452fcbeb8 normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents: 23330
diff changeset
   658
fun semiring_normalize_ord_conv ctxt ord tm =
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   659
  (case NormalizerData.match ctxt tm of
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   660
    NONE => reflexive tm
23407
0e4452fcbeb8 normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents: 23330
diff changeset
   661
  | SOME res => semiring_normalize_ord_wrapper ctxt res ord tm);
0e4452fcbeb8 normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents: 23330
diff changeset
   662
 
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   663
23407
0e4452fcbeb8 normalizer conversions depend on the proof context; added functions for conversion and wrapper that sill depend on the variable ordering (_ord)
chaieb
parents: 23330
diff changeset
   664
fun semiring_normalize_conv ctxt = semiring_normalize_ord_conv ctxt simple_cterm_ord;
23252
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   665
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   666
fun semiring_normalize_tac ctxt = SUBGOAL (fn (goal, i) =>
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   667
  rtac (semiring_normalize_conv ctxt
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   668
    (cterm_of (ProofContext.theory_of ctxt) (fst (Logic.dest_equals goal)))) i);
67268bb40b21 Semiring normalization and Groebner Bases.
wenzelm
parents:
diff changeset
   669
end;