* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download 3.1 Syntax - International Center for Computational Logic
Functional decomposition wikipedia , lookup
Positional notation wikipedia , lookup
List of first-order theories wikipedia , lookup
Big O notation wikipedia , lookup
Abuse of notation wikipedia , lookup
Large numbers wikipedia , lookup
Peano axioms wikipedia , lookup
Hyperreal number wikipedia , lookup
Quantum logic wikipedia , lookup
Proofs of Fermat's little theorem wikipedia , lookup
History of the function concept wikipedia , lookup
Laws of Form wikipedia , lookup
67 3.1. SYNTAX 3.1 Syntax 3.1.1 Formulas Just like any natural language, a formal language is based on an alphabet from which its words and sentences can be formed. Definition 3.1 An alphabet Σ consists of a finite or countably infinite set. The elements of this set are called symbols. Without loss of generality we assume that Λ !∈ Σ . Examples for alphabets are Σ = {1, 2}, Σ = {pi | i ∈ N}, Σ = {pi | i ∈ N} ∪ {¬, ∧, ∨, →, ←, (, )} or the alphabet of the German language. In some applications alphabets are restricted to consist of finite and non-empty sets. We will see later that we need countably infinite sets. If an alphabet is empty, then one usually cannot base many applications on it. However, from the viewpoint of logic there is no need to require non-empty alphabets. We can form words over alphabets. Informally speaking, words are just finite sequences of elements from an alphabet. They are formally defined as follows: Definition 3.2 Let Σ be an alphabet. The set of words (or strings) over Σ is denoted by Σ∗ and is defined as the smallest set satisfying the following conditions: 1. Λ ∈ Σ∗ . 2. If w ∈ Σ∗ and a ∈ Σ , then aw ∈ Σ∗ . Λ is called empty word or empty string. For Σ = {1, 2} we obtain the set Σ∗ = {Λ, 1Λ, 2Λ, 11Λ, 12Λ, 21Λ, 22Λ, 111Λ, . . . }. Because Λ denotes the empty word, the symbol Λ is often omitted when writing non-empty words and we obain Σ∗ = {Λ, 1, 2, 11, 12, 21, 22, 111, . . . }. Strictly speaking, we have to show that a smallest set satisfying the two conditions in Definition 3.2 exists. Thereby sets are compared with respect to the subset-relation. A set satisfying the two conditions in Definition 3.2 is the 68 CHAPTER 3. PROPOSITIONAL LOGIC smallest set, if there is no proper subset satisfying the the conditions. Obviously, there are sets satisfying the conditions. The intersection of two sets satisfying the conditions satisfies the conditions again. Hence, the smallest set is the intersection of all sets satisfying the two conditions in Definition 3.2. Let us consider the set Σ = {1, 2} as example again. Σ∗ as specified above meets both conditions in Definition 3.2. This holds also for the set Σ∗∗ = {Λ, 1, 2, !, 11, 12, 1!, 21, 22, 2!, 111, . . . }. Here, an additional word ! and all words necessary to satisfy the second condition in Definition 3.2 were added to Σ∗ . We find Σ∗ ⊂ Σ∗∗ . Hence, Σ∗∗ is not the smallest set satisfying the conditions in Definition 3.2. Now, let us turn to the alphabet of propositional logic. So-called propositional variables denote simple statements like for example “the cow is violet” or “the rooster crows on the dung”, where the internal structure of such a statement is not to be analyzed further at the moment. Simple propositions can be combined to more complex propositions using connectives. Such connectives correspond to, for instance, negation, conjunction, disjunction, implication, or equivalence of one or more propositions. Some examples are: • “the cow is not violet” (negation), • “the cow is violet and the rooster crows on the dung” (disjunction), • “the cow is violet or the rooster crows on the dung” (disjunction), • “if the cow is violet then the rooster crows on the dung” (implication), • “the cow is violet if and only if the rooster crows on the dung” (equivalence). Connectives are denoted by ◦/n , where ◦ is the connective itself, and n is a natural number indicating the arity of the connective. Besides that, there are the parantheses as special characters. Definition 3.3 An alphabet of propositional logic consists of • a (countably) infinite set R = {p1 , p2 , . . .} of propositional variables, • the set {¬/1, ∧/2, ∨/2, → /2, ↔ /2} of connectives, and • the special characters “(” and “)”. For simplicity, propositional variables are often denoted by p, q, . . . instead of p1 , p2 , . . .. Likewise, indices are sometimes omitted. Propositional letters are often called nullary relation symbols in the literature. Different alphabets of 3.1. SYNTAX 69 propositional logic differ in R . By abuse of notation, alphabets of propositional logic are often denoted by R . We can now build words over the alphabet according to Definition ??. A language over an alphabet Σ does usually not contain all words occurring in Σ∗ . For example, in English the words “sleep” or “run” are allowed, whereas the woods “leesp” or “urn” are not (although they are sometimes used in cartoons or advertisements). A language over an alphabet Σ is typically a subset of Σ∗ . This subset is formed according to certain rules. In English, the words are explicitely mentioned in a dictionary. In addition, there are rules specifying when an ending like “ing” can be added to a word like “sleep” to obtain the new wword “sleeping”. Similar rules exist specifying sentences. The same holds for the language of propositional logic, where the well-formed words are usually called formulas. Definition 3.4 A propositional atomic formula, briefly called atom, is a propositional variable. Definition 3.5 The set of propositional formulas is the smallest set L(R) of strings over an alphabet of propositional logic with propositional variables R satisfying the following properties: 1. If F is an atomic formula, then F ∈ L(R). 2. If F ∈ L(R) , then ¬F ∈ L(R). 3. If ◦ is a binary connective and F, G ∈ L(R) , then (F ◦ G) ∈ L(R). Examples for formulas are p1 , ¬p2 , and ¬((p1 → p2 ) ∨ p1 ). On the other hand, p1 p2 , p1 ∧ p2 , and (¬p1 ) are no formulas, although they are strings over the alphabet R of propositional logic (see also Exercise 3.1). We should again show that there is a smallest set satisfying the three conditions mentioned in Definition 3.5. Obviously, there are sets satisfying all the conditions. An example is the set of all strings over the alphabet of propositional logic. Obviously, the intersection of two sets satsfying these conditions satisfies the conditions as well. The smallest set is the intersection of all sets satisfying the conditions. As an example consider the following set of formulas: {p1 , p2 , . . . , !, ¬p1 , ¬p2 , . . . , ¬!, (p1 ∧ p1 ), (p1 ∧ p2 ), . . . , (p1 ∧ !), . . .}. This set satisfies the three conditions in Definition 3.5, but it is not minimal because it contains the strings ! , ¬! , (p1 ∧ !) etc. In the following, A (possibly indexed) denotes an atom and F , G and H (possibly indexed) denote propositional formulas, if not stated otherwise. Definitions 3.3, 3.4 and 3.5 may look a bit strange on first sight. On second sight, however, the reader should realize that he or she is used to similarly defined notions. For example, consider arithmetic expressions. They are defined 70 CHAPTER 3. PROPOSITIONAL LOGIC over an alphabet which may contain the rational numbers Q , the operators +/2, −/2, ÷/2 and ×/2 as well as the special charaters “(“ and “)”. Over such an alphabet we can define the arithmetic expressions as the smallest set satisfying the following conditions: 1. If T is a rational number, then T is an arithmetic expression. 2. If ◦/2 is an operator and T1 , T2 are arithmetic expressions, then (T1 ◦ T2 ) is also an arithmetic expression. 3 Hence, we obtain the arithmetic expressions like 19 3 , (3 + 5) or ( 2 ÷ (3 × 17)) . Comparing this definition with Definitions 3.3, 3.4 and 3.5 we find that rational numbers correspond to propositional variables or atoms, operators correspond to connectives and arithmetic expressions to formulas. One should observe that even in arithmetics one can find unary operators like the factorial or the square. Another example is the set of natural numbers. It is based on an alphabet consisting of the symbol 0 , the unary operator s/1 and the special charaters “(“ and “)”. The set of natural numbers is the smallest set satisfying the following conditions: 1. 0 is a natural number. 2. If N is a natural number, so is s(N ) . We thus obtain natural numbers like 0, s(0), s(s(0)) etc. As a final example we recall the set of lists as defined in Prolog (see Section 2.4.1. They were defined according to the principle discussed in this section. For example, the strings [ ] , .(1, [ ]) and .([ ], [ ]) are strings. 3.1.2 Induction and Recursion Let us return to the set of propositional logic. This is a set of structured objects over the alphabet of propositional logic. To prove properties1 of formulas or to define functions over formulas, we need techniques known as structural induction and structural recursion, respectively. Theorem 3.6 Principle of structural induction: Every propositional formula has a property E , if the following conditions are met: 1. Induction base: Every atom has property E. 1 We will see later that properties are usually predicate logic formulas with a freely occurring variable. 3.1. SYNTAX 71 2. Induction steps: If F has property E , then ¬F has property E as well. If ◦/2 is a connective, and F and G have property E , then (F ◦ G) has property E as well. Proof Let E be the set of all propositional formulas that have property E. According to the induction base and the induction steps, E satisfies the three properties of Definition 3.5. Because the set L(R) of propositional formulas is the smallest set satisfying these conditions, L(R) ⊆ E holds. Because E ⊆ L(R) , we have E = L(R). " Let E , for example, denote the property “the number of opening parentheses occurring in a propositional formula is identical to the number of closing parentheses occurring in that formula.” To show that all formulas have this property, it suffices to prove the induction base and the induction steps. An application of Theorem 3.6 then yields the desired result. The induction base follows immediately from the fact that there are no parentheses at all in atoms. In the first induction step, we assume that E holds for the formula F . Because parenthesis occurs in ¬F if and only if they occur in F , E holds for ¬F as well. In the second induction step, we assume that E holds for F and G. Let i be the number of opening and closing parentheses in F and j the number of opening and closing parentheses in G. Then there are exactly i + j + 1 opening and closing parentheses in (F ◦ G), which proves that E holds for (F ◦ G) as well. We have proven the principle of structural induction for propositional formulas. It can easily be applied to other structured objects that are or that can be defined recursively. Assume we want to prove a property over lists of terms, where lists are defined as in Section 2.4.1. The corresponding induction principle reads as follows: Every list has a property E if the following conditions are met: 1. Induction base: The empty list [ ] has property E . 2. Induction step: If K is a term and the list R has property E , then .(K, R) has property E as well. Using this principle we can show that each list contains the symbol “ [ ] ”. In a similar way we can define the principle of structural induction for natural numbers in successor representation. Each natural number has a property E if the following conditions are met: 1. Induction base: 0 has property E. 2. Induction step: If the natural number N has property E, then s(N ) has property E as well . 72 CHAPTER 3. PROPOSITIONAL LOGIC Using this principle we can show that each natural number is smaller than or equal to its square. As a final example I want to discuss the principle of structural induction for words over an alphabet Σ. Each word occurring in Σ∗ has property E, if the following conditions are met: 1. Induction base: Λ has property E. 2. Induction step: If w ∈ Σ∗ has property E and a ∈ Σ, then aw has property E as well . Using this principle we can, for example, show for Σ = {1, 2} that for all w ∈ Σ∗ we find: the symbol 3 does not occur in w. Let us now turn to the question of how to define functions over sets of structered objects. For example, how can we compute the number of occurrences of binary connectives in a formula? How can we compute the number of occurrences of atoms in a formula? The following principle provides a possible solution to these and similar questions. Theorem 3.7 Principle of structural recursion: Let M be an arbitrary set. Furthermore, assume that the following functions are given: fooR : R → M, foo¬ : M → M, foo◦ : M × M → M for ◦ ∈ {∧, ∨, →, ↔}. Then, there is exactly one function foo : L(R) → M satisfying the following conditions: 1. Recursion base: foo(A) = fooR (A) for all A ∈ R . 2. Recursion steps: foo(¬G) = foo¬ (foo(G)) for all G ∈ L(R) . foo((G1 ◦ G2 )) = foo◦ (foo(G1 ), foo(G2 )) for all G1 , G2 ∈ L(R) . In many applications the set M and the functions foo R , foo ¬ and foo ◦ are not explicitely defined. Often the principle is introduced only informally: There is exactly one function foo defined over L(R) satisfying the following conditions: 1. Recursion base: The value of foo for atoms is defined explicitly. 2. Recursion steps: The value of foo for ¬F is defined depending only on the value of foo for F . The value of foo for (F ◦ G) is defined depending only on the values od foo for F and G . 73 3.1. SYNTAX The interested reader is invited to prove this theorem in Exercise 3.2. It is similar to the proof of Theorem 3.6. Theorem 3.7 can be applied to answer the above mentioned questions. Let if F is an atom, 0 foo 1 (F ) if F is of the form ¬G, foo 1 (F ) = foo 1 (G1 ) + foo 1 (G2 ) + 1 if F is of the form (G1 ◦ G2 ). foo 1 /1 computes the number of occurrences of binary connectives in a formula. For example, we find foo 1 (p1 ) = 0, foo 1 (¬p1 ) = 0 and foo 1 (¬((p1 → p2 ) ∨ p1 )) = 2. Consider now: if F is an atom, 1 foo 2 (G) if F is of the form ¬G, foo 2 (F ) = foo 2 (G1 ) + foo 2 (G2 ) if F is of the form (G1 ◦ G2 ). foo 2 /1 computes the number of occurrences of atoms in a formula. For example, we find foo 2 (p1 ) = 1, foo 2 (¬p1 ) = 1 and foo 2 (¬(p1 ∨ p1 )) = 2 . The last example illustrates, that foo 2 computes in deed occurrences of atoms. Another example is: if F is an atom, F ¬foo 3 (G) if F is of the form ¬G, foo 3 (F ) = foo 3 (G1 ) ◦ foo 3 (G2 ) if F is of the form (G1 ◦ G2 ). foo 3 elimininates all paranthesis occurring in F : foo 3 ((¬(p1 ∧ p2 ) → p3 )) = ¬p1 ∧ p2 → p3 . As final example we consider: ∅ if F is an atom, {1π | π ∈ foo 4 (G)} if F is of the form ¬G, foo 4 (F ) = {Λ} ∪ {1π1 | π1 ∈ foo 4 (G1 )} ∪ {2π2 | π2 ∈ foo 4 (G2 )} if F is of the form (G1 ◦ G2 ). foo 4 (F ) is often called the set of positions or occurrences in F . For example, we obtain: foo 4 (p1 ) foo 4 (¬p1 ) foo 4 (¬¬p1 ) foo 4 ((p1 ∨ p2 )) foo 4 (((p1 ∨ ¬p2 ) → (p3 ∧ p4 ))) = = = = = {Λ}, {Λ, 1}, {Λ, 1, 11}, {Λ, 1, 2}, {Λ, 1, 11, 12, 121, 2, 21, 22} Positions in a formula can nicely be illustrated by considering a tree representation of terms. Tree representations of Prolog-terms were already discussed 74 CHAPTER 3. PROPOSITIONAL LOGIC p1 • Λ ¬ • Λ ¬ • Λ p1 • 1 ¬ • 1 ∨ •Λ p1 • 1 p2 • 2 p1 • 11 Figure 3.1: The tree representation of the formulas p1 , ¬p1 , ¬¬p1 and (p1 ∨ p2 ) together with the associated positions. in Figure 2.5. In a similar wat we can represent formulas as trees. In Figures 3.1 und 3.2 several formulas are depicted as trees, and for each node the corresponding position is shown. We have presented the principle of structural recursion for propositional formulas. It can easily be applied to other structured objects. To illustrate this, we consider again the lists of terms as defined in Section 2.4.1. The corresponding recursion principle reads as follows: There is exactly one function foo defined over the set of lists of terms satisfying the following conditions: 1. Recursion base: The value of foo for the empty list [ ] is defined explicitly. 2. Recursion step: The value of foo for .(K, R) is defined depending only on the value of foo for R . We can now use this definition to define a function length/1 over lists of terms: % 0 if X is the empty list [ ], length(X) = length(R) + 1 if X is of the form .(K, R). The interested reader is invited to compare this mathematically precise definition to the program for length/2 specified in Section 2.4.4 (see Exercise 3.3). The principle of structural recursion can also be defined for natural numbers. There is exactly one function foo defined over the set of natural numbers in successor representation satisfying the following conditions: 1. Recursion base: The value of foo for 0 is defined explicitly. 2. Recursion step: The value of foo for s(N ) is defined depending only on the value of foo for N . 75 3.1. SYNTAX → •Λ ∨ • 1 ∨ • 11 ∧ • 2 ¬ • 12 p3 • 21 p4 • 22 p2 • 121 Figure 3.2: The tree representation of the formula ((p1 ∨ ¬p2 ) → (p3 ∧ p4 )) together with the associated positions. Using this principle we can, for example, define a function +2/1 over natural numbers, which adds 2 to its argument: % s(s(0)) if N = 0, +2(N ) = s(+2(N # )) if N is of the form s(N # ). Thus, we find that +2(0) = s(s(0)) and +2(s(s(0))) = s(s(s(s(0)))). Another example is the function !/1 , which is usually written in postfix notation: % s(0) if N = 0, N! = N × N # ! if N is of the form s(N # ). It is quite easy to implement the functions +2/1 and !/2 in Prolog. Finally, we consider again strings over an alphabet Σ. There is exactly one function foo defined over Σ∗ satisfying the following conditions: 1. Recursion base: The value of foo for Λ is defined explicitly. 2. Recursion step: The value of foo for aw ∈ Σ∗ is defined depending only on the value of foo for w. Using this principle we can, for example, define the length of a string as follows: % 0 if w = Λ, length(w) = 1 + length(w# ) if w is of the form aw#. The interested reader is again asked to implement the function length/1 in Prolog (see Exercise ??).