src/HOL/Algebra/ringsimp.ML
author bauerg
Thu, 28 Apr 2005 17:08:08 +0200
changeset 15871 e524119dbf19
parent 15570 8d8c70b41bab
child 16486 1a12cdb6ee6b
permissions -rw-r--r--
*** empty log message ***
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 =
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents: 13864
diff changeset
    59
  find_index_eq a ["CRing.ring.zero", "CRing.ring.add", "CRing.a_inv",
14963
d584e32f7d46 removal of magmas and semigroups
paulson
parents: 14399
diff changeset
    60
  "CRing.minus", "Group.monoid.one", "Group.monoid.mult"];
13854
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
14399
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    67
    fun ring_filter t = (case HOLogic.dest_Trueprop t of
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    68
        Const ("CRing.ring_axioms", _) $ Free (s, _) => [s]
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    69
      | _ => [])
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    70
      handle TERM _ => [];
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    71
    fun comm_filter t = (case HOLogic.dest_Trueprop t of
14963
d584e32f7d46 removal of magmas and semigroups
paulson
parents: 14399
diff changeset
    72
        Const ("Group.comm_monoid_axioms", _) $ Free (s, _) => [s]
13864
f44f121dd275 Bugs fixed and operators finprod and finsum.
ballarin
parents: 13854
diff changeset
    73
      | _ => [])
13854
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    74
      handle TERM _ => [];
14399
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    75
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    76
    val prems = ProofContext.prems_of ctxt;
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
    77
    val rings = List.concat (map (ring_filter o #prop o rep_thm) prems);
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
    78
    val comms = List.concat (map (comm_filter o #prop o rep_thm) prems);
14399
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    79
    val non_comm_rings = rings \\ comms;
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    80
    val comm_rings = rings inter_string comms;
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    81
    val _ = tracing
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    82
      ("Non-commutative rings in proof context: " ^ commas non_comm_rings ^
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    83
       "\nCommutative rings in proof context: " ^ commas comm_rings);
13854
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    84
    val simps =
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
    85
      List.concat (map (fn s => ProofContext.get_thms ctxt (s ^ ".ring_simprules", NONE))
14399
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    86
        non_comm_rings) @
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
    87
      List.concat (map (fn s => ProofContext.get_thms ctxt (s ^ ".cring_simprules", NONE))
14399
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    88
        comm_rings);
13854
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    89
  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
    90
  end;
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    91
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    92
(*
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    93
val ring_ss = HOL_basic_ss settermless termless_ring addsimps
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    94
  [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
    95
   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
    96
   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
    97
*)
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    98
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    99
end;