src/FOL/ex/Natural_Numbers.thy
author nipkow
Tue, 05 Nov 2019 21:07:03 +0100
changeset 71044 cb504351d058
parent 69590 e65314985426
permissions -rw-r--r--
tuned
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11673
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
     1
(*  Title:      FOL/ex/Natural_Numbers.thy
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
     2
    Author:     Markus Wenzel, TU Munich
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
     3
*)
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
     4
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
     5
section \<open>Natural numbers\<close>
12371
wenzelm
parents: 11789
diff changeset
     6
31974
e81979a703a4 removed obsolete CVS Ids;
wenzelm
parents: 26720
diff changeset
     7
theory Natural_Numbers
e81979a703a4 removed obsolete CVS Ids;
wenzelm
parents: 26720
diff changeset
     8
imports FOL
e81979a703a4 removed obsolete CVS Ids;
wenzelm
parents: 26720
diff changeset
     9
begin
11673
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    10
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
    11
text \<open>
12371
wenzelm
parents: 11789
diff changeset
    12
  Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents: 11789
diff changeset
    13
  (Modernized version of Larry Paulson's theory "Nat".)  \medskip
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
    14
\<close>
12371
wenzelm
parents: 11789
diff changeset
    15
11673
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    16
typedecl nat
69590
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    17
instance nat :: \<open>term\<close> ..
11673
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    18
26720
8d1925ad0dac modernized specifications and proofs;
wenzelm
parents: 25989
diff changeset
    19
axiomatization
69590
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    20
  Zero :: \<open>nat\<close>    (\<open>0\<close>) and
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    21
  Suc :: \<open>nat => nat\<close> and
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    22
  rec :: \<open>[nat, 'a, [nat, 'a] => 'a] => 'a\<close>
26720
8d1925ad0dac modernized specifications and proofs;
wenzelm
parents: 25989
diff changeset
    23
where
11789
wenzelm
parents: 11726
diff changeset
    24
  induct [case_names 0 Suc, induct type: nat]:
69590
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    25
    \<open>P(0) ==> (!!x. P(x) ==> P(Suc(x))) ==> P(n)\<close> and
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    26
  Suc_inject: \<open>Suc(m) = Suc(n) ==> m = n\<close> and
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    27
  Suc_neq_0: \<open>Suc(m) = 0 ==> R\<close> and
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    28
  rec_0: \<open>rec(0, a, f) = a\<close> and
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    29
  rec_Suc: \<open>rec(Suc(m), a, f) = f(m, rec(m, a, f))\<close>
11673
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    30
69590
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    31
lemma Suc_n_not_n: \<open>Suc(k) \<noteq> k\<close>
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    32
proof (induct \<open>k\<close>)
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    33
  show \<open>Suc(0) \<noteq> 0\<close>
11673
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    34
  proof
69590
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    35
    assume \<open>Suc(0) = 0\<close>
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    36
    then show \<open>False\<close> by (rule Suc_neq_0)
11673
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    37
  qed
26720
8d1925ad0dac modernized specifications and proofs;
wenzelm
parents: 25989
diff changeset
    38
next
69590
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    39
  fix n assume hyp: \<open>Suc(n) \<noteq> n\<close>
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    40
  show \<open>Suc(Suc(n)) \<noteq> Suc(n)\<close>
11673
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    41
  proof
69590
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    42
    assume \<open>Suc(Suc(n)) = Suc(n)\<close>
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    43
    then have \<open>Suc(n) = n\<close> by (rule Suc_inject)
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    44
    with hyp show \<open>False\<close> by contradiction
11673
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    45
  qed
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    46
qed
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    47
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    48
69590
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    49
definition add :: \<open>nat => nat => nat\<close>    (infixl \<open>+\<close> 60)
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    50
  where \<open>m + n = rec(m, n, \<lambda>x y. Suc(y))\<close>
11673
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    51
69590
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    52
lemma add_0 [simp]: \<open>0 + n = n\<close>
26720
8d1925ad0dac modernized specifications and proofs;
wenzelm
parents: 25989
diff changeset
    53
  unfolding add_def by (rule rec_0)
11673
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    54
69590
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    55
lemma add_Suc [simp]: \<open>Suc(m) + n = Suc(m + n)\<close>
26720
8d1925ad0dac modernized specifications and proofs;
wenzelm
parents: 25989
diff changeset
    56
  unfolding add_def by (rule rec_Suc)
11673
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    57
69590
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    58
lemma add_assoc: \<open>(k + m) + n = k + (m + n)\<close>
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    59
  by (induct \<open>k\<close>) simp_all
11673
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    60
69590
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    61
lemma add_0_right: \<open>m + 0 = m\<close>
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    62
  by (induct \<open>m\<close>) simp_all
11673
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    63
69590
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    64
lemma add_Suc_right: \<open>m + Suc(n) = Suc(m + n)\<close>
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    65
  by (induct \<open>m\<close>) simp_all
11673
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    66
26720
8d1925ad0dac modernized specifications and proofs;
wenzelm
parents: 25989
diff changeset
    67
lemma
69590
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    68
  assumes \<open>!!n. f(Suc(n)) = Suc(f(n))\<close>
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    69
  shows \<open>f(i + j) = i + f(j)\<close>
e65314985426 isabelle update_inner_syntax_cartouches;
wenzelm
parents: 69587
diff changeset
    70
  using assms by (induct \<open>i\<close>) simp_all
11673
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    71
79e5536af6c4 Theory of the natural numbers: Peano's axioms, primitive recursion.
wenzelm
parents:
diff changeset
    72
end