src/HOL/Algebra/ringsimp.ML
author ballarin
Fri, 14 Mar 2003 18:00:16 +0100
changeset 13864 f44f121dd275
parent 13854 91c9ab25fece
child 13936 d3671b878828
permissions -rw-r--r--
Bugs fixed and operators finprod and finsum.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13854
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
     1
(*
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
     2
  Title:     Normalisation method for locale cring
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
     3
  Id:        $Id$
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
     4
  Author:    Clemens Ballarin
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
     5
  Copyright: TU Muenchen
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
     6
*)
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
     7
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
     8
local
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
     9
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    10
(*** Lexicographic path order on terms.
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    11
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    12
  See Baader & Nipkow, Term rewriting, CUP 1998.
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    13
  Without variables.  Const, Var, Bound, Free and Abs are treated all as
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    14
  constants.
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    15
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    16
  f_ord maps strings to integers and serves two purposes:
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    17
  - Predicate on constant symbols.  Those that are not recognised by f_ord
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    18
    must be mapped to ~1.
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    19
  - Order on the recognised symbols.  These must be mapped to distinct
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    20
    integers >= 0.
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    21
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    22
***)
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    23
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    24
fun dest_hd f_ord (Const (a, T)) = 
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    25
      let val ord = f_ord a in
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    26
        if ord = ~1 then ((1, ((a, 0), T)), 0) else ((0, (("", ord), T)), 0)
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    27
      end
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    28
  | dest_hd _ (Free (a, T)) = ((1, ((a, 0), T)), 0)
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    29
  | dest_hd _ (Var v) = ((1, v), 1)
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    30
  | dest_hd _ (Bound i) = ((1, (("", i), Term.dummyT)), 2)
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    31
  | dest_hd _ (Abs (_, T, _)) = ((1, (("", 0), T)), 3);
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    32
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    33
fun term_lpo f_ord (s, t) =
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    34
  let val (f, ss) = strip_comb s and (g, ts) = strip_comb t in
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    35
    if forall (fn si => term_lpo f_ord (si, t) = LESS) ss
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    36
    then case hd_ord f_ord (f, g) of
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    37
	GREATER =>
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    38
	  if forall (fn ti => term_lpo f_ord (s, ti) = GREATER) ts
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    39
	  then GREATER else LESS
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    40
      | EQUAL =>
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    41
	  if forall (fn ti => term_lpo f_ord (s, ti) = GREATER) ts
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    42
	  then list_ord (term_lpo f_ord) (ss, ts)
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    43
	  else LESS
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    44
      | LESS => LESS
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    45
    else GREATER
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    46
  end
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    47
and hd_ord f_ord (f, g) = case (f, g) of
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    48
    (Abs (_, T, t), Abs (_, U, u)) =>
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    49
      (case term_lpo f_ord (t, u) of EQUAL => Term.typ_ord (T, U) | ord => ord)
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    50
  | (_, _) => prod_ord (prod_ord int_ord
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    51
                  (prod_ord Term.indexname_ord Term.typ_ord)) int_ord
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    52
                (dest_hd f_ord f, dest_hd f_ord g)
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    53
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    54
in
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    55
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    56
(*** Term order for commutative rings ***)
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    57
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    58
fun ring_ord a =
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    59
  find_index_eq a ["CRing.ring.zero", "CRing.ring.add", "Cring.ring.a_inv",
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    60
  "CRing.ring.minus", "Group.monoid.one", "Group.semigroup.mult"];
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    61
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    62
fun termless_ring (a, b) = (term_lpo ring_ord (a, b) = LESS);
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    63
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    64
val cring_ss = HOL_ss settermless termless_ring;
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    65
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    66
fun cring_normalise ctxt = let
13864
f44f121dd275 Bugs fixed and operators finprod and finsum.
ballarin
parents: 13854
diff changeset
    67
    fun filter t = (case HOLogic.dest_Trueprop t of
13854
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    68
        Const ("CRing.cring_axioms", _) $ Free (s, _) => [s]
13864
f44f121dd275 Bugs fixed and operators finprod and finsum.
ballarin
parents: 13854
diff changeset
    69
      | _ => [])
13854
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    70
      handle TERM _ => [];
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    71
    val insts = flat (map (filter o #prop o rep_thm)
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    72
      (ProofContext.prems_of ctxt));
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    73
val _ = warning ("Rings in proof context: " ^ implode insts);
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    74
    val simps =
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    75
      flat (map (fn s => ProofContext.get_thms ctxt (s ^ ".cring_simprules"))
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    76
        insts);
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    77
  in Method.SIMPLE_METHOD' HEADGOAL (asm_full_simp_tac (cring_ss addsimps simps))
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    78
  end;
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    79
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    80
(*
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    81
val ring_ss = HOL_basic_ss settermless termless_ring addsimps
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    82
  [a_assoc, l_zero, l_neg, a_comm, m_assoc, l_one, l_distr, m_comm, minus_def,
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    83
   r_zero, r_neg, r_neg2, r_neg1, minus_add, minus_minus, minus0,
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    84
   a_lcomm, m_lcomm, (*r_one,*) r_distr, l_null, r_null, l_minus, r_minus];
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    85
*)
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    86
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    87
end;