src/HOL/Isar_Examples/First_Order_Logic.thy
author wenzelm
Sat, 26 Dec 2015 19:27:46 +0100
changeset 61935 6512e84cc9f5
parent 61758 src/FOL/ex/First_Order_Logic.thy@df6258b7e53f
child 63585 f4a308fdf664
permissions -rw-r--r--
clarified sessions;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61935
6512e84cc9f5 clarified sessions;
wenzelm
parents: 61758
diff changeset
     1
(*  Title:      HOL/Isar_Examples/First_Order_Logic.thy
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
     2
    Author:     Makarius
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
     3
*)
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
     4
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60769
diff changeset
     5
section \<open>A simple formulation of First-Order Logic\<close>
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
     6
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60769
diff changeset
     7
text \<open>
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
     8
  The subsequent theory development illustrates single-sorted intuitionistic
61935
6512e84cc9f5 clarified sessions;
wenzelm
parents: 61758
diff changeset
     9
  first-order logic with equality, formulated within the Pure framework.
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60769
diff changeset
    10
\<close>
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    11
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    12
theory First_Order_Logic
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    13
imports Pure
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    14
begin
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    15
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    16
subsection \<open>Abstract syntax\<close>
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    17
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    18
typedecl i
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    19
typedecl o
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    20
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    21
judgment Trueprop :: "o \<Rightarrow> prop"  ("_" 5)
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    22
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    23
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60769
diff changeset
    24
subsection \<open>Propositional logic\<close>
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    25
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    26
axiomatization false :: o  ("\<bottom>")
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    27
  where falseE [elim]: "\<bottom> \<Longrightarrow> A"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    28
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    29
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    30
axiomatization imp :: "o \<Rightarrow> o \<Rightarrow> o"  (infixr "\<longrightarrow>" 25)
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    31
  where impI [intro]: "(A \<Longrightarrow> B) \<Longrightarrow> A \<longrightarrow> B"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    32
    and mp [dest]: "A \<longrightarrow> B \<Longrightarrow> A \<Longrightarrow> B"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    33
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    34
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    35
axiomatization conj :: "o \<Rightarrow> o \<Rightarrow> o"  (infixr "\<and>" 35)
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    36
  where conjI [intro]: "A \<Longrightarrow> B \<Longrightarrow> A \<and> B"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    37
    and conjD1: "A \<and> B \<Longrightarrow> A"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    38
    and conjD2: "A \<and> B \<Longrightarrow> B"
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    39
21939
9b772ac66830 tuned specifications/proofs;
wenzelm
parents: 16417
diff changeset
    40
theorem conjE [elim]:
9b772ac66830 tuned specifications/proofs;
wenzelm
parents: 16417
diff changeset
    41
  assumes "A \<and> B"
9b772ac66830 tuned specifications/proofs;
wenzelm
parents: 16417
diff changeset
    42
  obtains A and B
9b772ac66830 tuned specifications/proofs;
wenzelm
parents: 16417
diff changeset
    43
proof
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    44
  from \<open>A \<and> B\<close> show A
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    45
    by (rule conjD1)
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    46
  from \<open>A \<and> B\<close> show B
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    47
    by (rule conjD2)
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    48
qed
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    49
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    50
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    51
axiomatization disj :: "o \<Rightarrow> o \<Rightarrow> o"  (infixr "\<or>" 30)
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    52
  where disjE [elim]: "A \<or> B \<Longrightarrow> (A \<Longrightarrow> C) \<Longrightarrow> (B \<Longrightarrow> C) \<Longrightarrow> C"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    53
    and disjI1 [intro]: "A \<Longrightarrow> A \<or> B"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    54
    and disjI2 [intro]: "B \<Longrightarrow> A \<or> B"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    55
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    56
60769
cf7f3465eaf1 tuned proofs;
wenzelm
parents: 58889
diff changeset
    57
definition true :: o  ("\<top>")
cf7f3465eaf1 tuned proofs;
wenzelm
parents: 58889
diff changeset
    58
  where "\<top> \<equiv> \<bottom> \<longrightarrow> \<bottom>"
21939
9b772ac66830 tuned specifications/proofs;
wenzelm
parents: 16417
diff changeset
    59
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    60
theorem trueI [intro]: \<top>
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    61
  unfolding true_def ..
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    62
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    63
60769
cf7f3465eaf1 tuned proofs;
wenzelm
parents: 58889
diff changeset
    64
definition not :: "o \<Rightarrow> o"  ("\<not> _" [40] 40)
cf7f3465eaf1 tuned proofs;
wenzelm
parents: 58889
diff changeset
    65
  where "\<not> A \<equiv> A \<longrightarrow> \<bottom>"
21939
9b772ac66830 tuned specifications/proofs;
wenzelm
parents: 16417
diff changeset
    66
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    67
theorem notI [intro]: "(A \<Longrightarrow> \<bottom>) \<Longrightarrow> \<not> A"
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    68
  unfolding not_def ..
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    69
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    70
theorem notE [elim]: "\<not> A \<Longrightarrow> A \<Longrightarrow> B"
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    71
  unfolding not_def
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    72
proof -
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    73
  assume "A \<longrightarrow> \<bottom>" and A
60769
cf7f3465eaf1 tuned proofs;
wenzelm
parents: 58889
diff changeset
    74
  then have \<bottom> ..
cf7f3465eaf1 tuned proofs;
wenzelm
parents: 58889
diff changeset
    75
  then show B ..
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    76
qed
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
    77
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    78
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    79
definition iff :: "o \<Rightarrow> o \<Rightarrow> o"  (infixr "\<longleftrightarrow>" 25)
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    80
  where "A \<longleftrightarrow> B \<equiv> (A \<longrightarrow> B) \<and> (B \<longrightarrow> A)"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    81
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    82
theorem iffI [intro]:
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    83
  assumes "A \<Longrightarrow> B"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    84
    and "B \<Longrightarrow> A"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    85
  shows "A \<longleftrightarrow> B"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    86
  unfolding iff_def
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    87
proof
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    88
  from \<open>A \<Longrightarrow> B\<close> show "A \<longrightarrow> B" ..
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    89
  from \<open>B \<Longrightarrow> A\<close> show "B \<longrightarrow> A" ..
12392
wenzelm
parents: 12369
diff changeset
    90
qed
wenzelm
parents: 12369
diff changeset
    91
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    92
theorem iff1 [elim]:
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    93
  assumes "A \<longleftrightarrow> B" and A
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    94
  shows B
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    95
proof -
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    96
  from \<open>A \<longleftrightarrow> B\<close> have "(A \<longrightarrow> B) \<and> (B \<longrightarrow> A)"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    97
    unfolding iff_def .
21939
9b772ac66830 tuned specifications/proofs;
wenzelm
parents: 16417
diff changeset
    98
  then have "A \<longrightarrow> B" ..
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
    99
  from this and \<open>A\<close> show B ..
12392
wenzelm
parents: 12369
diff changeset
   100
qed
wenzelm
parents: 12369
diff changeset
   101
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   102
theorem iff2 [elim]:
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   103
  assumes "A \<longleftrightarrow> B" and B
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   104
  shows A
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   105
proof -
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   106
  from \<open>A \<longleftrightarrow> B\<close> have "(A \<longrightarrow> B) \<and> (B \<longrightarrow> A)"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   107
    unfolding iff_def .
21939
9b772ac66830 tuned specifications/proofs;
wenzelm
parents: 16417
diff changeset
   108
  then have "B \<longrightarrow> A" ..
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   109
  from this and \<open>B\<close> show A ..
12392
wenzelm
parents: 12369
diff changeset
   110
qed
wenzelm
parents: 12369
diff changeset
   111
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   112
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60769
diff changeset
   113
subsection \<open>Equality\<close>
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   114
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   115
axiomatization equal :: "i \<Rightarrow> i \<Rightarrow> o"  (infixl "=" 50)
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   116
  where refl [intro]: "x = x"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   117
    and subst: "x = y \<Longrightarrow> P x \<Longrightarrow> P y"
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   118
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   119
theorem trans [trans]: "x = y \<Longrightarrow> y = z \<Longrightarrow> x = z"
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   120
  by (rule subst)
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   121
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   122
theorem sym [sym]: "x = y \<Longrightarrow> y = x"
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   123
proof -
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   124
  assume "x = y"
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   125
  from this and refl show "y = x"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   126
    by (rule subst)
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   127
qed
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   128
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   129
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 60769
diff changeset
   130
subsection \<open>Quantifiers\<close>
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   131
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   132
axiomatization All :: "(i \<Rightarrow> o) \<Rightarrow> o"  (binder "\<forall>" 10)
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   133
  where allI [intro]: "(\<And>x. P x) \<Longrightarrow> \<forall>x. P x"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   134
    and allD [dest]: "\<forall>x. P x \<Longrightarrow> P a"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   135
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   136
axiomatization Ex :: "(i \<Rightarrow> o) \<Rightarrow> o"  (binder "\<exists>" 10)
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   137
  where exI [intro]: "P a \<Longrightarrow> \<exists>x. P x"
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   138
    and exE [elim]: "\<exists>x. P x \<Longrightarrow> (\<And>x. P x \<Longrightarrow> C) \<Longrightarrow> C"
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   139
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   140
26958
ed3a58a9eae1 converted to regular application syntax;
wenzelm
parents: 21939
diff changeset
   141
lemma "(\<exists>x. P (f x)) \<longrightarrow> (\<exists>y. P y)"
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   142
proof
26958
ed3a58a9eae1 converted to regular application syntax;
wenzelm
parents: 21939
diff changeset
   143
  assume "\<exists>x. P (f x)"
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   144
  then obtain x where "P (f x)" ..
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   145
  then show "\<exists>y. P y" ..
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   146
qed
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   147
26958
ed3a58a9eae1 converted to regular application syntax;
wenzelm
parents: 21939
diff changeset
   148
lemma "(\<exists>x. \<forall>y. R x y) \<longrightarrow> (\<forall>y. \<exists>x. R x y)"
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   149
proof
26958
ed3a58a9eae1 converted to regular application syntax;
wenzelm
parents: 21939
diff changeset
   150
  assume "\<exists>x. \<forall>y. R x y"
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   151
  then obtain x where "\<forall>y. R x y" ..
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   152
  show "\<forall>y. \<exists>x. R x y"
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   153
  proof
61758
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   154
    fix y
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   155
    from \<open>\<forall>y. R x y\<close> have "R x y" ..
df6258b7e53f misc tuning and modernization;
wenzelm
parents: 60770
diff changeset
   156
    then show "\<exists>x. R x y" ..
12369
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   157
  qed
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   158
qed
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   159
ab207f9c1e1e added First_Order_Logic.thy;
wenzelm
parents:
diff changeset
   160
end