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