src/HOL/Isar_Examples/Puzzle.thy
author huffman
Tue, 02 Mar 2010 09:54:50 -0800
changeset 35512 d1ef88d7de5a
parent 34915 7894c7dab132
child 37671 fa53d267dab3
permissions -rw-r--r--
remove dead code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9941
diff changeset
     1
header {* An old chestnut *}
8020
2823ce1753a5 added Isar_examples/Puzzle.thy;
wenzelm
parents:
diff changeset
     2
31758
3edd5f813f01 observe standard theory naming conventions;
wenzelm
parents: 20503
diff changeset
     3
theory Puzzle
3edd5f813f01 observe standard theory naming conventions;
wenzelm
parents: 20503
diff changeset
     4
imports Main
3edd5f813f01 observe standard theory naming conventions;
wenzelm
parents: 20503
diff changeset
     5
begin
8020
2823ce1753a5 added Isar_examples/Puzzle.thy;
wenzelm
parents:
diff changeset
     6
2823ce1753a5 added Isar_examples/Puzzle.thy;
wenzelm
parents:
diff changeset
     7
text_raw {*
18193
54419506df9e tuned document;
wenzelm
parents: 18191
diff changeset
     8
  \footnote{A question from ``Bundeswettbewerb Mathematik''.  Original
54419506df9e tuned document;
wenzelm
parents: 18191
diff changeset
     9
  pen-and-paper proof due to Herbert Ehler; Isabelle tactic script by
54419506df9e tuned document;
wenzelm
parents: 18191
diff changeset
    10
  Tobias Nipkow.}
54419506df9e tuned document;
wenzelm
parents: 18191
diff changeset
    11
*}
8020
2823ce1753a5 added Isar_examples/Puzzle.thy;
wenzelm
parents:
diff changeset
    12
18193
54419506df9e tuned document;
wenzelm
parents: 18191
diff changeset
    13
text {*
54419506df9e tuned document;
wenzelm
parents: 18191
diff changeset
    14
  \textbf{Problem.}  Given some function $f\colon \Nat \to \Nat$ such
54419506df9e tuned document;
wenzelm
parents: 18191
diff changeset
    15
  that $f \ap (f \ap n) < f \ap (\idt{Suc} \ap n)$ for all $n$.
54419506df9e tuned document;
wenzelm
parents: 18191
diff changeset
    16
  Demonstrate that $f$ is the identity.
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9941
diff changeset
    17
*}
8020
2823ce1753a5 added Isar_examples/Puzzle.thy;
wenzelm
parents:
diff changeset
    18
18191
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    19
theorem
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    20
  assumes f_ax: "\<And>n. f (f n) < f (Suc n)"
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    21
  shows "f n = n"
10436
98c421dd5972 simplified induction;
wenzelm
parents: 10007
diff changeset
    22
proof (rule order_antisym)
18191
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    23
  {
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    24
    fix n show "n \<le> f n"
34915
7894c7dab132 Adapted to changes in induct method.
berghofe
parents: 33026
diff changeset
    25
    proof (induct "f n" arbitrary: n rule: less_induct)
7894c7dab132 Adapted to changes in induct method.
berghofe
parents: 33026
diff changeset
    26
      case less
18191
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    27
      show "n \<le> f n"
10436
98c421dd5972 simplified induction;
wenzelm
parents: 10007
diff changeset
    28
      proof (cases n)
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31758
diff changeset
    29
        case (Suc m)
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31758
diff changeset
    30
        from f_ax have "f (f m) < f n" by (simp only: Suc)
34915
7894c7dab132 Adapted to changes in induct method.
berghofe
parents: 33026
diff changeset
    31
        with less have "f m \<le> f (f m)" .
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31758
diff changeset
    32
        also from f_ax have "\<dots> < f n" by (simp only: Suc)
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31758
diff changeset
    33
        finally have "f m < f n" .
34915
7894c7dab132 Adapted to changes in induct method.
berghofe
parents: 33026
diff changeset
    34
        with less have "m \<le> f m" .
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31758
diff changeset
    35
        also note `\<dots> < f n`
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31758
diff changeset
    36
        finally have "m < f n" .
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31758
diff changeset
    37
        then have "n \<le> f n" by (simp only: Suc)
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31758
diff changeset
    38
        then show ?thesis .
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9941
diff changeset
    39
      next
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31758
diff changeset
    40
        case 0
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31758
diff changeset
    41
        then show ?thesis by simp
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9941
diff changeset
    42
      qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9941
diff changeset
    43
    qed
18191
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    44
  } note ge = this
8020
2823ce1753a5 added Isar_examples/Puzzle.thy;
wenzelm
parents:
diff changeset
    45
10436
98c421dd5972 simplified induction;
wenzelm
parents: 10007
diff changeset
    46
  {
18191
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    47
    fix m n :: nat
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    48
    assume "m \<le> n"
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    49
    then have "f m \<le> f n"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9941
diff changeset
    50
    proof (induct n)
18191
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    51
      case 0
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    52
      then have "m = 0" by simp
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    53
      then show ?case by simp
10436
98c421dd5972 simplified induction;
wenzelm
parents: 10007
diff changeset
    54
    next
18191
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    55
      case (Suc n)
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    56
      from Suc.prems show "f m \<le> f (Suc n)"
10436
98c421dd5972 simplified induction;
wenzelm
parents: 10007
diff changeset
    57
      proof (rule le_SucE)
18191
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    58
        assume "m \<le> n"
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    59
        with Suc.hyps have "f m \<le> f n" .
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    60
        also from ge f_ax have "\<dots> < f (Suc n)"
10436
98c421dd5972 simplified induction;
wenzelm
parents: 10007
diff changeset
    61
          by (rule le_less_trans)
98c421dd5972 simplified induction;
wenzelm
parents: 10007
diff changeset
    62
        finally show ?thesis by simp
98c421dd5972 simplified induction;
wenzelm
parents: 10007
diff changeset
    63
      next
98c421dd5972 simplified induction;
wenzelm
parents: 10007
diff changeset
    64
        assume "m = Suc n"
18191
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    65
        then show ?thesis by simp
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9941
diff changeset
    66
      qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9941
diff changeset
    67
    qed
10436
98c421dd5972 simplified induction;
wenzelm
parents: 10007
diff changeset
    68
  } note mono = this
8020
2823ce1753a5 added Isar_examples/Puzzle.thy;
wenzelm
parents:
diff changeset
    69
18191
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    70
  show "f n \<le> n"
10436
98c421dd5972 simplified induction;
wenzelm
parents: 10007
diff changeset
    71
  proof -
18191
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    72
    have "\<not> n < f n"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9941
diff changeset
    73
    proof
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9941
diff changeset
    74
      assume "n < f n"
18191
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    75
      then have "Suc n \<le> f n" by simp
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    76
      then have "f (Suc n) \<le> f (f n)" by (rule mono)
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    77
      also have "\<dots> < f (Suc n)" by (rule f_ax)
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    78
      finally have "\<dots> < \<dots>" . then show False ..
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9941
diff changeset
    79
    qed
18191
ef29685acef0 improved induction proof: local defs/fixes;
wenzelm
parents: 16417
diff changeset
    80
    then show ?thesis by simp
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9941
diff changeset
    81
  qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9941
diff changeset
    82
qed
8020
2823ce1753a5 added Isar_examples/Puzzle.thy;
wenzelm
parents:
diff changeset
    83
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9941
diff changeset
    84
end