simpdata.ML
author wenzelm
Wed, 21 Sep 1994 15:40:41 +0200
changeset 145 a9f7ff3a464c
parent 129 0bba840aa07c
child 198 663cead79989
permissions -rw-r--r--
minor cleanup, added 'axclass', 'instance', 'syntax', 'defs' sections;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
142f1eb707b4 defined addcongs locally in simpdata.ML
nipkow
parents: 0
diff changeset
     1
(*  Title: 	HOL/simpdata.ML
142f1eb707b4 defined addcongs locally in simpdata.ML
nipkow
parents: 0
diff changeset
     2
    ID:         $Id$
142f1eb707b4 defined addcongs locally in simpdata.ML
nipkow
parents: 0
diff changeset
     3
    Author: 	Tobias Nipkow
142f1eb707b4 defined addcongs locally in simpdata.ML
nipkow
parents: 0
diff changeset
     4
    Copyright   1991  University of Cambridge
142f1eb707b4 defined addcongs locally in simpdata.ML
nipkow
parents: 0
diff changeset
     5
142f1eb707b4 defined addcongs locally in simpdata.ML
nipkow
parents: 0
diff changeset
     6
Instantiation of the generic simplifier
142f1eb707b4 defined addcongs locally in simpdata.ML
nipkow
parents: 0
diff changeset
     7
*)
142f1eb707b4 defined addcongs locally in simpdata.ML
nipkow
parents: 0
diff changeset
     8
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
     9
open Simplifier;
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    10
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    11
local
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    12
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    13
fun prover s = prove_goal HOL.thy s (fn _ => [fast_tac HOL_cs 1]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    14
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    15
val P_imp_P_iff_True = prover "P --> (P = True)" RS mp;
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    16
val P_imp_P_eq_True = P_imp_P_iff_True RS eq_reflection;
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    17
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    18
val not_P_imp_P_iff_F = prover "~P --> (P = False)" RS mp;
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    19
val not_P_imp_P_eq_False = not_P_imp_P_iff_F RS eq_reflection;
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    20
129
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
    21
fun atomize pairs =
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
    22
  let fun atoms th =
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
    23
        (case concl_of th of
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
    24
           Const("Trueprop",_) $ p =>
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
    25
             (case head_of p of
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
    26
                Const(a,_) =>
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
    27
                  (case assoc(pairs,a) of
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
    28
                     Some(rls) => flat (map atoms ([th] RL rls))
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
    29
                   | None => [th])
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
    30
              | _ => [th])
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
    31
         | _ => [th])
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
    32
  in atoms end;
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    33
129
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
    34
fun mk_meta_eq r = case concl_of r of
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    35
	Const("==",_)$_$_ => r
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    36
    |	_$(Const("op =",_)$_$_) => r RS eq_reflection
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    37
    |	_$(Const("not",_)$_) => r RS not_P_imp_P_eq_False
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    38
    |   _ => r RS P_imp_P_eq_True;
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    39
(* last 2 lines requires all formulae to be of the from Trueprop(.) *)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    40
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    41
fun gen_all th = forall_elim_vars (#maxidx(rep_thm th)+1) th;
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    42
1
142f1eb707b4 defined addcongs locally in simpdata.ML
nipkow
parents: 0
diff changeset
    43
val imp_cong = impI RSN
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    44
    (2, prove_goal HOL.thy "(P=P')--> (P'--> (Q=Q'))--> ((P-->Q) = (P'-->Q'))"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    45
	(fn _=> [fast_tac HOL_cs 1]) RS mp RS mp);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    46
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 62
diff changeset
    47
val o_apply = prove_goalw HOL.thy [o_def] "(f o g)(x) = f(g(x))"
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 62
diff changeset
    48
 (fn _ => [rtac refl 1]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    49
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    50
val simp_thms = map prover
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    51
 [ "(x=x) = True",
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    52
   "(~True) = False", "(~False) = True", "(~ ~ P) = P",
40
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
    53
   "(~P) ~= P", "P ~= (~P)", "(P ~= Q) = (P = (~Q))",
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    54
   "(True=P) = P", "(P=True) = P",
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    55
   "(True --> P) = P", "(False --> P) = True", 
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    56
   "(P --> True) = True", "(P --> P) = True",
129
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
    57
   "(P --> False) = (~P)", "(P --> ~P) = (~P)",
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    58
   "(P & True) = P", "(True & P) = P", 
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    59
   "(P & False) = False", "(False & P) = False", "(P & P) = P",
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    60
   "(P | True) = True", "(True | P) = True", 
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    61
   "(P | False) = P", "(False | P) = P", "(P | P) = P",
30
2fdeeae553ac modified solver of HOL_ss to take the new simplifier into account: the thm to
nipkow
parents: 3
diff changeset
    62
   "(!x.P) = P", "(? x.P) = P",
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    63
   "(P|Q --> R) = ((P-->R)&(Q-->R))" ];
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    64
99
be01ba66ba7b exposed meta_obj_reflection
nipkow
parents: 95
diff changeset
    65
in
be01ba66ba7b exposed meta_obj_reflection
nipkow
parents: 95
diff changeset
    66
100
e0d0e5b4994f renamed meta_obj_reflection meta_eq_to_obj_eq.
nipkow
parents: 99
diff changeset
    67
val meta_eq_to_obj_eq = prove_goal HOL.thy "x==y ==> x=y"
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    68
  (fn [prem] => [rewtac prem, rtac refl 1]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    69
95
3da472b96f25 added val eq_sym_conv = prover "(x=y) = (y=x)";
nipkow
parents: 66
diff changeset
    70
val eq_sym_conv = prover "(x=y) = (y=x)";
3da472b96f25 added val eq_sym_conv = prover "(x=y) = (y=x)";
nipkow
parents: 66
diff changeset
    71
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 32
diff changeset
    72
val conj_assoc = prover "((P&Q)&R) = (P&(Q&R))";
57
194d088c1511 Updated simpsets and a few proofs.
nipkow
parents: 43
diff changeset
    73
val conj_commute = prover "(P&Q) = (Q&P)";
62
32a83e3ad5a4 integrated permutative rewriting
nipkow
parents: 57
diff changeset
    74
val conj_left_commute = prover "(P&(Q&R)) = (Q&(P&R))";
32a83e3ad5a4 integrated permutative rewriting
nipkow
parents: 57
diff changeset
    75
val conj_comms = [conj_commute, conj_left_commute];
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    76
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 62
diff changeset
    77
val if_True = prove_goalw HOL.thy [if_def] "if(True,x,y) = x"
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 62
diff changeset
    78
 (fn _=>[fast_tac (HOL_cs addIs [select_equality]) 1]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    79
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 62
diff changeset
    80
val if_False = prove_goalw HOL.thy [if_def] "if(False,x,y) = y"
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 62
diff changeset
    81
 (fn _=>[fast_tac (HOL_cs addIs [select_equality]) 1]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    82
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    83
val if_P = prove_goal HOL.thy "P ==> if(P,x,y) = x"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    84
 (fn [prem] => [ stac (prem RS eqTrueI) 1, rtac if_True 1 ]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    85
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    86
val if_not_P = prove_goal HOL.thy "~P ==> if(P,x,y) = y"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    87
 (fn [prem] => [ stac (prem RS not_P_imp_P_iff_F) 1, rtac if_False 1 ]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    88
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    89
val expand_if = prove_goal HOL.thy
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    90
    "P(if(Q,x,y)) = ((Q --> P(x)) & (~Q --> P(y)))"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    91
 (fn _=> [ (res_inst_tac [("Q","Q")] (excluded_middle RS disjE) 1),
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    92
	 rtac (if_P RS ssubst) 2,
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    93
	 rtac (if_not_P RS ssubst) 1,
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    94
	 REPEAT(fast_tac HOL_cs 1) ]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    95
1
142f1eb707b4 defined addcongs locally in simpdata.ML
nipkow
parents: 0
diff changeset
    96
infix addcongs;
142f1eb707b4 defined addcongs locally in simpdata.ML
nipkow
parents: 0
diff changeset
    97
fun ss addcongs congs = ss addeqcongs (congs RL [eq_reflection]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    98
129
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
    99
val mksimps_pairs =
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
   100
  [("op -->", [mp]), ("op &", [conjunct1,conjunct2]),
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
   101
   ("All", [spec]), ("True", []), ("False", [])];
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
   102
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
   103
fun mksimps pairs = map mk_meta_eq o atomize pairs o gen_all;
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
   104
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   105
val HOL_ss = empty_ss
129
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
   106
      setmksimps (mksimps mksimps_pairs)
43
424c7b1489df added etac FalseE to the simplifier's solver.
nipkow
parents: 40
diff changeset
   107
      setsolver (fn prems => resolve_tac (TrueI::refl::prems) ORELSE' atac
424c7b1489df added etac FalseE to the simplifier's solver.
nipkow
parents: 40
diff changeset
   108
                             ORELSE' etac FalseE)
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   109
      setsubgoaler asm_simp_tac
34
7d437bed7765 added conj_assoc to HOL_ss
nipkow
parents: 32
diff changeset
   110
      addsimps ([if_True, if_False, o_apply, conj_assoc] @ simp_thms)
1
142f1eb707b4 defined addcongs locally in simpdata.ML
nipkow
parents: 0
diff changeset
   111
      addcongs [imp_cong];
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   112
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   113
fun split_tac splits =
129
0bba840aa07c New version of datatype.ML with primrec (Norbert).
nipkow
parents: 100
diff changeset
   114
  mk_case_split_tac (meta_eq_to_obj_eq RS iffD2) (map mk_meta_eq splits);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   115
40
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
   116
(* eliminiation of existential quantifiers in assumptions *)
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
   117
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
   118
val ex_all_equiv =
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
   119
  let val lemma1 = prove_goal HOL.thy
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
   120
        "(? x. P(x) ==> PROP Q) ==> (!!x. P(x) ==> PROP Q)"
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
   121
        (fn prems => [resolve_tac prems 1, etac exI 1]);
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 62
diff changeset
   122
      val lemma2 = prove_goalw HOL.thy [Ex_def]
40
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
   123
        "(!!x. P(x) ==> PROP Q) ==> (? x. P(x) ==> PROP Q)"
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
   124
        (fn prems => [REPEAT(resolve_tac prems 1)])
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
   125
  in equal_intr lemma1 lemma2 end;
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 34
diff changeset
   126
30
2fdeeae553ac modified solver of HOL_ss to take the new simplifier into account: the thm to
nipkow
parents: 3
diff changeset
   127
(** '&' congruence rule: not included by default! *)
2fdeeae553ac modified solver of HOL_ss to take the new simplifier into account: the thm to
nipkow
parents: 3
diff changeset
   128
2fdeeae553ac modified solver of HOL_ss to take the new simplifier into account: the thm to
nipkow
parents: 3
diff changeset
   129
val conj_cong = impI RSN
2fdeeae553ac modified solver of HOL_ss to take the new simplifier into account: the thm to
nipkow
parents: 3
diff changeset
   130
    (2, prove_goal HOL.thy "(P=P')--> (P'--> (Q=Q'))--> ((P&Q) = (P'&Q'))"
2fdeeae553ac modified solver of HOL_ss to take the new simplifier into account: the thm to
nipkow
parents: 3
diff changeset
   131
	(fn _=> [fast_tac HOL_cs 1]) RS mp RS mp);
2fdeeae553ac modified solver of HOL_ss to take the new simplifier into account: the thm to
nipkow
parents: 3
diff changeset
   132
3
a910a65478be This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents: 1
diff changeset
   133
(** 'if' congruence rules: neither included by default! *)
a910a65478be This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents: 1
diff changeset
   134
a910a65478be This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents: 1
diff changeset
   135
(*Simplifies x assuming c and y assuming ~c*)
a910a65478be This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents: 1
diff changeset
   136
val if_cong = prove_goal HOL.thy
a910a65478be This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents: 1
diff changeset
   137
  "[| b=c; c ==> x=u; ~c ==> y=v |] ==> if(b,x,y) = if(c,u,v)"
a910a65478be This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents: 1
diff changeset
   138
  (fn rew::prems =>
a910a65478be This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents: 1
diff changeset
   139
   [stac rew 1, stac expand_if 1, stac expand_if 1,
a910a65478be This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents: 1
diff changeset
   140
    fast_tac (HOL_cs addDs prems) 1]);
a910a65478be This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents: 1
diff changeset
   141
a910a65478be This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents: 1
diff changeset
   142
(*Prevents simplification of x and y: much faster*)
a910a65478be This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents: 1
diff changeset
   143
val if_weak_cong = prove_goal HOL.thy
a910a65478be This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents: 1
diff changeset
   144
  "b=c ==> if(b,x,y) = if(c,x,y)"
a910a65478be This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents: 1
diff changeset
   145
  (fn [prem] => [rtac (prem RS arg_cong) 1]);
a910a65478be This repeats a previous commit, which failed to update simpdata.ML because
lcp
parents: 1
diff changeset
   146
32
4ea58120ef3d added let_weak_cong
nipkow
parents: 30
diff changeset
   147
(*Prevents simplification of t: much faster*)
4ea58120ef3d added let_weak_cong
nipkow
parents: 30
diff changeset
   148
val let_weak_cong = prove_goal HOL.thy
4ea58120ef3d added let_weak_cong
nipkow
parents: 30
diff changeset
   149
  "a = b ==> (let x=a in t(x)) = (let x=b in t(x))"
4ea58120ef3d added let_weak_cong
nipkow
parents: 30
diff changeset
   150
  (fn [prem] => [rtac (prem RS arg_cong) 1]);
4ea58120ef3d added let_weak_cong
nipkow
parents: 30
diff changeset
   151
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   152
end;