src/HOL/Algebra/ringsimp.ML
author ballarin
Fri, 14 Jul 2006 14:37:15 +0200
changeset 20129 95e84d2c9f2c
parent 19931 fb32b43e7f80
child 20168 ed7bced29e1b
permissions -rw-r--r--
Term.term_lpo takes order on terms rather than strings as argument.
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
20129
95e84d2c9f2c Term.term_lpo takes order on terms rather than strings as argument.
ballarin
parents: 19931
diff changeset
    10
fun ring_ord (Const (a, _)) =
95e84d2c9f2c Term.term_lpo takes order on terms rather than strings as argument.
ballarin
parents: 19931
diff changeset
    11
    find_index_eq a ["CRing.ring.zero", "CRing.ring.add", "CRing.a_inv",
95e84d2c9f2c Term.term_lpo takes order on terms rather than strings as argument.
ballarin
parents: 19931
diff changeset
    12
      "CRing.minus", "Group.monoid.one", "Group.monoid.mult"]
95e84d2c9f2c Term.term_lpo takes order on terms rather than strings as argument.
ballarin
parents: 19931
diff changeset
    13
  | ring_ord _ = ~1;
13854
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    14
16568
e02fe7ae212b Changes due to new abel_cancel.ML
nipkow
parents: 16486
diff changeset
    15
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
    16
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    17
val cring_ss = HOL_ss settermless termless_ring;
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    18
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    19
fun cring_normalise ctxt = let
19931
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    20
    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
    21
        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
    22
      | _ => [])
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    23
      handle TERM _ => [];
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    24
    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
    25
        Const (p', _) $ Free (s, _) $ _ => if p = p' then [s] else []
14399
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    26
      | _ => [])
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    27
      handle TERM _ => [];
19931
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    28
    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
    29
        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
    30
      | _ => [])
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    31
      handle TERM _ => [];
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    32
    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
    33
        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
    34
      | _ => [])
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    35
      handle TERM _ => [];
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    36
    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
    37
        Const (p', _) $ _ $ Free (s, _) $ _ => if p = p' then [s] else []
13864
f44f121dd275 Bugs fixed and operators finprod and finsum.
ballarin
parents: 13854
diff changeset
    38
      | _ => [])
13854
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    39
      handle TERM _ => [];
14399
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    40
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    41
    val prems = ProofContext.prems_of ctxt;
19931
fb32b43e7f80 Restructured locales with predicates: import is now an interpretation.
ballarin
parents: 16568
diff changeset
    42
    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
    43
    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
    44
        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
    45
        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
    46
        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
    47
        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
    48
        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
    49
        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
    50
        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
    51
        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
    52
    val _ = tracing
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    53
      ("Non-commutative rings in proof context: " ^ commas non_comm_rings ^
dc677b35e54f New lemmas about inversion of restricted functions.
ballarin
parents: 13936
diff changeset
    54
       "\nCommutative rings in proof context: " ^ commas comm_rings);
13854
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    55
    val simps =
16486
1a12cdb6ee6b get_thm(s): Name;
wenzelm
parents: 15570
diff changeset
    56
      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
    57
        non_comm_rings) @
16486
1a12cdb6ee6b get_thm(s): Name;
wenzelm
parents: 15570
diff changeset
    58
      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
    59
        comm_rings);
13854
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    60
  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
    61
  end;
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
(*
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    64
val ring_ss = HOL_basic_ss settermless termless_ring addsimps
91c9ab25fece First distributed version of Group and Ring theory.
ballarin
parents:
diff changeset
    65
  [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
    66
   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
    67
   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
    68
*)