src/HOL/Isar_Examples/Cantor.thy
author wenzelm
Sat, 18 Jul 2015 20:53:05 +0200
changeset 60753 80ca4a065a48
parent 58882 6e2010ab8bd9
child 61541 846c72206207
permissions -rw-r--r--
tuned whitespace;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33026
8f35633c4922 modernized session Isar_Examples;
wenzelm
parents: 31758
diff changeset
     1
(*  Title:      HOL/Isar_Examples/Cantor.thy
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
     2
    Author:     Markus Wenzel, TU Muenchen
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
     3
*)
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
     4
58882
6e2010ab8bd9 modernized header;
wenzelm
parents: 58614
diff changeset
     5
section \<open>Cantor's Theorem\<close>
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
     6
31758
3edd5f813f01 observe standard theory naming conventions;
wenzelm
parents: 23373
diff changeset
     7
theory Cantor
3edd5f813f01 observe standard theory naming conventions;
wenzelm
parents: 23373
diff changeset
     8
imports Main
3edd5f813f01 observe standard theory naming conventions;
wenzelm
parents: 23373
diff changeset
     9
begin
7955
wenzelm
parents: 7874
diff changeset
    10
58614
7338eb25226c more cartouches;
wenzelm
parents: 55640
diff changeset
    11
text_raw \<open>\footnote{This is an Isar version of the final example of
7338eb25226c more cartouches;
wenzelm
parents: 55640
diff changeset
    12
  the Isabelle/HOL manual @{cite "isabelle-HOL"}.}\<close>
7819
6dd018b6cf3f tuned presentation;
wenzelm
parents: 7800
diff changeset
    13
58614
7338eb25226c more cartouches;
wenzelm
parents: 55640
diff changeset
    14
text \<open>Cantor's Theorem states that every set has more subsets than
37671
fa53d267dab3 misc tuning and modernization;
wenzelm
parents: 33026
diff changeset
    15
  it has elements.  It has become a favorite basic example in pure
12388
c845fec1ac94 simplified proof (no longer use swapped rules);
wenzelm
parents: 10007
diff changeset
    16
  higher-order logic since it is so easily expressed: \[\all{f::\alpha
c845fec1ac94 simplified proof (no longer use swapped rules);
wenzelm
parents: 10007
diff changeset
    17
  \To \alpha \To \idt{bool}} \ex{S::\alpha \To \idt{bool}}
c845fec1ac94 simplified proof (no longer use swapped rules);
wenzelm
parents: 10007
diff changeset
    18
  \all{x::\alpha} f \ap x \not= S\]
c845fec1ac94 simplified proof (no longer use swapped rules);
wenzelm
parents: 10007
diff changeset
    19
c845fec1ac94 simplified proof (no longer use swapped rules);
wenzelm
parents: 10007
diff changeset
    20
  Viewing types as sets, $\alpha \To \idt{bool}$ represents the
c845fec1ac94 simplified proof (no longer use swapped rules);
wenzelm
parents: 10007
diff changeset
    21
  powerset of $\alpha$.  This version of the theorem states that for
c845fec1ac94 simplified proof (no longer use swapped rules);
wenzelm
parents: 10007
diff changeset
    22
  every function from $\alpha$ to its powerset, some subset is outside
c845fec1ac94 simplified proof (no longer use swapped rules);
wenzelm
parents: 10007
diff changeset
    23
  its range.  The Isabelle/Isar proofs below uses HOL's set theory,
c845fec1ac94 simplified proof (no longer use swapped rules);
wenzelm
parents: 10007
diff changeset
    24
  with the type $\alpha \ap \idt{set}$ and the operator
58614
7338eb25226c more cartouches;
wenzelm
parents: 55640
diff changeset
    25
  $\idt{range}::(\alpha \To \beta) \To \beta \ap \idt{set}$.\<close>
6505
2863855a6902 elaborated;
wenzelm
parents: 6494
diff changeset
    26
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    27
theorem "\<exists>S. S \<notin> range (f :: 'a \<Rightarrow> 'a set)"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9474
diff changeset
    28
proof
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    29
  let ?S = "{x. x \<notin> f x}"
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    30
  show "?S \<notin> range f"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9474
diff changeset
    31
  proof
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    32
    assume "?S \<in> range f"
12388
c845fec1ac94 simplified proof (no longer use swapped rules);
wenzelm
parents: 10007
diff changeset
    33
    then obtain y where "?S = f y" ..
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 16417
diff changeset
    34
    then show False
12388
c845fec1ac94 simplified proof (no longer use swapped rules);
wenzelm
parents: 10007
diff changeset
    35
    proof (rule equalityCE)
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    36
      assume "y \<in> f y"
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    37
      assume "y \<in> ?S"
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    38
      then have "y \<notin> f y" ..
58614
7338eb25226c more cartouches;
wenzelm
parents: 55640
diff changeset
    39
      with \<open>y : f y\<close> show ?thesis by contradiction
12388
c845fec1ac94 simplified proof (no longer use swapped rules);
wenzelm
parents: 10007
diff changeset
    40
    next
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    41
      assume "y \<notin> ?S"
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    42
      assume "y \<notin> f y"
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    43
      then have "y \<in> ?S" ..
58614
7338eb25226c more cartouches;
wenzelm
parents: 55640
diff changeset
    44
      with \<open>y \<notin> ?S\<close> show ?thesis by contradiction
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9474
diff changeset
    45
    qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9474
diff changeset
    46
  qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9474
diff changeset
    47
qed
6494
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    48
58614
7338eb25226c more cartouches;
wenzelm
parents: 55640
diff changeset
    49
text \<open>How much creativity is required?  As it happens, Isabelle can
37671
fa53d267dab3 misc tuning and modernization;
wenzelm
parents: 33026
diff changeset
    50
  prove this theorem automatically using best-first search.
fa53d267dab3 misc tuning and modernization;
wenzelm
parents: 33026
diff changeset
    51
  Depth-first search would diverge, but best-first search successfully
fa53d267dab3 misc tuning and modernization;
wenzelm
parents: 33026
diff changeset
    52
  navigates through the large search space.  The context of Isabelle's
fa53d267dab3 misc tuning and modernization;
wenzelm
parents: 33026
diff changeset
    53
  classical prover contains rules for the relevant constructs of HOL's
58614
7338eb25226c more cartouches;
wenzelm
parents: 55640
diff changeset
    54
  set theory.\<close>
6505
2863855a6902 elaborated;
wenzelm
parents: 6494
diff changeset
    55
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    56
theorem "\<exists>S. S \<notin> range (f :: 'a \<Rightarrow> 'a set)"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9474
diff changeset
    57
  by best
6494
ab1442d2e4e1 detailed proofs;
wenzelm
parents: 6444
diff changeset
    58
58614
7338eb25226c more cartouches;
wenzelm
parents: 55640
diff changeset
    59
text \<open>While this establishes the same theorem internally, we do not
37671
fa53d267dab3 misc tuning and modernization;
wenzelm
parents: 33026
diff changeset
    60
  get any idea of how the proof actually works.  There is currently no
fa53d267dab3 misc tuning and modernization;
wenzelm
parents: 33026
diff changeset
    61
  way to transform internal system-level representations of Isabelle
12388
c845fec1ac94 simplified proof (no longer use swapped rules);
wenzelm
parents: 10007
diff changeset
    62
  proofs back into Isar text.  Writing intelligible proof documents
58614
7338eb25226c more cartouches;
wenzelm
parents: 55640
diff changeset
    63
  really is a creative process, after all.\<close>
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
    64
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9474
diff changeset
    65
end