src/HOL/Isar_examples/Cantor.thy
author wenzelm
Thu, 14 Oct 1999 01:07:24 +0200
changeset 7860 7819547df4d8
parent 7833 f5288e4b95d1
child 7869 c007f801cd59
permissions -rw-r--r--
improved presentation;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Isar_examples/Cantor.thy
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
     4
*)
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
     5
7800
8ee919e42174 improved presentation;
wenzelm
parents: 7748
diff changeset
     6
header {* Cantor's Theorem *};
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
     7
7833
f5288e4b95d1 improved presentation;
wenzelm
parents: 7819
diff changeset
     8
theory Cantor = Main:;verbatim {* \footnote{This is an Isar version of
f5288e4b95d1 improved presentation;
wenzelm
parents: 7819
diff changeset
     9
 the final example of the Isabelle/HOL manual \cite{isabelle-HOL}.}
7819
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
    10
*};
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
    11
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
    12
text {*
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
    13
 Cantor's Theorem states that every set has more subsets than it has
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
    14
 elements.  It has become a favorite basic example in pure
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
    15
 higher-order logic since it is so easily expressed: \[\all{f::\alpha
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
    16
 \To \alpha \To \idt{bool}} \ex{S::\alpha \To \idt{bool}}
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
    17
 \all{x::\alpha}. f \ap x \not= S\]
7748
5b9c45b21782 improved presentation;
wenzelm
parents: 7480
diff changeset
    18
  
7819
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
    19
 Viewing types as sets, $\alpha \To \idt{bool}$ represents the
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
    20
 powerset of $\alpha$.  This version of the theorem states that for
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
    21
 every function from $\alpha$ to its powerset, some subset is outside
7860
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    22
 its range.  The Isabelle/Isar proofs below uses HOL's set theory,
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    23
 with the type $\alpha \ap \idt{set}$ and the operator $\idt{range}$.
7748
5b9c45b21782 improved presentation;
wenzelm
parents: 7480
diff changeset
    24
  
7860
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    25
 \bigskip We first consider a slightly awkward version of the proof,
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    26
 with the reasoning expressed quite naively.
6744
9727e83f0578 changed {| |} verbatim syntax to {* *};
wenzelm
parents: 6517
diff changeset
    27
*};
6505
2863855a6902 elaborated;
wenzelm
parents: 6494
diff changeset
    28
6494
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    29
theorem "EX S. S ~: range(f :: 'a => 'a set)";
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    30
proof;
7480
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 6746
diff changeset
    31
  let ?S = "{x. x ~: f x}";
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 6746
diff changeset
    32
  show "?S ~: range f";
6494
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    33
  proof;
7480
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 6746
diff changeset
    34
    assume "?S : range f";
7860
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    35
    thus False;
6494
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    36
    proof;
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    37
      fix y; 
7480
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 6746
diff changeset
    38
      assume "?S = f y";
7860
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    39
      thus ?thesis;
6494
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    40
      proof (rule equalityCE);
7860
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    41
        assume in_S: "y : ?S";
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    42
        assume in_fy: "y : f y";
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    43
        from in_S; have notin_fy: "y ~: f y"; ..;
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    44
        from notin_fy in_fy; show ?thesis; by contradiction;
6494
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    45
      next;
7860
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    46
        assume notin_S: "y ~: ?S";
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    47
        assume notin_fy: "y ~: f y";
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    48
        from notin_S; have in_fy: "y : f y"; ..;
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    49
        from notin_fy in_fy; show ?thesis; by contradiction;
6494
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    50
      qed;
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    51
    qed;
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    52
  qed;
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    53
qed;
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    54
6744
9727e83f0578 changed {| |} verbatim syntax to {* *};
wenzelm
parents: 6517
diff changeset
    55
text {*
7819
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
    56
 The following version of the proof essentially does the same
7860
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    57
 reasoning, only that it is expressed more neatly.  In particular, we
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    58
 change the order of assumptions introduced in the two cases of rule
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    59
 \name{equalityCE}, streamlining the flow of intermediate facts and
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    60
 avoiding explicit naming.\footnote{In general, neither the order of
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    61
 assumptions as introduced \isacommand{assume}, nor the order of goals
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    62
 as solved by \isacommand{show} matters.  The basic logical structure
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    63
 has to be left intact, though.  In particular, assumptions
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    64
 ``belonging'' to some goal have to be introduced \emph{before} its
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    65
 corresponding \isacommand{show}.}
6744
9727e83f0578 changed {| |} verbatim syntax to {* *};
wenzelm
parents: 6517
diff changeset
    66
*};
6494
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    67
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    68
theorem "EX S. S ~: range(f :: 'a => 'a set)";
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    69
proof;
7480
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 6746
diff changeset
    70
  let ?S = "{x. x ~: f x}";
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 6746
diff changeset
    71
  show "?S ~: range f";
6494
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    72
  proof;
7480
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 6746
diff changeset
    73
    assume "?S : range f";
6505
2863855a6902 elaborated;
wenzelm
parents: 6494
diff changeset
    74
    thus False;
6494
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    75
    proof;
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    76
      fix y; 
7480
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 6746
diff changeset
    77
      assume "?S = f y";
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 6746
diff changeset
    78
      thus ?thesis;
6494
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    79
      proof (rule equalityCE);
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    80
        assume "y : f y";
7480
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 6746
diff changeset
    81
        assume "y : ?S"; hence "y ~: f y"; ..;
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 6746
diff changeset
    82
        thus ?thesis; by contradiction;
6494
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    83
      next;
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    84
        assume "y ~: f y";
7480
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 6746
diff changeset
    85
        assume "y ~: ?S"; hence "y : f y"; ..;
0a0e0dbe1269 replaced ?? by ?;
wenzelm
parents: 6746
diff changeset
    86
        thus ?thesis; by contradiction;
6494
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    87
      qed;
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    88
    qed;
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    89
  qed;
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    90
qed;
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    91
6744
9727e83f0578 changed {| |} verbatim syntax to {* *};
wenzelm
parents: 6517
diff changeset
    92
text {*
7819
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
    93
 How much creativity is required?  As it happens, Isabelle can prove
7860
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    94
 this theorem automatically.  The default context of the classical
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    95
 proof tools contains rules for most of the constructs of HOL's set
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    96
 theory.  We must augment it with \name{equalityCE} to break up set
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    97
 equalities, and then apply best-first search.  Depth-first search
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    98
 would diverge, but best-first search successfully navigates through
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
    99
 the large search space.
6744
9727e83f0578 changed {| |} verbatim syntax to {* *};
wenzelm
parents: 6517
diff changeset
   100
*};
6505
2863855a6902 elaborated;
wenzelm
parents: 6494
diff changeset
   101
6494
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
   102
theorem "EX S. S ~: range(f :: 'a => 'a set)";
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
   103
  by (best elim: equalityCE);
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
   104
6744
9727e83f0578 changed {| |} verbatim syntax to {* *};
wenzelm
parents: 6517
diff changeset
   105
text {*
7819
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
   106
 While this establishes the same theorem internally, we do not get any
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
   107
 idea of how the proof actually works.  There is currently no way to
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
   108
 transform internal system-level representations of Isabelle proofs
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
   109
 back into Isar documents.  Writing proof documents really is a
7860
7819547df4d8 improved presentation;
wenzelm
parents: 7833
diff changeset
   110
 creative process, after all.
6744
9727e83f0578 changed {| |} verbatim syntax to {* *};
wenzelm
parents: 6517
diff changeset
   111
*};
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
   112
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
   113
end;