src/HOL/Algebra/abstract/order.ML
author skalberg
Sun, 13 Feb 2005 17:15:14 +0100
changeset 15531 08c8dad8e399
parent 13783 3294f727e20d
child 15661 9ef583b08647
permissions -rw-r--r--
Deleted Library.option type.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
     1
(*
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
     2
  Title:     Term order, needed for normal forms in rings
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
     3
  Id:        $Id$
13783
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
     4
  Author:    Clemens Ballarin
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
     5
  Copyright: TU Muenchen
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
     6
*)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
     7
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
     8
local
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
     9
13783
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    10
(*** Lexicographic path order on terms.
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    11
13783
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    12
  See Baader & Nipkow, Term rewriting, CUP 1998.
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    13
  Without variables.  Const, Var, Bound, Free and Abs are treated all as
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    14
  constants.
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    15
13783
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    16
  f_ord maps strings to integers and serves two purposes:
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    17
  - Predicate on constant symbols.  Those that are not recognised by f_ord
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    18
    must be mapped to ~1.
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    19
  - Order on the recognised symbols.  These must be mapped to distinct
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    20
    integers >= 0.
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    21
13783
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    22
***)
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    23
13783
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    24
fun dest_hd f_ord (Const (a, T)) = 
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    25
      let val ord = f_ord a in
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    26
        if ord = ~1 then ((1, ((a, 0), T)), 0) else ((0, (("", ord), T)), 0)
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    27
      end
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    28
  | dest_hd _ (Free (a, T)) = ((1, ((a, 0), T)), 0)
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    29
  | dest_hd _ (Var v) = ((1, v), 1)
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    30
  | dest_hd _ (Bound i) = ((1, (("", i), Term.dummyT)), 2)
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    31
  | dest_hd _ (Abs (_, T, _)) = ((1, (("", 0), T)), 3);
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    32
13783
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    33
fun term_lpo f_ord (s, t) =
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    34
  let val (f, ss) = strip_comb s and (g, ts) = strip_comb t in
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    35
    if forall (fn si => term_lpo f_ord (si, t) = LESS) ss
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    36
    then case hd_ord f_ord (f, g) of
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    37
	GREATER =>
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    38
	  if forall (fn ti => term_lpo f_ord (s, ti) = GREATER) ts
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    39
	  then GREATER else LESS
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    40
      | EQUAL =>
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    41
	  if forall (fn ti => term_lpo f_ord (s, ti) = GREATER) ts
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    42
	  then list_ord (term_lpo f_ord) (ss, ts)
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    43
	  else LESS
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    44
      | LESS => LESS
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    45
    else GREATER
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    46
  end
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    47
and hd_ord f_ord (f, g) = case (f, g) of
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    48
    (Abs (_, T, t), Abs (_, U, u)) =>
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    49
      (case term_lpo f_ord (t, u) of EQUAL => Term.typ_ord (T, U) | ord => ord)
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    50
  | (_, _) => prod_ord (prod_ord int_ord
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    51
                  (prod_ord Term.indexname_ord Term.typ_ord)) int_ord
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    52
                (dest_hd f_ord f, dest_hd f_ord g)
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    53
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    54
in
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    55
13783
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    56
(*** Term order for commutative rings ***)
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    57
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    58
fun ring_ord a =
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    59
  find_index_eq a ["0", "op +", "uminus", "op -", "1", "op *"];
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    60
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    61
fun termless_ring (a, b) = (term_lpo ring_ord (a, b) = LESS);
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    62
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 13783
diff changeset
    63
(* SOME code useful for debugging
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    64
13783
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    65
val intT = HOLogic.intT;
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    66
val a = Free ("a", intT);
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    67
val b = Free ("b", intT);
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    68
val c = Free ("c", intT);
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    69
val plus = Const ("op +", [intT, intT]--->intT);
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    70
val mult = Const ("op *", [intT, intT]--->intT);
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    71
val uminus = Const ("uminus", intT-->intT);
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    72
val one = Const ("1", intT);
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    73
val f = Const("f", intT-->intT);
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    74
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
    75
*)
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    76
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    77
(*** Rewrite rules ***)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    78
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    79
val a_assoc = thm "ring.a_assoc";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    80
val l_zero = thm "ring.l_zero";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    81
val l_neg = thm "ring.l_neg";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    82
val a_comm = thm "ring.a_comm";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    83
val m_assoc = thm "ring.m_assoc";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    84
val l_one = thm "ring.l_one";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    85
val l_distr = thm "ring.l_distr";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    86
val m_comm = thm "ring.m_comm";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    87
val minus_def = thm "ring.minus_def";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    88
val inverse_def = thm "ring.inverse_def";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    89
val divide_def = thm "ring.divide_def";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    90
val power_def = thm "ring.power_def";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    91
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    92
(* These are the following axioms:
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    93
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    94
  a_assoc:      "(a + b) + c = a + (b + c)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    95
  l_zero:       "0 + a = a"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    96
  l_neg:        "(-a) + a = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    97
  a_comm:       "a + b = b + a"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    98
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
    99
  m_assoc:      "(a * b) * c = a * (b * c)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   100
  l_one:        "1 * a = a"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   101
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   102
  l_distr:      "(a + b) * c = a * c + b * c"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   103
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   104
  m_comm:       "a * b = b * a"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   105
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   106
  -- {* Definition of derived operations *}
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   107
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   108
  minus_def:    "a - b = a + (-b)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   109
  inverse_def:  "inverse a = (if a dvd 1 then THE x. a*x = 1 else 0)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   110
  divide_def:   "a / b = a * inverse b"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   111
  power_def:    "a ^ n = nat_rec 1 (%u b. b * a) n"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   112
*)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   113
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   114
(* These lemmas are needed in the proofs *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   115
val trans = thm "trans";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   116
val sym = thm "sym";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   117
val subst = thm "subst";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   118
val box_equals = thm "box_equals";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   119
val arg_cong = thm "arg_cong";
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   120
(* current theory *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   121
val thy = the_context ();
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   122
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   123
(* derived rewrite rules *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   124
val a_lcomm = prove_goal thy "(a::'a::ring)+(b+c) = b+(a+c)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   125
  (fn _ => [rtac (a_comm RS trans) 1, rtac (a_assoc RS trans) 1,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   126
     rtac (a_comm RS arg_cong) 1]);
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   127
val r_zero = prove_goal thy "(a::'a::ring) + 0 = a"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   128
  (fn _ => [rtac (a_comm RS trans) 1, rtac l_zero 1]);
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   129
val r_neg = prove_goal thy "(a::'a::ring) + (-a) = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   130
  (fn _ => [rtac (a_comm RS trans) 1, rtac l_neg 1]);
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   131
val r_neg2 = prove_goal thy "(a::'a::ring) + (-a + b) = b"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   132
  (fn _ => [rtac (a_assoc RS sym RS trans) 1,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   133
     simp_tac (simpset() addsimps [r_neg, l_zero]) 1]);
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   134
val r_neg1 = prove_goal thy "-(a::'a::ring) + (a + b) = b"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   135
  (fn _ => [rtac (a_assoc RS sym RS trans) 1,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   136
     simp_tac (simpset() addsimps [l_neg, l_zero]) 1]);
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   137
(* auxiliary *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   138
val a_lcancel = prove_goal thy "!! a::'a::ring. a + b = a + c ==> b = c"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   139
  (fn _ => [rtac box_equals 1, rtac l_zero 2, rtac l_zero 2,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   140
     res_inst_tac [("a1", "a")] (l_neg RS subst) 1,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   141
     asm_simp_tac (simpset() addsimps [a_assoc]) 1]);
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   142
val minus_add = prove_goal thy "-((a::'a::ring) + b) = (-a) + (-b)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   143
  (fn _ => [res_inst_tac [("a", "a+b")] a_lcancel 1,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   144
     simp_tac (simpset() addsimps [r_neg, l_neg, l_zero, 
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   145
                                   a_assoc, a_comm, a_lcomm]) 1]);
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   146
val minus_minus = prove_goal thy "-(-(a::'a::ring)) = a"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   147
  (fn _ => [rtac a_lcancel 1, rtac (r_neg RS trans) 1, rtac (l_neg RS sym) 1]);
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   148
val minus0 = prove_goal thy "- 0 = (0::'a::ring)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   149
  (fn _ => [rtac a_lcancel 1, rtac (r_neg RS trans) 1,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   150
     rtac (l_zero RS sym) 1]);
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   151
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   152
(* derived rules for multiplication *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   153
val m_lcomm = prove_goal thy "(a::'a::ring)*(b*c) = b*(a*c)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   154
  (fn _ => [rtac (m_comm RS trans) 1, rtac (m_assoc RS trans) 1,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   155
     rtac (m_comm RS arg_cong) 1]);
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   156
val r_one = prove_goal thy "(a::'a::ring) * 1 = a"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   157
  (fn _ => [rtac (m_comm RS trans) 1, rtac l_one 1]);
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   158
val r_distr = prove_goal thy "(a::'a::ring) * (b + c) = a * b + a * c"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   159
  (fn _ => [rtac (m_comm RS trans) 1, rtac (l_distr RS trans) 1,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   160
     simp_tac (simpset() addsimps [m_comm]) 1]);
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   161
(* the following proof is from Jacobson, Basic Algebra I, pp. 88-89 *)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   162
val l_null = prove_goal thy "0 * (a::'a::ring) = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   163
  (fn _ => [rtac a_lcancel 1, rtac (l_distr RS sym RS trans) 1,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   164
     simp_tac (simpset() addsimps [r_zero]) 1]);
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   165
val r_null = prove_goal thy "(a::'a::ring) * 0 = 0"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   166
  (fn _ => [rtac (m_comm RS trans) 1, rtac l_null 1]);
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   167
val l_minus = prove_goal thy "(-(a::'a::ring)) * b = - (a * b)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   168
  (fn _ => [rtac a_lcancel 1, rtac (r_neg RS sym RSN (2, trans)) 1,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   169
     rtac (l_distr RS sym RS trans) 1,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   170
     simp_tac (simpset() addsimps [l_null, r_neg]) 1]);
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   171
val r_minus = prove_goal thy "(a::'a::ring) * (-b) = - (a * b)"
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   172
  (fn _ => [rtac a_lcancel 1, rtac (r_neg RS sym RSN (2, trans)) 1,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   173
     rtac (r_distr RS sym RS trans) 1,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   174
     simp_tac (simpset() addsimps [r_null, r_neg]) 1]);
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   175
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   176
val ring_ss = HOL_basic_ss settermless termless_ring addsimps
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   177
  [a_assoc, l_zero, l_neg, a_comm, m_assoc, l_one, l_distr, m_comm, minus_def,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   178
   r_zero, r_neg, r_neg2, r_neg1, minus_add, minus_minus, minus0,
13783
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
   179
   a_lcomm, m_lcomm, (*r_one,*) r_distr, l_null, r_null, l_minus, r_minus];
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
   180
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
   181
(* Note: r_one is not necessary in ring_ss *)
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   182
13783
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
   183
val x = bind_thms ("ring_simps", 
3294f727e20d Fixed term order for normal form in rings.
ballarin
parents: 13738
diff changeset
   184
  [l_zero, r_zero, l_neg, r_neg, minus_minus, minus0, 
13735
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   185
  l_one, r_one, l_null, r_null, l_minus, r_minus]);
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   186
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   187
(* note: not added (and not proved):
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   188
  a_lcancel_eq, a_rcancel_eq, power_one, power_Suc, power_zero, power_one,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   189
  m_lcancel_eq, m_rcancel_eq,
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   190
  thms involving dvd, integral domains, fields
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   191
*)
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   192
7de9342aca7a HOL-Algebra partially ported to Isar.
ballarin
parents:
diff changeset
   193
end;