src/HOL/Prod.ML
author oheimb
Tue, 02 Jun 1998 15:07:25 +0200
changeset 4989 857dabe71d72
parent 4830 bd73675adbed
child 5069 3ea049f7979d
permissions -rw-r--r--
added split_etas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1454
diff changeset
     1
(*  Title:      HOL/prod
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1454
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1991  University of Cambridge
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     6
For prod.thy.  Ordered Pairs, the Cartesian product type, the unit type
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     7
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     9
open Prod;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    10
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    11
(*This counts as a non-emptiness result for admitting 'a * 'b as a type*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    12
goalw Prod.thy [Prod_def] "Pair_Rep a b : Prod";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    13
by (EVERY1 [rtac CollectI, rtac exI, rtac exI, rtac refl]);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    14
qed "ProdI";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    15
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    16
val [major] = goalw Prod.thy [Pair_Rep_def]
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    17
    "Pair_Rep a b = Pair_Rep a' b' ==> a=a' & b=b'";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    18
by (EVERY1 [rtac (major RS fun_cong RS fun_cong RS subst), 
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1454
diff changeset
    19
            rtac conjI, rtac refl, rtac refl]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    20
qed "Pair_Rep_inject";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    21
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4828
diff changeset
    22
goal Prod.thy "inj_on Abs_Prod Prod";
bd73675adbed Added a few lemmas.
nipkow
parents: 4828
diff changeset
    23
by (rtac inj_on_inverseI 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    24
by (etac Abs_Prod_inverse 1);
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4828
diff changeset
    25
qed "inj_on_Abs_Prod";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    26
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    27
val prems = goalw Prod.thy [Pair_def]
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    28
    "[| (a, b) = (a',b');  [| a=a';  b=b' |] ==> R |] ==> R";
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4828
diff changeset
    29
by (rtac (inj_on_Abs_Prod RS inj_onD RS Pair_Rep_inject RS conjE) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    30
by (REPEAT (ares_tac (prems@[ProdI]) 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    31
qed "Pair_inject";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    32
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    33
goal Prod.thy "((a,b) = (a',b')) = (a=a' & b=b')";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
    34
by (blast_tac (claset() addSEs [Pair_inject]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    35
qed "Pair_eq";
3429
nipkow
parents: 2935
diff changeset
    36
AddIffs [Pair_eq];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    37
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    38
goalw Prod.thy [fst_def] "fst((a,b)) = a";
4534
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
    39
by (Blast_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    40
qed "fst_conv";
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    41
goalw Prod.thy [snd_def] "snd((a,b)) = b";
4534
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
    42
by (Blast_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    43
qed "snd_conv";
4534
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
    44
Addsimps [fst_conv, snd_conv];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    45
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    46
goalw Prod.thy [Pair_def] "? x y. p = (x,y)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
by (rtac (rewrite_rule [Prod_def] Rep_Prod RS CollectE) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    48
by (EVERY1[etac exE, etac exE, rtac exI, rtac exI,
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1454
diff changeset
    49
           rtac (Rep_Prod_inverse RS sym RS trans),  etac arg_cong]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    50
qed "PairE_lemma";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    51
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
    52
val [prem] = goal Prod.thy "[| !!x y. p = (x,y) ==> Q |] ==> Q";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    53
by (rtac (PairE_lemma RS exE) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    54
by (REPEAT (eresolve_tac [prem,exE] 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    55
qed "PairE";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    56
4819
ef2e8e2a10e1 improved pair_tac to call prune_params_tac afterwards
oheimb
parents: 4799
diff changeset
    57
fun pair_tac s = EVERY' [res_inst_tac [("p",s)] PairE, hyp_subst_tac,
ef2e8e2a10e1 improved pair_tac to call prune_params_tac afterwards
oheimb
parents: 4799
diff changeset
    58
			 K prune_params_tac];
4134
5c6cb2a25816 added several theorems
oheimb
parents: 4089
diff changeset
    59
4828
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    60
(* Do not add as rewrite rule: invalidates some proofs in IMP *)
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    61
goal Prod.thy "p = (fst(p),snd(p))";
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    62
by (pair_tac "p" 1);
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    63
by (Asm_simp_tac 1);
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    64
qed "surjective_pairing";
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    65
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    66
val surj_pair = prove_goal Prod.thy "? x y. z = (x, y)" (K [
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    67
	rtac exI 1, rtac exI 1, rtac surjective_pairing 1]);
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    68
Addsimps [surj_pair];
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    69
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    70
(* lemmas for splitting paired `!!' *)
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    71
local 
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    72
    val lemma1 = prove_goal Prod.thy "(!!x. PROP P x) ==> (!!a b. PROP P(a,b))" 
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    73
		 (fn prems => [resolve_tac prems 1]);
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    74
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    75
    val psig = sign_of Prod.thy;
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    76
    val pT = Sign.read_typ (psig, K None) "?'a*?'b=>prop";
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    77
    val PeqP = reflexive(read_cterm psig ("P", pT));
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    78
    val psplit = zero_var_indexes(read_instantiate [("p","x")]
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    79
                                  surjective_pairing RS eq_reflection);
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    80
    val adhoc = combination PeqP psplit;
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    81
    val lemma = prove_goal Prod.thy "(!!a b. PROP P(a,b)) ==> PROP P x" 
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    82
		(fn prems => [rewtac adhoc, resolve_tac prems 1]);
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    83
    val lemma2 = prove_goal Prod.thy "(!!a b. PROP P(a,b)) ==> (!!x. PROP P x)"
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    84
		(fn prems => [rtac lemma 1, resolve_tac prems 1]);
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    85
in
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    86
  val split_paired_all = equal_intr lemma1 lemma2
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    87
end;
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    88
bind_thm("split_paired_all", split_paired_all);
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    89
(*
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    90
Addsimps [split_paired_all] does not work with simplifier 
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    91
because it also affects premises in congrence rules, 
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    92
where is can lead to premises of the form !!a b. ... = ?P(a,b)
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    93
which cannot be solved by reflexivity.
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    94
*)
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
    95
1301
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    96
(* replace parameters of product type by individual component parameters *)
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    97
local
4819
ef2e8e2a10e1 improved pair_tac to call prune_params_tac afterwards
oheimb
parents: 4799
diff changeset
    98
  fun is_pair (_,Type("*",_)) = true
ef2e8e2a10e1 improved pair_tac to call prune_params_tac afterwards
oheimb
parents: 4799
diff changeset
    99
    | is_pair  _              = false;
4828
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
   100
  fun exists_paired_all prem  = exists is_pair (Logic.strip_params prem);
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
   101
  val split_tac = full_simp_tac (HOL_basic_ss addsimps [split_paired_all]);
1301
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
   102
in
4828
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
   103
val split_all_tac = SUBGOAL (fn (prem,i) => 
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
   104
    if exists_paired_all prem then split_tac i else no_tac);  
1301
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
   105
end;
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
   106
4828
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
   107
claset_ref() := claset() addSWrapper ("split_all_tac", 
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
   108
				      fn tac2 => split_all_tac ORELSE' tac2);
3568
36ff1ab12021 Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents: 3429
diff changeset
   109
1301
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
   110
goal Prod.thy "(!x. P x) = (!a b. P(a,b))";
4650
91af1ef45d68 added split_all_tac to claset()
oheimb
parents: 4534
diff changeset
   111
by (Fast_tac 1);
1301
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
   112
qed "split_paired_All";
3568
36ff1ab12021 Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents: 3429
diff changeset
   113
Addsimps [split_paired_All];
36ff1ab12021 Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents: 3429
diff changeset
   114
(* AddIffs is not a good idea because it makes Blast_tac loop *)
36ff1ab12021 Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents: 3429
diff changeset
   115
36ff1ab12021 Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents: 3429
diff changeset
   116
goal Prod.thy "(? x. P x) = (? a b. P(a,b))";
4650
91af1ef45d68 added split_all_tac to claset()
oheimb
parents: 4534
diff changeset
   117
by (Fast_tac 1);
3568
36ff1ab12021 Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents: 3429
diff changeset
   118
qed "split_paired_Ex";
4534
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   119
Addsimps [split_paired_Ex];
1301
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
   120
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   121
goalw Prod.thy [split_def] "split c (a,b) = c a b";
4534
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   122
by (Simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   123
qed "split";
4534
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   124
Addsimps [split];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   125
4828
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
   126
goal Prod.thy "split Pair p = p";
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
   127
by (pair_tac "p" 1);
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
   128
by (Simp_tac 1);
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
   129
qed "split_Pair";
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
   130
(*unused: val surjective_pairing2 = split_Pair RS sym;*)
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
   131
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
   132
goal Prod.thy "!!s t. (s=t) = (fst(s)=fst(t) & snd(s)=snd(t))";
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
   133
by (split_all_tac 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 972
diff changeset
   134
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   135
qed "Pair_fst_snd_eq";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   136
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   137
(*Prevents simplification of c: much faster*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   138
qed_goal "split_weak_cong" Prod.thy
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   139
  "p=q ==> split c p = split c q"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   140
  (fn [prem] => [rtac (prem RS arg_cong) 1]);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   141
1655
5be64540f275 Added a number of lemmas
nipkow
parents: 1642
diff changeset
   142
qed_goal "split_eta" Prod.thy "(%(x,y). f(x,y)) = f"
4534
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   143
  (K [rtac ext 1, split_all_tac 1, rtac split 1]);
1655
5be64540f275 Added a number of lemmas
nipkow
parents: 1642
diff changeset
   144
4989
857dabe71d72 added split_etas
oheimb
parents: 4830
diff changeset
   145
qed_goal "cond_split_eta" Prod.thy 
857dabe71d72 added split_etas
oheimb
parents: 4830
diff changeset
   146
	"!!f. (!!x y. f x y = g(x,y)) ==> (%(x,y). f x y) = g"
857dabe71d72 added split_etas
oheimb
parents: 4830
diff changeset
   147
  (K [asm_simp_tac (simpset() addsimps [split_eta]) 1]);
857dabe71d72 added split_etas
oheimb
parents: 4830
diff changeset
   148
(*Addsimps [cond_split_eta];  with this version of split_eta, the simplifier 
857dabe71d72 added split_etas
oheimb
parents: 4830
diff changeset
   149
			      can eta-contract arbitrarily tupled functions.
857dabe71d72 added split_etas
oheimb
parents: 4830
diff changeset
   150
  Unfortunately, this renders some existing proofs very inefficient.
857dabe71d72 added split_etas
oheimb
parents: 4830
diff changeset
   151
                 stac split_eta does not work in general either. *)
857dabe71d72 added split_etas
oheimb
parents: 4830
diff changeset
   152
val split_etas = split_eta::map (fn s => prove_goal Prod.thy s 
857dabe71d72 added split_etas
oheimb
parents: 4830
diff changeset
   153
  (K [simp_tac (simpset() addsimps [cond_split_eta]) 1]))
857dabe71d72 added split_etas
oheimb
parents: 4830
diff changeset
   154
["(%(a,b,c    ). f(a,b,c    )) = f","(%(a,b,c,d    ). f(a,b,c,d    )) = f",
857dabe71d72 added split_etas
oheimb
parents: 4830
diff changeset
   155
 "(%(a,b,c,d,e). f(a,b,c,d,e)) = f","(%(a,b,c,d,e,g). f(a,b,c,d,e,g)) = f"];
857dabe71d72 added split_etas
oheimb
parents: 4830
diff changeset
   156
Addsimps split_etas; (* pragmatic solution *)
857dabe71d72 added split_etas
oheimb
parents: 4830
diff changeset
   157
857dabe71d72 added split_etas
oheimb
parents: 4830
diff changeset
   158
Goal "(%(x,y,z).f(x,y,z)) = t";
857dabe71d72 added split_etas
oheimb
parents: 4830
diff changeset
   159
by(simp_tac (simpset() addsimps [cond_split_eta]) 1);
857dabe71d72 added split_etas
oheimb
parents: 4830
diff changeset
   160
4819
ef2e8e2a10e1 improved pair_tac to call prune_params_tac afterwards
oheimb
parents: 4799
diff changeset
   161
qed_goal "split_beta" Prod.thy "(%(x,y). P x y) z = P (fst z) (snd z)"
4534
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   162
	(K [stac surjective_pairing 1, stac split 1, rtac refl 1]);
4134
5c6cb2a25816 added several theorems
oheimb
parents: 4089
diff changeset
   163
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   164
(*For use with split_tac and the simplifier*)
4435
41a7e4f0e957 added expand_split_asm
oheimb
parents: 4423
diff changeset
   165
goal Prod.thy "R (split c p) = (! x y. p = (x,y) --> R (c x y))";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   166
by (stac surjective_pairing 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   167
by (stac split 1);
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2886
diff changeset
   168
by (Blast_tac 1);
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4828
diff changeset
   169
qed "split_split";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   170
3568
36ff1ab12021 Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents: 3429
diff changeset
   171
(* could be done after split_tac has been speeded up significantly:
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4828
diff changeset
   172
simpset_ref() := simpset() addsplits [split_split];
3568
36ff1ab12021 Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents: 3429
diff changeset
   173
   precompute the constants involved and don't do anything unless
36ff1ab12021 Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents: 3429
diff changeset
   174
   the current goal contains one of those constants
36ff1ab12021 Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents: 3429
diff changeset
   175
*)
36ff1ab12021 Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents: 3429
diff changeset
   176
4435
41a7e4f0e957 added expand_split_asm
oheimb
parents: 4423
diff changeset
   177
goal Prod.thy "R (split c p) = (~(? x y. p = (x,y) & (~R (c x y))))";
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4828
diff changeset
   178
by (stac split_split 1);
4435
41a7e4f0e957 added expand_split_asm
oheimb
parents: 4423
diff changeset
   179
by (Simp_tac 1);
41a7e4f0e957 added expand_split_asm
oheimb
parents: 4423
diff changeset
   180
qed "expand_split_asm";
41a7e4f0e957 added expand_split_asm
oheimb
parents: 4423
diff changeset
   181
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   182
(** split used as a logical connective or set former **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   183
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2886
diff changeset
   184
(*These rules are for use with blast_tac.
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   185
  Could instead call simp_tac/asm_full_simp_tac using split as rewrite.*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   186
1454
d0266c81a85e Streamlined defs in Relation and added new intro/elim rules to do with
nipkow
parents: 1301
diff changeset
   187
goal Prod.thy "!!p. [| !!a b. p=(a,b) ==> c a b |] ==> split c p";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1515
diff changeset
   188
by (split_all_tac 1);
1454
d0266c81a85e Streamlined defs in Relation and added new intro/elim rules to do with
nipkow
parents: 1301
diff changeset
   189
by (Asm_simp_tac 1);
d0266c81a85e Streamlined defs in Relation and added new intro/elim rules to do with
nipkow
parents: 1301
diff changeset
   190
qed "splitI2";
d0266c81a85e Streamlined defs in Relation and added new intro/elim rules to do with
nipkow
parents: 1301
diff changeset
   191
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   192
goal Prod.thy "!!a b c. c a b ==> split c (a,b)";
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 972
diff changeset
   193
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   194
qed "splitI";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   195
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   196
val prems = goalw Prod.thy [split_def]
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   197
    "[| split c p;  !!x y. [| p = (x,y);  c x y |] ==> Q |] ==> Q";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   198
by (REPEAT (resolve_tac (prems@[surjective_pairing]) 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   199
qed "splitE";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   200
4134
5c6cb2a25816 added several theorems
oheimb
parents: 4089
diff changeset
   201
val splitE2 = prove_goal Prod.thy 
5c6cb2a25816 added several theorems
oheimb
parents: 4089
diff changeset
   202
"[|Q (split P z); !!x y. [|z = (x, y); Q (P x y)|] ==> R|] ==> R" (fn prems => [
5c6cb2a25816 added several theorems
oheimb
parents: 4089
diff changeset
   203
	REPEAT (resolve_tac (prems@[surjective_pairing]) 1),
5c6cb2a25816 added several theorems
oheimb
parents: 4089
diff changeset
   204
	rtac (split_beta RS subst) 1,
5c6cb2a25816 added several theorems
oheimb
parents: 4089
diff changeset
   205
	rtac (hd prems) 1]);
5c6cb2a25816 added several theorems
oheimb
parents: 4089
diff changeset
   206
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   207
goal Prod.thy "!!R a b. split R (a,b) ==> R a b";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   208
by (etac (split RS iffD1) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   209
qed "splitD";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   210
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   211
goal Prod.thy "!!a b c. z: c a b ==> z: split c (a,b)";
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 972
diff changeset
   212
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   213
qed "mem_splitI";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   214
1454
d0266c81a85e Streamlined defs in Relation and added new intro/elim rules to do with
nipkow
parents: 1301
diff changeset
   215
goal Prod.thy "!!p. [| !!a b. p=(a,b) ==> z: c a b |] ==> z: split c p";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1515
diff changeset
   216
by (split_all_tac 1);
1454
d0266c81a85e Streamlined defs in Relation and added new intro/elim rules to do with
nipkow
parents: 1301
diff changeset
   217
by (Asm_simp_tac 1);
d0266c81a85e Streamlined defs in Relation and added new intro/elim rules to do with
nipkow
parents: 1301
diff changeset
   218
qed "mem_splitI2";
d0266c81a85e Streamlined defs in Relation and added new intro/elim rules to do with
nipkow
parents: 1301
diff changeset
   219
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   220
val prems = goalw Prod.thy [split_def]
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   221
    "[| z: split c p;  !!x y. [| p = (x,y);  z: c x y |] ==> Q |] ==> Q";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   222
by (REPEAT (resolve_tac (prems@[surjective_pairing]) 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   223
qed "mem_splitE";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   224
2856
cdb908486a96 Reorganization of how classical rules are installed
paulson
parents: 2637
diff changeset
   225
AddSIs [splitI, splitI2, mem_splitI, mem_splitI2];
cdb908486a96 Reorganization of how classical rules are installed
paulson
parents: 2637
diff changeset
   226
AddSEs [splitE, mem_splitE];
cdb908486a96 Reorganization of how classical rules are installed
paulson
parents: 2637
diff changeset
   227
4534
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   228
(* allows simplifications of nested splits in case of independent predicates *)
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   229
goal Prod.thy "(%(a,b). P & Q a b) = (%ab. P & split Q ab)";
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   230
by (rtac ext 1);
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   231
by (Blast_tac 1);
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   232
qed "split_part";
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   233
Addsimps [split_part];
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   234
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   235
goal Prod.thy "(@(x',y'). x = x' & y = y') = (x,y)";
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   236
by (Blast_tac 1);
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   237
qed "Eps_split_eq";
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   238
Addsimps [Eps_split_eq];
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   239
(*
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   240
the following  would be slightly more general, 
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   241
but cannot be used as rewrite rule:
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   242
### Cannot add premise as rewrite rule because it contains (type) unknowns:
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   243
### ?y = .x
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   244
goal Prod.thy "!!P. [| P y; !!x. P x ==> x = y |] ==> (@(x',y). x = x' & P y) = (x,y)";
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   245
by (rtac select_equality 1);
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   246
by ( Simp_tac 1);
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   247
by (split_all_tac 1);
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   248
by (Asm_full_simp_tac 1);
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   249
qed "Eps_split_eq";
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   250
*)
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   251
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   252
(*** prod_fun -- action of the product functor upon functions ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   253
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   254
goalw Prod.thy [prod_fun_def] "prod_fun f g (a,b) = (f(a),g(b))";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   255
by (rtac split 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   256
qed "prod_fun";
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4435
diff changeset
   257
Addsimps [prod_fun];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   258
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   259
goal Prod.thy 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   260
    "prod_fun (f1 o f2) (g1 o g2) = ((prod_fun f1 g1) o (prod_fun f2 g2))";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   261
by (rtac ext 1);
4828
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
   262
by (pair_tac "x" 1);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4435
diff changeset
   263
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   264
qed "prod_fun_compose";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   265
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3568
diff changeset
   266
goal Prod.thy "prod_fun (%x. x) (%y. y) = (%z. z)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   267
by (rtac ext 1);
4828
ee3317896a47 improved split_all_tac significantly
oheimb
parents: 4819
diff changeset
   268
by (pair_tac "z" 1);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4435
diff changeset
   269
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   270
qed "prod_fun_ident";
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4435
diff changeset
   271
Addsimps [prod_fun_ident];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   272
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   273
val prems = goal Prod.thy "(a,b):r ==> (f(a),g(b)) : (prod_fun f g)``r";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   274
by (rtac image_eqI 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   275
by (rtac (prod_fun RS sym) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   276
by (resolve_tac prems 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   277
qed "prod_fun_imageI";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   278
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   279
val major::prems = goal Prod.thy
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   280
    "[| c: (prod_fun f g)``r;  !!x y. [| c=(f(x),g(y));  (x,y):r |] ==> P  \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   281
\    |] ==> P";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   282
by (rtac (major RS imageE) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   283
by (res_inst_tac [("p","x")] PairE 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   284
by (resolve_tac prems 1);
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2886
diff changeset
   285
by (Blast_tac 2);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   286
by (blast_tac (claset() addIs [prod_fun]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   287
qed "prod_fun_imageE";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   288
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4435
diff changeset
   289
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   290
(*** Disjoint union of a family of sets - Sigma ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   291
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   292
qed_goalw "SigmaI" Prod.thy [Sigma_def]
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   293
    "[| a:A;  b:B(a) |] ==> (a,b) : Sigma A B"
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   294
 (fn prems=> [ (REPEAT (resolve_tac (prems@[singletonI,UN_I]) 1)) ]);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   295
2856
cdb908486a96 Reorganization of how classical rules are installed
paulson
parents: 2637
diff changeset
   296
AddSIs [SigmaI];
cdb908486a96 Reorganization of how classical rules are installed
paulson
parents: 2637
diff changeset
   297
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   298
(*The general elimination rule*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   299
qed_goalw "SigmaE" Prod.thy [Sigma_def]
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   300
    "[| c: Sigma A B;  \
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   301
\       !!x y.[| x:A;  y:B(x);  c=(x,y) |] ==> P \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   302
\    |] ==> P"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   303
 (fn major::prems=>
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   304
  [ (cut_facts_tac [major] 1),
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   305
    (REPEAT (eresolve_tac [UN_E, singletonE] 1 ORELSE ares_tac prems 1)) ]);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   306
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   307
(** Elimination of (a,b):A*B -- introduces no eigenvariables **)
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   308
qed_goal "SigmaD1" Prod.thy "(a,b) : Sigma A B ==> a : A"
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   309
 (fn [major]=>
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   310
  [ (rtac (major RS SigmaE) 1),
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   311
    (REPEAT (eresolve_tac [asm_rl,Pair_inject,ssubst] 1)) ]);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   312
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   313
qed_goal "SigmaD2" Prod.thy "(a,b) : Sigma A B ==> b : B(a)"
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   314
 (fn [major]=>
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   315
  [ (rtac (major RS SigmaE) 1),
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   316
    (REPEAT (eresolve_tac [asm_rl,Pair_inject,ssubst] 1)) ]);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   317
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   318
qed_goal "SigmaE2" Prod.thy
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   319
    "[| (a,b) : Sigma A B;    \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   320
\       [| a:A;  b:B(a) |] ==> P   \
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   321
\    |] ==> P"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   322
 (fn [major,minor]=>
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   323
  [ (rtac minor 1),
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   324
    (rtac (major RS SigmaD1) 1),
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   325
    (rtac (major RS SigmaD2) 1) ]);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   326
2856
cdb908486a96 Reorganization of how classical rules are installed
paulson
parents: 2637
diff changeset
   327
AddSEs [SigmaE2, SigmaE];
cdb908486a96 Reorganization of how classical rules are installed
paulson
parents: 2637
diff changeset
   328
1515
4ed79ebab64d Introduced normalize_thm into HOL.ML
nipkow
parents: 1485
diff changeset
   329
val prems = goal Prod.thy
1642
21db0cf9a1a4 Using new "Times" infix
paulson
parents: 1618
diff changeset
   330
    "[| A<=C;  !!x. x:A ==> B x <= D x |] ==> Sigma A B <= Sigma C D";
1515
4ed79ebab64d Introduced normalize_thm into HOL.ML
nipkow
parents: 1485
diff changeset
   331
by (cut_facts_tac prems 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   332
by (blast_tac (claset() addIs (prems RL [subsetD])) 1);
1515
4ed79ebab64d Introduced normalize_thm into HOL.ML
nipkow
parents: 1485
diff changeset
   333
qed "Sigma_mono";
4ed79ebab64d Introduced normalize_thm into HOL.ML
nipkow
parents: 1485
diff changeset
   334
1618
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   335
qed_goal "Sigma_empty1" Prod.thy "Sigma {} B = {}"
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2886
diff changeset
   336
 (fn _ => [ (Blast_tac 1) ]);
1618
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   337
1642
21db0cf9a1a4 Using new "Times" infix
paulson
parents: 1618
diff changeset
   338
qed_goal "Sigma_empty2" Prod.thy "A Times {} = {}"
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2886
diff changeset
   339
 (fn _ => [ (Blast_tac 1) ]);
1618
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   340
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   341
Addsimps [Sigma_empty1,Sigma_empty2]; 
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   342
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   343
goal Prod.thy "((a,b): Sigma A B) = (a:A & b:B(a))";
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2886
diff changeset
   344
by (Blast_tac 1);
1618
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   345
qed "mem_Sigma_iff";
3568
36ff1ab12021 Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents: 3429
diff changeset
   346
AddIffs [mem_Sigma_iff]; 
1618
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   347
4534
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   348
val Collect_split = prove_goal Prod.thy 
4134
5c6cb2a25816 added several theorems
oheimb
parents: 4089
diff changeset
   349
	"{(a,b). P a & Q b} = Collect P Times Collect Q" (K [Blast_tac 1]);
4534
6932c3ae3912 added select_equality to the implicit claset
oheimb
parents: 4521
diff changeset
   350
Addsimps [Collect_split];
1515
4ed79ebab64d Introduced normalize_thm into HOL.ML
nipkow
parents: 1485
diff changeset
   351
2856
cdb908486a96 Reorganization of how classical rules are installed
paulson
parents: 2637
diff changeset
   352
(*Suggested by Pierre Chartier*)
cdb908486a96 Reorganization of how classical rules are installed
paulson
parents: 2637
diff changeset
   353
goal Prod.thy
cdb908486a96 Reorganization of how classical rules are installed
paulson
parents: 2637
diff changeset
   354
     "(UN (a,b):(A Times B). E a Times F b) = (UNION A E) Times (UNION B F)";
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2886
diff changeset
   355
by (Blast_tac 1);
2856
cdb908486a96 Reorganization of how classical rules are installed
paulson
parents: 2637
diff changeset
   356
qed "UNION_Times_distrib";
cdb908486a96 Reorganization of how classical rules are installed
paulson
parents: 2637
diff changeset
   357
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   358
(*** Domain of a relation ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   359
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   360
val prems = goalw Prod.thy [image_def] "(a,b) : r ==> a : fst``r";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   361
by (rtac CollectI 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   362
by (rtac bexI 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   363
by (rtac (fst_conv RS sym) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   364
by (resolve_tac prems 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   365
qed "fst_imageI";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   366
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   367
val major::prems = goal Prod.thy
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   368
    "[| a : fst``r;  !!y.[| (a,y) : r |] ==> P |] ==> P"; 
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   369
by (rtac (major RS imageE) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   370
by (resolve_tac prems 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   371
by (etac ssubst 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   372
by (rtac (surjective_pairing RS subst) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   373
by (assume_tac 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   374
qed "fst_imageE";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   375
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   376
(*** Range of a relation ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   377
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   378
val prems = goalw Prod.thy [image_def] "(a,b) : r ==> b : snd``r";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   379
by (rtac CollectI 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   380
by (rtac bexI 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   381
by (rtac (snd_conv RS sym) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   382
by (resolve_tac prems 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   383
qed "snd_imageI";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   384
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   385
val major::prems = goal Prod.thy
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   386
    "[| a : snd``r;  !!y.[| (y,a) : r |] ==> P |] ==> P"; 
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   387
by (rtac (major RS imageE) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   388
by (resolve_tac prems 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   389
by (etac ssubst 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   390
by (rtac (surjective_pairing RS subst) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   391
by (assume_tac 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   392
qed "snd_imageE";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   393
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   394
(** Exhaustion rule for unit -- a degenerate form of induction **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   395
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   396
goalw Prod.thy [Unity_def]
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 923
diff changeset
   397
    "u = ()";
2886
fd5645efa43d Now: unit = {True}
nipkow
parents: 2880
diff changeset
   398
by (stac (rewrite_rule [unit_def] Rep_unit RS singletonD RS sym) 1);
2880
a0fde30aa126 Removed (Unit) in Prod.
nipkow
parents: 2856
diff changeset
   399
by (rtac (Rep_unit_inverse RS sym) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   400
qed "unit_eq";
1754
852093aeb0ab Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1746
diff changeset
   401
 
852093aeb0ab Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1746
diff changeset
   402
AddIs  [fst_imageI, snd_imageI, prod_fun_imageI];
2856
cdb908486a96 Reorganization of how classical rules are installed
paulson
parents: 2637
diff changeset
   403
AddSEs [fst_imageE, snd_imageE, prod_fun_imageE];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   404
1746
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   405
structure Prod_Syntax =
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   406
struct
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   407
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   408
val unitT = Type("unit",[]);
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   409
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   410
fun mk_prod (T1,T2) = Type("*", [T1,T2]);
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   411
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   412
(*Maps the type T1*...*Tn to [T1,...,Tn], however nested*)
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   413
fun factors (Type("*", [T1,T2])) = factors T1 @ factors T2
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   414
  | factors T                    = [T];
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   415
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   416
(*Make a correctly typed ordered pair*)
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   417
fun mk_Pair (t1,t2) = 
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   418
  let val T1 = fastype_of t1
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   419
      and T2 = fastype_of t2
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   420
  in  Const("Pair", [T1, T2] ---> mk_prod(T1,T2)) $ t1 $ t2  end;
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   421
   
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   422
fun split_const(Ta,Tb,Tc) = 
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   423
    Const("split", [[Ta,Tb]--->Tc, mk_prod(Ta,Tb)] ---> Tc);
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   424
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   425
(*In ap_split S T u, term u expects separate arguments for the factors of S,
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   426
  with result type T.  The call creates a new term expecting one argument
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   427
  of type S.*)
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   428
fun ap_split (Type("*", [T1,T2])) T3 u = 
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   429
      split_const(T1,T2,T3) $ 
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   430
      Abs("v", T1, 
2031
03a843f0f447 Ran expandshort
paulson
parents: 1754
diff changeset
   431
          ap_split T2 T3
03a843f0f447 Ran expandshort
paulson
parents: 1754
diff changeset
   432
             ((ap_split T1 (factors T2 ---> T3) (incr_boundvars 1 u)) $ 
03a843f0f447 Ran expandshort
paulson
parents: 1754
diff changeset
   433
              Bound 0))
1746
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   434
  | ap_split T T3 u = u;
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   435
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   436
(*Makes a nested tuple from a list, following the product type structure*)
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   437
fun mk_tuple (Type("*", [T1,T2])) tms = 
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   438
        mk_Pair (mk_tuple T1 tms, 
2031
03a843f0f447 Ran expandshort
paulson
parents: 1754
diff changeset
   439
                 mk_tuple T2 (drop (length (factors T1), tms)))
1746
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   440
  | mk_tuple T (t::_) = t;
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   441
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   442
(*Attempts to remove occurrences of split, and pair-valued parameters*)
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   443
val remove_split = rewrite_rule [split RS eq_reflection]  o  
4772
8c7e7eaffbdf split_all_tac now fails if there is nothing to split
oheimb
parents: 4650
diff changeset
   444
                   rule_by_tactic (TRYALL split_all_tac);
1746
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   445
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   446
(*Uncurries any Var of function type in the rule*)
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   447
fun split_rule_var (t as Var(v, Type("fun",[T1,T2])), rl) =
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   448
      let val T' = factors T1 ---> T2
2031
03a843f0f447 Ran expandshort
paulson
parents: 1754
diff changeset
   449
          val newt = ap_split T1 T2 (Var(v,T'))
03a843f0f447 Ran expandshort
paulson
parents: 1754
diff changeset
   450
          val cterm = Thm.cterm_of (#sign(rep_thm rl))
1746
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   451
      in
2031
03a843f0f447 Ran expandshort
paulson
parents: 1754
diff changeset
   452
          remove_split (instantiate ([], [(cterm t, cterm newt)]) rl)
1746
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   453
      end
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   454
  | split_rule_var (t,rl) = rl;
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   455
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   456
(*Uncurries ALL function variables occurring in a rule's conclusion*)
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   457
fun split_rule rl = foldr split_rule_var (term_vars (concl_of rl), rl)
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   458
                    |> standard;
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   459
f0c6aabc6c02 Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents: 1727
diff changeset
   460
end;