src/HOL/Algebra/ringsimp.ML
author wenzelm
Tue, 11 Jul 2006 12:17:08 +0200
changeset 20083 717b1eb434f1
parent 19931 fb32b43e7f80
child 20129 95e84d2c9f2c
permissions -rw-r--r--
removed obsolete mem_ix;
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
(*** Term order for commutative rings ***)
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
fun ring_ord a =
13936
d3671b878828 Greatly extended CRing. Added Module.
ballarin
parents: 13864
diff changeset
    11
  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
    12
  "CRing.minus", "Group.monoid.one", "Group.monoid.mult"];
13854
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    13
16568
e02fe7ae212b Changes due to new abel_cancel.ML
nipkow
parents: 16486
diff changeset
    14
fun termless_ring (a, b) = (Term.term_lpo ring_ord (a, b) = LESS);
13854
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
val cring_ss = HOL_ss settermless termless_ring;
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    17
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    18
fun cring_normalise ctxt = let
19931
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    19
    fun filter p t = (case HOLogic.dest_Trueprop t of
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    20
        Const (p', _) $ Free (s, _) => if p = p' then [s] else []
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    21
      | _ => [])
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    22
      handle TERM _ => [];
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    23
    fun filter21 p t = (case HOLogic.dest_Trueprop t of
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    24
        Const (p', _) $ Free (s, _) $ _ => if p = p' then [s] else []
14399
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    25
      | _ => [])
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    26
      handle TERM _ => [];
19931
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    27
    fun filter22 p t = (case HOLogic.dest_Trueprop t of
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    28
        Const (p', _) $ _ $ Free (s, _) => if p = p' then [s] else []
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    29
      | _ => [])
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    30
      handle TERM _ => [];
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    31
    fun filter31 p t = (case HOLogic.dest_Trueprop t of
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    32
        Const (p', _) $ Free (s, _) $ _ $ _ => if p = p' then [s] else []
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    33
      | _ => [])
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    34
      handle TERM _ => [];
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    35
    fun filter32 p t = (case HOLogic.dest_Trueprop t of
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    36
        Const (p', _) $ _ $ Free (s, _) $ _ => if p = p' then [s] else []
13864
f44f121dd275 Bugs fixed and operators finprod and finsum.
ballarin
parents: 13854
diff changeset
    37
      | _ => [])
13854
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    38
      handle TERM _ => [];
14399
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    39
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    40
    val prems = ProofContext.prems_of ctxt;
19931
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    41
    val non_comm_rings = List.concat (map (filter "CRing.ring" o #prop o rep_thm) prems);
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    42
    val comm_rings = List.concat (map (filter "CRing.cring" o #prop o rep_thm) prems) @
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    43
        List.concat (map (filter "CRing.domain" o #prop o rep_thm) prems) @
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    44
        List.concat (map (filter21 "Module.module" o #prop o rep_thm) prems) @
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    45
        List.concat (map (filter21 "Module.algebra" o #prop o rep_thm) prems) @
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    46
        List.concat (map (filter22 "Module.algebra" o #prop o rep_thm) prems) @
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    47
        List.concat (map (filter "UnivPoly.UP_cring" o #prop o rep_thm) prems) @
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    48
        List.concat (map (filter "UnivPoly.UP_domain" o #prop o rep_thm) prems) @
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    49
        List.concat (map (filter31 "CRing.ring_hom_cring" o #prop o rep_thm) prems) @
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    50
        List.concat (map (filter32 "CRing.ring_hom_cring" o #prop o rep_thm) prems);
14399
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    51
    val _ = tracing
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    52
      ("Non-commutative rings in proof context: " ^ commas non_comm_rings ^
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    53
       "\nCommutative rings in proof context: " ^ commas comm_rings);
13854
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    54
    val simps =
16486
1a12cdb6ee6b get_thm(s): Name;
wenzelm
parents: 15570
diff changeset
    55
      List.concat (map (fn s => ProofContext.get_thms ctxt (Name (s ^ ".ring_simprules")))
14399
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    56
        non_comm_rings) @
16486
1a12cdb6ee6b get_thm(s): Name;
wenzelm
parents: 15570
diff changeset
    57
      List.concat (map (fn s => ProofContext.get_thms ctxt (Name (s ^ ".cring_simprules")))
14399
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    58
        comm_rings);
13854
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    59
  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
    60
  end;
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
(*
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    63
val ring_ss = HOL_basic_ss settermless termless_ring addsimps
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    64
  [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
    65
   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
    66
   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
    67
*)