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