| 
12369
 | 
     1  | 
(*  Title:      FOL/ex/First_Order_Logic.thy
  | 
| 
 | 
     2  | 
    Author:     Markus Wenzel, TU Munich
  | 
| 
 | 
     3  | 
*)
  | 
| 
 | 
     4  | 
  | 
| 
 | 
     5  | 
header {* A simple formulation of First-Order Logic *}
 | 
| 
 | 
     6  | 
  | 
| 
16417
 | 
     7  | 
theory First_Order_Logic imports Pure begin
  | 
| 
12369
 | 
     8  | 
  | 
| 
 | 
     9  | 
text {*
 | 
| 
 | 
    10  | 
  The subsequent theory development illustrates single-sorted
  | 
| 
 | 
    11  | 
  intuitionistic first-order logic with equality, formulated within
  | 
| 
 | 
    12  | 
  the Pure framework.  Actually this is not an example of
  | 
| 
 | 
    13  | 
  Isabelle/FOL, but of Isabelle/Pure.
  | 
| 
 | 
    14  | 
*}
  | 
| 
 | 
    15  | 
  | 
| 
 | 
    16  | 
subsection {* Syntax *}
 | 
| 
 | 
    17  | 
  | 
| 
 | 
    18  | 
typedecl i
  | 
| 
 | 
    19  | 
typedecl o
  | 
| 
 | 
    20  | 
  | 
| 
 | 
    21  | 
judgment
  | 
| 
 | 
    22  | 
  Trueprop :: "o \<Rightarrow> prop"    ("_" 5)
 | 
| 
 | 
    23  | 
  | 
| 
 | 
    24  | 
  | 
| 
 | 
    25  | 
subsection {* Propositional logic *}
 | 
| 
 | 
    26  | 
  | 
| 
21939
 | 
    27  | 
axiomatization
  | 
| 
 | 
    28  | 
  false :: o  ("\<bottom>") and
 | 
| 
 | 
    29  | 
  imp :: "o \<Rightarrow> o \<Rightarrow> o"  (infixr "\<longrightarrow>" 25) and
  | 
| 
 | 
    30  | 
  conj :: "o \<Rightarrow> o \<Rightarrow> o"  (infixr "\<and>" 35) and
  | 
| 
 | 
    31  | 
  disj :: "o \<Rightarrow> o \<Rightarrow> o"  (infixr "\<or>" 30)
  | 
| 
 | 
    32  | 
where
  | 
| 
 | 
    33  | 
  falseE [elim]: "\<bottom> \<Longrightarrow> A" and
  | 
| 
12369
 | 
    34  | 
  | 
| 
21939
 | 
    35  | 
  impI [intro]: "(A \<Longrightarrow> B) \<Longrightarrow> A \<longrightarrow> B" and
  | 
| 
 | 
    36  | 
  mp [dest]: "A \<longrightarrow> B \<Longrightarrow> A \<Longrightarrow> B" and
  | 
| 
12369
 | 
    37  | 
  | 
| 
21939
 | 
    38  | 
  conjI [intro]: "A \<Longrightarrow> B \<Longrightarrow> A \<and> B" and
  | 
| 
 | 
    39  | 
  conjD1: "A \<and> B \<Longrightarrow> A" and
  | 
| 
 | 
    40  | 
  conjD2: "A \<and> B \<Longrightarrow> B" and
  | 
| 
12369
 | 
    41  | 
  | 
| 
21939
 | 
    42  | 
  disjE [elim]: "A \<or> B \<Longrightarrow> (A \<Longrightarrow> C) \<Longrightarrow> (B \<Longrightarrow> C) \<Longrightarrow> C" and
  | 
| 
 | 
    43  | 
  disjI1 [intro]: "A \<Longrightarrow> A \<or> B" and
  | 
| 
12369
 | 
    44  | 
  disjI2 [intro]: "B \<Longrightarrow> A \<or> B"
  | 
| 
 | 
    45  | 
  | 
| 
21939
 | 
    46  | 
theorem conjE [elim]:
  | 
| 
 | 
    47  | 
  assumes "A \<and> B"
  | 
| 
 | 
    48  | 
  obtains A and B
  | 
| 
 | 
    49  | 
proof
  | 
| 
 | 
    50  | 
  from `A \<and> B` show A by (rule conjD1)
  | 
| 
 | 
    51  | 
  from `A \<and> B` show B by (rule conjD2)
  | 
| 
12369
 | 
    52  | 
qed
  | 
| 
 | 
    53  | 
  | 
| 
21939
 | 
    54  | 
definition
  | 
| 
 | 
    55  | 
  true :: o  ("\<top>") where
 | 
| 
12369
 | 
    56  | 
  "\<top> \<equiv> \<bottom> \<longrightarrow> \<bottom>"
  | 
| 
21939
 | 
    57  | 
  | 
| 
 | 
    58  | 
definition
  | 
| 
 | 
    59  | 
  not :: "o \<Rightarrow> o"  ("\<not> _" [40] 40) where
 | 
| 
12369
 | 
    60  | 
  "\<not> A \<equiv> A \<longrightarrow> \<bottom>"
  | 
| 
21939
 | 
    61  | 
  | 
| 
 | 
    62  | 
definition
  | 
| 
 | 
    63  | 
  iff :: "o \<Rightarrow> o \<Rightarrow> o"  (infixr "\<longleftrightarrow>" 25) where
  | 
| 
12392
 | 
    64  | 
  "A \<longleftrightarrow> B \<equiv> (A \<longrightarrow> B) \<and> (B \<longrightarrow> A)"
  | 
| 
 | 
    65  | 
  | 
| 
12369
 | 
    66  | 
  | 
| 
 | 
    67  | 
theorem trueI [intro]: \<top>
  | 
| 
 | 
    68  | 
proof (unfold true_def)
  | 
| 
 | 
    69  | 
  show "\<bottom> \<longrightarrow> \<bottom>" ..
  | 
| 
 | 
    70  | 
qed
  | 
| 
 | 
    71  | 
  | 
| 
 | 
    72  | 
theorem notI [intro]: "(A \<Longrightarrow> \<bottom>) \<Longrightarrow> \<not> A"
  | 
| 
 | 
    73  | 
proof (unfold not_def)
  | 
| 
 | 
    74  | 
  assume "A \<Longrightarrow> \<bottom>"
  | 
| 
21939
 | 
    75  | 
  then show "A \<longrightarrow> \<bottom>" ..
  | 
| 
12369
 | 
    76  | 
qed
  | 
| 
 | 
    77  | 
  | 
| 
 | 
    78  | 
theorem notE [elim]: "\<not> A \<Longrightarrow> A \<Longrightarrow> B"
  | 
| 
 | 
    79  | 
proof (unfold not_def)
  | 
| 
 | 
    80  | 
  assume "A \<longrightarrow> \<bottom>" and A
  | 
| 
21939
 | 
    81  | 
  then have \<bottom> .. then show B ..
  | 
| 
12369
 | 
    82  | 
qed
  | 
| 
 | 
    83  | 
  | 
| 
12392
 | 
    84  | 
theorem iffI [intro]: "(A \<Longrightarrow> B) \<Longrightarrow> (B \<Longrightarrow> A) \<Longrightarrow> A \<longleftrightarrow> B"
  | 
| 
 | 
    85  | 
proof (unfold iff_def)
  | 
| 
21939
 | 
    86  | 
  assume "A \<Longrightarrow> B" then have "A \<longrightarrow> B" ..
  | 
| 
 | 
    87  | 
  moreover assume "B \<Longrightarrow> A" then have "B \<longrightarrow> A" ..
  | 
| 
12392
 | 
    88  | 
  ultimately show "(A \<longrightarrow> B) \<and> (B \<longrightarrow> A)" ..
  | 
| 
 | 
    89  | 
qed
  | 
| 
 | 
    90  | 
  | 
| 
 | 
    91  | 
theorem iff1 [elim]: "A \<longleftrightarrow> B \<Longrightarrow> A \<Longrightarrow> B"
  | 
| 
 | 
    92  | 
proof (unfold iff_def)
  | 
| 
 | 
    93  | 
  assume "(A \<longrightarrow> B) \<and> (B \<longrightarrow> A)"
  | 
| 
21939
 | 
    94  | 
  then have "A \<longrightarrow> B" ..
  | 
| 
 | 
    95  | 
  then show "A \<Longrightarrow> B" ..
  | 
| 
12392
 | 
    96  | 
qed
  | 
| 
 | 
    97  | 
  | 
| 
 | 
    98  | 
theorem iff2 [elim]: "A \<longleftrightarrow> B \<Longrightarrow> B \<Longrightarrow> A"
  | 
| 
 | 
    99  | 
proof (unfold iff_def)
  | 
| 
 | 
   100  | 
  assume "(A \<longrightarrow> B) \<and> (B \<longrightarrow> A)"
  | 
| 
21939
 | 
   101  | 
  then have "B \<longrightarrow> A" ..
  | 
| 
 | 
   102  | 
  then show "B \<Longrightarrow> A" ..
  | 
| 
12392
 | 
   103  | 
qed
  | 
| 
 | 
   104  | 
  | 
| 
12369
 | 
   105  | 
  | 
| 
 | 
   106  | 
subsection {* Equality *}
 | 
| 
 | 
   107  | 
  | 
| 
21939
 | 
   108  | 
axiomatization
  | 
| 
 | 
   109  | 
  equal :: "i \<Rightarrow> i \<Rightarrow> o"  (infixl "=" 50)
  | 
| 
 | 
   110  | 
where
  | 
| 
 | 
   111  | 
  refl [intro]: "x = x" and
  | 
| 
26958
 | 
   112  | 
  subst: "x = y \<Longrightarrow> P x \<Longrightarrow> P y"
  | 
| 
12369
 | 
   113  | 
  | 
| 
 | 
   114  | 
theorem trans [trans]: "x = y \<Longrightarrow> y = z \<Longrightarrow> x = z"
  | 
| 
 | 
   115  | 
  by (rule subst)
  | 
| 
 | 
   116  | 
  | 
| 
 | 
   117  | 
theorem sym [sym]: "x = y \<Longrightarrow> y = x"
  | 
| 
 | 
   118  | 
proof -
  | 
| 
 | 
   119  | 
  assume "x = y"
  | 
| 
 | 
   120  | 
  from this and refl show "y = x" by (rule subst)
  | 
| 
 | 
   121  | 
qed
  | 
| 
 | 
   122  | 
  | 
| 
 | 
   123  | 
  | 
| 
 | 
   124  | 
subsection {* Quantifiers *}
 | 
| 
 | 
   125  | 
  | 
| 
21939
 | 
   126  | 
axiomatization
  | 
| 
 | 
   127  | 
  All :: "(i \<Rightarrow> o) \<Rightarrow> o"  (binder "\<forall>" 10) and
  | 
| 
 | 
   128  | 
  Ex :: "(i \<Rightarrow> o) \<Rightarrow> o"  (binder "\<exists>" 10)
  | 
| 
 | 
   129  | 
where
  | 
| 
26958
 | 
   130  | 
  allI [intro]: "(\<And>x. P x) \<Longrightarrow> \<forall>x. P x" and
  | 
| 
 | 
   131  | 
  allD [dest]: "\<forall>x. P x \<Longrightarrow> P a" and
  | 
| 
 | 
   132  | 
  exI [intro]: "P a \<Longrightarrow> \<exists>x. P x" and
  | 
| 
 | 
   133  | 
  exE [elim]: "\<exists>x. P x \<Longrightarrow> (\<And>x. P x \<Longrightarrow> C) \<Longrightarrow> C"
  | 
| 
12369
 | 
   134  | 
  | 
| 
 | 
   135  | 
  | 
| 
26958
 | 
   136  | 
lemma "(\<exists>x. P (f x)) \<longrightarrow> (\<exists>y. P y)"
  | 
| 
12369
 | 
   137  | 
proof
  | 
| 
26958
 | 
   138  | 
  assume "\<exists>x. P (f x)"
  | 
| 
 | 
   139  | 
  then show "\<exists>y. P y"
  | 
| 
12369
 | 
   140  | 
  proof
  | 
| 
26958
 | 
   141  | 
    fix x assume "P (f x)"
  | 
| 
21939
 | 
   142  | 
    then show ?thesis ..
  | 
| 
12369
 | 
   143  | 
  qed
  | 
| 
 | 
   144  | 
qed
  | 
| 
 | 
   145  | 
  | 
| 
26958
 | 
   146  | 
lemma "(\<exists>x. \<forall>y. R x y) \<longrightarrow> (\<forall>y. \<exists>x. R x y)"
  | 
| 
12369
 | 
   147  | 
proof
  | 
| 
26958
 | 
   148  | 
  assume "\<exists>x. \<forall>y. R x y"
  | 
| 
 | 
   149  | 
  then show "\<forall>y. \<exists>x. R x y"
  | 
| 
12369
 | 
   150  | 
  proof
  | 
| 
26958
 | 
   151  | 
    fix x assume a: "\<forall>y. R x y"
  | 
| 
12369
 | 
   152  | 
    show ?thesis
  | 
| 
 | 
   153  | 
    proof
  | 
| 
26958
 | 
   154  | 
      fix y from a have "R x y" ..
  | 
| 
 | 
   155  | 
      then show "\<exists>x. R x y" ..
  | 
| 
12369
 | 
   156  | 
    qed
  | 
| 
 | 
   157  | 
  qed
  | 
| 
 | 
   158  | 
qed
  | 
| 
 | 
   159  | 
  | 
| 
 | 
   160  | 
end
  |