src/HOL/Set.ML
changeset 5143 b94cd208f073
parent 5069 3ea049f7979d
child 5148 74919e8f221c
equal deleted inserted replaced
5142:c56aa8b59dc0 5143:b94cd208f073
    11 section "Relating predicates and sets";
    11 section "Relating predicates and sets";
    12 
    12 
    13 Addsimps [Collect_mem_eq];
    13 Addsimps [Collect_mem_eq];
    14 AddIffs  [mem_Collect_eq];
    14 AddIffs  [mem_Collect_eq];
    15 
    15 
    16 Goal "!!a. P(a) ==> a : {x. P(x)}";
    16 Goal "P(a) ==> a : {x. P(x)}";
    17 by (Asm_simp_tac 1);
    17 by (Asm_simp_tac 1);
    18 qed "CollectI";
    18 qed "CollectI";
    19 
    19 
    20 val prems = goal Set.thy "!!a. a : {x. P(x)} ==> P(a)";
    20 val prems = goal Set.thy "!!a. a : {x. P(x)} ==> P(a)";
    21 by (Asm_full_simp_tac 1);
    21 by (Asm_full_simp_tac 1);
   323 qed_goalw "Un_iff" Set.thy [Un_def] "(c : A Un B) = (c:A | c:B)"
   323 qed_goalw "Un_iff" Set.thy [Un_def] "(c : A Un B) = (c:A | c:B)"
   324  (fn _ => [ Blast_tac 1 ]);
   324  (fn _ => [ Blast_tac 1 ]);
   325 
   325 
   326 Addsimps [Un_iff];
   326 Addsimps [Un_iff];
   327 
   327 
   328 Goal "!!c. c:A ==> c : A Un B";
   328 Goal "c:A ==> c : A Un B";
   329 by (Asm_simp_tac 1);
   329 by (Asm_simp_tac 1);
   330 qed "UnI1";
   330 qed "UnI1";
   331 
   331 
   332 Goal "!!c. c:B ==> c : A Un B";
   332 Goal "c:B ==> c : A Un B";
   333 by (Asm_simp_tac 1);
   333 by (Asm_simp_tac 1);
   334 qed "UnI2";
   334 qed "UnI2";
   335 
   335 
   336 (*Classical introduction rule: no commitment to A vs B*)
   336 (*Classical introduction rule: no commitment to A vs B*)
   337 qed_goal "UnCI" Set.thy "(c~:B ==> c:A) ==> c : A Un B"
   337 qed_goal "UnCI" Set.thy "(c~:B ==> c:A) ==> c : A Un B"
   354 qed_goalw "Int_iff" Set.thy [Int_def] "(c : A Int B) = (c:A & c:B)"
   354 qed_goalw "Int_iff" Set.thy [Int_def] "(c : A Int B) = (c:A & c:B)"
   355  (fn _ => [ (Blast_tac 1) ]);
   355  (fn _ => [ (Blast_tac 1) ]);
   356 
   356 
   357 Addsimps [Int_iff];
   357 Addsimps [Int_iff];
   358 
   358 
   359 Goal "!!c. [| c:A;  c:B |] ==> c : A Int B";
   359 Goal "[| c:A;  c:B |] ==> c : A Int B";
   360 by (Asm_simp_tac 1);
   360 by (Asm_simp_tac 1);
   361 qed "IntI";
   361 qed "IntI";
   362 
   362 
   363 Goal "!!c. c : A Int B ==> c:A";
   363 Goal "c : A Int B ==> c:A";
   364 by (Asm_full_simp_tac 1);
   364 by (Asm_full_simp_tac 1);
   365 qed "IntD1";
   365 qed "IntD1";
   366 
   366 
   367 Goal "!!c. c : A Int B ==> c:B";
   367 Goal "c : A Int B ==> c:B";
   368 by (Asm_full_simp_tac 1);
   368 by (Asm_full_simp_tac 1);
   369 qed "IntD2";
   369 qed "IntD2";
   370 
   370 
   371 val [major,minor] = goal Set.thy
   371 val [major,minor] = goal Set.thy
   372     "[| c : A Int B;  [| c:A; c:B |] ==> P |] ==> P";
   372     "[| c : A Int B;  [| c:A; c:B |] ==> P |] ==> P";
   434 section "Singletons, using insert";
   434 section "Singletons, using insert";
   435 
   435 
   436 qed_goal "singletonI" Set.thy "a : {a}"
   436 qed_goal "singletonI" Set.thy "a : {a}"
   437  (fn _=> [ (rtac insertI1 1) ]);
   437  (fn _=> [ (rtac insertI1 1) ]);
   438 
   438 
   439 Goal "!!a. b : {a} ==> b=a";
   439 Goal "b : {a} ==> b=a";
   440 by (Blast_tac 1);
   440 by (Blast_tac 1);
   441 qed "singletonD";
   441 qed "singletonD";
   442 
   442 
   443 bind_thm ("singletonE", make_elim singletonD);
   443 bind_thm ("singletonE", make_elim singletonD);
   444 
   444 
   445 qed_goal "singleton_iff" thy "(b : {a}) = (b=a)" 
   445 qed_goal "singleton_iff" thy "(b : {a}) = (b=a)" 
   446 (fn _ => [Blast_tac 1]);
   446 (fn _ => [Blast_tac 1]);
   447 
   447 
   448 Goal "!!a b. {a}={b} ==> a=b";
   448 Goal "{a}={b} ==> a=b";
   449 by (blast_tac (claset() addEs [equalityE]) 1);
   449 by (blast_tac (claset() addEs [equalityE]) 1);
   450 qed "singleton_inject";
   450 qed "singleton_inject";
   451 
   451 
   452 (*Redundant? But unlike insertCI, it proves the subgoal immediately!*)
   452 (*Redundant? But unlike insertCI, it proves the subgoal immediately!*)
   453 AddSIs [singletonI];   
   453 AddSIs [singletonI];   
   467 qed "UN_iff";
   467 qed "UN_iff";
   468 
   468 
   469 Addsimps [UN_iff];
   469 Addsimps [UN_iff];
   470 
   470 
   471 (*The order of the premises presupposes that A is rigid; b may be flexible*)
   471 (*The order of the premises presupposes that A is rigid; b may be flexible*)
   472 Goal "!!b. [| a:A;  b: B(a) |] ==> b: (UN x:A. B(x))";
   472 Goal "[| a:A;  b: B(a) |] ==> b: (UN x:A. B(x))";
   473 by Auto_tac;
   473 by Auto_tac;
   474 qed "UN_I";
   474 qed "UN_I";
   475 
   475 
   476 val major::prems = goalw Set.thy [UNION_def]
   476 val major::prems = goalw Set.thy [UNION_def]
   477     "[| b : (UN x:A. B(x));  !!x.[| x:A;  b: B(x) |] ==> R |] ==> R";
   477     "[| b : (UN x:A. B(x));  !!x.[| x:A;  b: B(x) |] ==> R |] ==> R";
   502 val prems = goalw Set.thy [INTER_def]
   502 val prems = goalw Set.thy [INTER_def]
   503     "(!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))";
   503     "(!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))";
   504 by (REPEAT (ares_tac ([CollectI,ballI] @ prems) 1));
   504 by (REPEAT (ares_tac ([CollectI,ballI] @ prems) 1));
   505 qed "INT_I";
   505 qed "INT_I";
   506 
   506 
   507 Goal "!!b. [| b : (INT x:A. B(x));  a:A |] ==> b: B(a)";
   507 Goal "[| b : (INT x:A. B(x));  a:A |] ==> b: B(a)";
   508 by Auto_tac;
   508 by Auto_tac;
   509 qed "INT_D";
   509 qed "INT_D";
   510 
   510 
   511 (*"Classical" elimination -- by the Excluded Middle on a:A *)
   511 (*"Classical" elimination -- by the Excluded Middle on a:A *)
   512 val major::prems = goalw Set.thy [INTER_def]
   512 val major::prems = goalw Set.thy [INTER_def]
   534 qed "Union_iff";
   534 qed "Union_iff";
   535 
   535 
   536 Addsimps [Union_iff];
   536 Addsimps [Union_iff];
   537 
   537 
   538 (*The order of the premises presupposes that C is rigid; A may be flexible*)
   538 (*The order of the premises presupposes that C is rigid; A may be flexible*)
   539 Goal "!!X. [| X:C;  A:X |] ==> A : Union(C)";
   539 Goal "[| X:C;  A:X |] ==> A : Union(C)";
   540 by Auto_tac;
   540 by Auto_tac;
   541 qed "UnionI";
   541 qed "UnionI";
   542 
   542 
   543 val major::prems = goalw Set.thy [Union_def]
   543 val major::prems = goalw Set.thy [Union_def]
   544     "[| A : Union(C);  !!X.[| A:X;  X:C |] ==> R |] ==> R";
   544     "[| A : Union(C);  !!X.[| A:X;  X:C |] ==> R |] ==> R";
   563 by (REPEAT (ares_tac ([INT_I] @ prems) 1));
   563 by (REPEAT (ares_tac ([INT_I] @ prems) 1));
   564 qed "InterI";
   564 qed "InterI";
   565 
   565 
   566 (*A "destruct" rule -- every X in C contains A as an element, but
   566 (*A "destruct" rule -- every X in C contains A as an element, but
   567   A:X can hold when X:C does not!  This rule is analogous to "spec". *)
   567   A:X can hold when X:C does not!  This rule is analogous to "spec". *)
   568 Goal "!!X. [| A : Inter(C);  X:C |] ==> A:X";
   568 Goal "[| A : Inter(C);  X:C |] ==> A:X";
   569 by Auto_tac;
   569 by Auto_tac;
   570 qed "InterD";
   570 qed "InterD";
   571 
   571 
   572 (*"Classical" elimination rule -- does not require proving X:C *)
   572 (*"Classical" elimination rule -- does not require proving X:C *)
   573 val major::prems = goalw Set.thy [Inter_def]
   573 val major::prems = goalw Set.thy [Inter_def]
   624 qed "image_subsetI";
   624 qed "image_subsetI";
   625 
   625 
   626 
   626 
   627 (*** Range of a function -- just a translation for image! ***)
   627 (*** Range of a function -- just a translation for image! ***)
   628 
   628 
   629 Goal "!!b. b=f(x) ==> b : range(f)";
   629 Goal "b=f(x) ==> b : range(f)";
   630 by (EVERY1 [etac image_eqI, rtac UNIV_I]);
   630 by (EVERY1 [etac image_eqI, rtac UNIV_I]);
   631 bind_thm ("range_eqI", UNIV_I RSN (2,image_eqI));
   631 bind_thm ("range_eqI", UNIV_I RSN (2,image_eqI));
   632 
   632 
   633 bind_thm ("rangeI", UNIV_I RS imageI);
   633 bind_thm ("rangeI", UNIV_I RS imageI);
   634 
   634