word

29
word From Wikipedia, the free encyclopedia

Upload: man

Post on 05-Feb-2016

5 views

Category:

Documents


0 download

DESCRIPTION

1. From Wikipedia, the free encyclopedia2. Lexicographical order

TRANSCRIPT

Page 1: Word

wordFrom Wikipedia, the free encyclopedia

Page 2: Word

Contents

1 Free variables and bound variables 11.1 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.1.1 Variable-binding operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.2 Formal explanation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.2.1 Function expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.3 Natural language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.4 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2 Open sentence 62.1 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3 Sentence (logic) 83.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.2 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

4 String (computer science) 104.1 Formal theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

4.1.1 Concatenation and substrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.1.2 Prefixes and suffixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.1.3 Rotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.1.4 Reversal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124.1.5 Lexicographical ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124.1.6 String operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124.1.7 Topology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

4.2 String datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134.2.1 String length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134.2.2 Character encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134.2.3 Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144.2.4 Representations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144.2.5 Security concerns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

4.3 Text file strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

i

Page 3: Word

ii CONTENTS

4.4 Non-text strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164.5 String processing algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164.6 Character string-oriented languages and utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . 164.7 Character string functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174.8 String buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

4.8.1 In Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174.8.2 In .NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184.8.3 In other languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

4.9 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184.10 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

5 Well-formed formula 205.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215.2 Propositional calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215.3 Predicate logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225.4 Atomic and open formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225.5 Closed formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235.6 Properties applicable to formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235.7 Usage of the terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235.8 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235.9 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235.10 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245.11 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245.12 Text and image sources, contributors, and licenses . . . . . . . . . . . . . . . . . . . . . . . . . . 25

5.12.1 Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255.12.2 Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255.12.3 Content license . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

Page 4: Word

Chapter 1

Free variables and bound variables

For bound variables in computer programming, see Name binding.

In mathematics, and in other disciplines involving formal languages, including mathematical logic and computerscience, a free variable is a notation that specifies places in an expression where substitution may take place. Someolder books use the terms real variable and apparent variable for free variable and bound variable. The idea isrelated to a placeholder (a symbol that will later be replaced by some literal string), or a wildcard character thatstands for an unspecified symbol.In computer programming, the term free variable refers to variables used in a function that are neither local variablesnor parameters of that function.[1] The term non-local variable is often a synonym in this context.A bound variable is a variable that was previously free, but has been bound to a specific value or set of values. Forexample, the variable x becomes a bound variable when we write:

'For all x, (x + 1)2 = x2 + 2x + 1.'

or

'There exists x such that x2 = 2.'

In either of these propositions, it does not matter logically whether we use x or some other letter. However, it couldbe confusing to use the same letter again elsewhere in some compound proposition. That is, free variables becomebound, and then in a sense retire from being available as stand-in values for other values in the creation of formulae.The term “dummy variable” is also sometimes used for a bound variable (more often in general mathematics than incomputer science), but that use can create an ambiguity with the definition of dummy variables in regression analysis.

1.1 Examples

Before stating a precise definition of free variable and bound variable, the following are some examples that perhapsmake these two concepts clearer than the definition would:In the expression

10∑k=1

f(k, n),

n is a free variable and k is a bound variable; consequently the value of this expression depends on the value of n, butthere is nothing called k on which it could depend.In the expression

1

Page 5: Word

2 CHAPTER 1. FREE VARIABLES AND BOUND VARIABLES

∫ ∞

0

xy−1e−x dx,

y is a free variable and x is a bound variable; consequently the value of this expression depends on the value of y, butthere is nothing called x on which it could depend.In the expression

limh→0

f(x+ h)− f(x)

h,

x is a free variable and h is a bound variable; consequently the value of this expression depends on the value of x, butthere is nothing called h on which it could depend.In the expression

∀x ∃y[φ(x, y, z)

],

z is a free variable and x and y are bound variables; consequently the logical value of this expression depends on thevalue of z, but there is nothing called x or y on which it could depend.

1.1.1 Variable-binding operators

The following

∑x∈S

∏x∈S

∫ ∞

0

· · · dx limx→0

∀x ∃x

are variable-binding operators. Each of them binds the variable x.Note that many of these are operators which act on functions of the bound variable. In more complicated contexts,such notations can become awkward and confusing. It can be useful to switch to notations which make the bindingexplicit, such as

∑1 ... 10

(k 7→ f(k, n))

for sums or

D(x 7→ x2 + 2x+ 1

)for differentiation.

1.2 Formal explanation

Variable-binding mechanisms occur in different contexts in mathematics, logic and computer science. In all cases,however, they are purely syntactic properties of expressions and variables in them. For this section we can sum-marize syntax by identifying an expression with a tree whose leaf nodes are variables, constants, function constantsor predicate constants and whose non-leaf nodes are logical operators. This expression can then be determined bydoing an inorder traversal of the tree. Variable-binding operators are logical operators that occur in almost everyformal language. Indeed languages that do not have them are either extremely inexpressive or extremely difficult touse. A binding operator Q takes two arguments: a variable v and an expression P, and when applied to its arguments

Page 6: Word

1.2. FORMAL EXPLANATION 3

α

α

x

x

y z

A

B

Tree summarizing the syntax of the expression ∀x (∃y A(x) ∨B(z))

produces a new expression Q(v, P). The meaning of binding operators is supplied by the semantics of the languageand does not concern us here.Variable binding relates three things: a variable v, a location a for that variable in an expression and a non-leaf noden of the form Q(v, P). Note: we define a location in an expression as a leaf node in the syntax tree. Variable bindingoccurs when that location is below the node n.In the lambda calculus, x is a bound variable in the term M = λ x . T, and a free variable of T. We say x is bound inM and free in T. If T contains a subterm λ x . U then x is rebound in this term. This nested, inner binding of x is saidto “shadow” the outer binding. Occurrences of x in U are free occurrences of the new x.Variables bound at the top level of a program are technically free variables within the terms to which they are boundbut are often treated specially because they can be compiled as fixed addresses. Similarly, an identifier bound to arecursive function is also technically a free variable within its own body but is treated specially.A closed term is one containing no free variables.

Page 7: Word

4 CHAPTER 1. FREE VARIABLES AND BOUND VARIABLES

1.2.1 Function expressions

To give an example from mathematics, consider an expression which defines a function

f = [(x1, . . . , xn) 7→ t]

where t is an expression. t may contain some, all or none of the x1, ..., xn and it may contain other variables. In thiscase we say that function definition binds the variables x1, ..., xn.In this manner, function definition expressions of the kind shown above can be thought of as the variable bindingoperator, analogous to the lambda expressions of lambda calculus. Other binding operators, like the summation sign,can be thought of as higher-order functions applying to a function. So, for example, the expression

∑x∈A

x2

could be treated as a notation for

∑A

(x 7→ x2)

where∑

S f is an operator with two parameters—a one-parameter function, and a set to evaluate that function over.The other operators listed above can be expressed in similar ways; for example, the universal quantifier ∀x ∈ S P (x)can be thought of as an operator that evaluates to the logical conjunction of the boolean-valued function P appliedover the (possibly infinite) set S.

1.3 Natural language

When analyzed in formal semantics, natural languages can be seen to have free and bound variables. In English,personal pronouns like he, she, they, etc. can act as free variables.

Lisa found her book.

In the sentence above, the possessive pronoun her is a free variable. It may refer to the previously mentioned Lisa or toany other female. In other words, her book could be referring to Lisa’s book (an instance of coreference) or to a bookthat belongs to a different female (e.g. Jane’s book). Whoever the referent of her is can be established according tothe situational (i.e. pragmatic) context. The identity of the referent can be shown using coindexing subscripts wherei indicates one referent and j indicates a second referent (different from i). Thus, the sentence Lisa found her bookhas the following interpretations:

Lisai found heri book. (interpretation #1: her = Lisa)Lisai found herj book. (interpretation #2: her = female that is not Lisa)

The distinction is not purely of academic interest, as some languages do actually have different forms for heri andherj: for example, Norwegian translates coreferent heri as sin and noncoreferent herj as hennes.However, reflexive pronouns, such as himself, herself, themselves, etc., and reciprocal pronouns, such as each other,act as bound variables. In a sentence like the following:

Jane hurt herself.

the reflexive herself can only refer to the previously mentioned antecedent Jane. It can never refer to a differentfemale person. In other words, the person being hurt and the person doing the hurting are both the same person, i.e.Jane. The semantics of this sentence is abstractly: JANE hurt JANE. And it cannot be the case that this sentence

Page 8: Word

1.4. SEE ALSO 5

could mean JANE hurt LISA. The reflexive herself must refer and can only refer to the previously mentioned Jane. Inthis sense, the variable herself is bound to the noun Jane that occurs in subject position. Indicating the coindexation,the first interpretation with Jane and herself coindexed is permissible, but the other interpretation where they are notcoindexed is ungrammatical (the ungrammatical interpretation is indicated with an asterisk):

Janei hurt herselfi. (interpretation #1: herself = Jane)*Janei hurt herselfj. (interpretation #2: herself = a female that is not Jane)

Note that the coreference binding can be represented using a lambda expression as mentioned in the previous Formalexplanation section. The sentence with the reflexive could be represented as

(λx.x hurt x)Jane

in which Jane is the subject referent argument and λx.x hurt x is the predicate function (a lambda abstraction) withthe lambda notation and x indicating both the semantic subject and the semantic object of sentence as being bound.This returns the semantic interpretation JANE hurt JANE with JANE being the same person.Pronouns can also behave in a different way. In the sentence below

Ashley hit her.

the pronoun her can only refer to a female that is not Ashley. This means that it can never have a reflexive meaningequivalent to Ashley hit herself. The grammatical and ungrammatical interpretations are:

*Ashleyi hit heri. (interpretation #1: her = Ashley)Ashleyi hit herj. (interpretation #2: her = a female that is not Ashley)

The first interpretation is impossible. Only the second interpretation is permitted by the grammar.Thus, it can be seen that reflexives and reciprocals are bound variables (known technically as anaphors) while truepronouns are free variables in some grammatical structures but variables that cannot be bound in other grammaticalstructures. The binding phenomena found in natural languages was particularly important to the syntactic governmentand binding theory (see also: Binding (linguistics)).

1.4 See also• Closure (computer science)

• Combinatory logic

• Lambda lifting

• Name binding

• Scope (programming)

1.5 References[1] Free variables in Lisp

Page 9: Word

Chapter 2

Open sentence

In mathematics, an open sentence (usually an equation or equality) is described as “open” in the sense that its truthvalue is meaningless until its variables are replaced with specific numbers, at which point the truth value can usuallybe determined (and hence the sentences are no longer regarded as “open”). These possible replacement values areassumed to range over a subset of either the real or complex numbers, depending on the equation or inequality underconsideration (in applications, real numbers are usually associated also with measurement units). The replacementvalues which produce a true equation or inequality are called solutions of the equation or inequality, and are said to“satisfy” it.In mathematical logic, a non-closed formula is a formula which contains free variables. (Note that in logic, a"sentence" is a formula without free variables, and a formula is “open” if it contains no quantifiers, which disagreeswith the terminology of this article.) Unlike closed formulas, which contain constants, non-closed formulas do notexpress propositions; they are neither true nor false. Hence, the formula

has no truth-value. A formula is said to be satisfied by any object(s) such that if it is written in place of the variable(s),it will form a sentence expressing a true proposition. Hence, “5” satisfies (1). Any sentence which results from aformula in such a way is said to be a substitution instance of that formula. Hence, “5 is a number” is a substitutioninstance of (1).Mathematicians have not adopted that nomenclature, but refer instead to equations, inequalities with free variables,etc.Such replacements are known as solutions to the sentence. An identity is an open sentence for which every number isa solution.Examples of open sentences include:

1. 3x − 9 = 21, whose only solution for x is 10;

2. 4x + 3 > 9, whose solutions for x are all numbers greater than 3/2;

3. x + y = 0, whose solutions for x and y are all pairs of numbers that are additive inverses;

4. 3x + 9 = 3(x + 3), whose solutions for x are all numbers.

5. 3x + 9 = 3(x + 4), which has no solution.

Example 4 is an identity. Examples 1, 3, and 4 are equations, while example 2 is an inequality. Example 5 is acontradiction.Every open sentence must have (usually implicitly) a universe of discourse describing which numbers are under con-sideration as solutions. For instance, one might consider all real numbers or only integers. For example, in example2 above, 1.6 is a solution if the universe of discourse is all real numbers, but not if the universe of discourse is onlyintegers. In that case, only the integers greater than 3/2 are solutions: 2, 3, 4, and so on. On the other hand, if the

6

Page 10: Word

2.1. REFERENCES 7

universe of discourse consists of all complex numbers, then example 2 doesn't even make sense (although the otherexamples do). An identity is only required to hold for the numbers in its universe of discourse.This same universe of discourse can be used to describe the solutions to the open sentence in symbolic logic usinguniversal quantification. For example, the solution to example 2 above can be specified as:

For all x, 4x + 3 > 9 if and only if x > 3/2.

Here, the phrase “for all” implicitly requires a universe of discourse to specify which mathematical objects are “all”the possibilities for x.The idea can even be generalised to situations where the variables don't refer to numbers at all, as in a functionalequation. For an example of this, consider

f * f = f,

which says that f(x) * f(x) = f(x) for every value of x. If the universe of discourse consists of all functions from thereal lineR to itself, then the solutions for f are all functions whose only values are one and zero. But if the universe ofdiscourse consists of all continuous functions from R to itself, then the solutions for f are only the constant functionswith value one or zero.

2.1 References• Definition at The Math Resource

• The Math Forum @ Drexel

Page 11: Word

Chapter 3

Sentence (logic)

This article is a technical mathematical article in the area of predicate logic. For the ordinary Englishlanguage meaning see Sentence (linguistics), for a less technical introductory article see Statement (logic).

In mathematical logic, a sentence of a predicate logic is a boolean-valued well-formed formula with no free variables.A sentence can be viewed as expressing a proposition, something that may be true or false. The restriction of havingno free variables is needed to make sure that sentences can have concrete, fixed truth values: As the free variables ofa (general) formula can range over several values, the truth value of such a formula may vary.Sentences without any logical connectives or quantifiers in them are known as atomic sentences; by analogy to atomicformula. Sentences are then built up out of atomic sentences by applying connectives and quantifiers.A set of sentences is called a theory; thus, individual sentences may be called theorems. To properly evaluate thetruth (or falsehood) of a sentence, one must make reference to an interpretation of the theory. For first-order theories,interpretations are commonly called structures. Given a structure or interpretation, a sentence will have a fixed truthvalue. A theory is satisfiable when all of its sentences are true. The study of algorithms to automatically discoverinterpretations of theories that render all sentences as being true is known as the satisfiability modulo theories problem.

3.1 Example

The following example is in first-order logic.

∀y∃x(x2 = y)

is a sentence. This sentence is true in the positive real numbers ℝ+, false in the real numbers ℝ, and true in the complexnumbers ℂ. (In plain English, this sentence is interpreted to mean that every member of the structure concerned isthe square of a member of that particular structure.) On the other hand, the formula

∃x(x2 = y)

is not a sentence, because of the presence of the free variable y. In the structure of the real numbers, this formula istrue if we substitute (arbitrarily) y = 2, but is false if y = –2.

3.2 See also• Ground expression

• Open sentence

• Statement (logic)

• Proposition

8

Page 13: Word

Chapter 4

String (computer science)

This article is about the data type. For other uses, see String (disambiguation).In computer programming, a string is traditionally a sequence of characters, either as a literal constant or as some

Strings are applied e.g. in Bioinformatics to describe DNA strands composed of nitrogenous bases.

kind of variable. The latter may allow its elements to be mutated and the length changed, or it may be fixed (aftercreation). A string is generally understood as a data type and is often implemented as an array of bytes (or words)that stores a sequence of elements, typically characters, using some character encoding. A string may also denotemore general arrays or other sequence (or list) data types and structures.Depending on programming language and precise data type used, a variable declared to be a string may either causestorage in memory to be statically allocated for a predetermined maximum length or employ dynamic allocation toallow it to hold variable number of elements.

10

Page 14: Word

4.1. FORMAL THEORY 11

When a string appears literally in source code, it is known as a string literal or an anonymous string.[1]

In formal languages, which are used in mathematical logic and theoretical computer science, a string is a finitesequence of symbols that are chosen from a set called an alphabet.

4.1 Formal theory

See also: Tuple

Let Σ be a non-empty finite set of symbols (alternatively called characters), called the alphabet. No assumption ismade about the nature of the symbols. A string (or word) over Σ is any finite sequence of symbols from Σ.[2] Forexample, if Σ = {0, 1}, then 01011 is a string over Σ.The length of a string s is the number of symbols in s (the length of the sequence) and can be any non-negative integer;it is often denoted as |s|. The empty string is the unique string over Σ of length 0, and is denoted ε or λ.[2][3]

The set of all strings over Σ of length n is denoted Σn. For example, if Σ = {0, 1}, then Σ2 = {00, 01, 10, 11}. Notethat Σ0 = {ε} for any alphabet Σ.The set of all strings over Σ of any length is the Kleene closure of Σ and is denoted Σ*. In terms of Σn,

Σ∗ =∪

n∈N∪{0}

Σn

For example, if Σ = {0, 1}, then Σ* = {ε, 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, ...}. Although the set Σ* itself iscountably infinite, each element of Σ* is a string of finite length.A set of strings over Σ (i.e. any subset of Σ*) is called a formal language over Σ. For example, if Σ = {0, 1}, the setof strings with an even number of zeros, {ε, 1, 00, 11, 001, 010, 100, 111, 0000, 0011, 0101, 0110, 1001, 1010,1100, 1111, ...}, is a formal language over Σ.

4.1.1 Concatenation and substrings

Concatenation is an important binary operation on Σ*. For any two strings s and t in Σ*, their concatenation is definedas the sequence of symbols in s followed by the sequence of characters in t, and is denoted st. For example, if Σ ={a, b, ..., z}, s = bear, and t = hug, then st = bearhug and ts = hugbear.String concatenation is an associative, but non-commutative operation. The empty string ε serves as the identityelement; for any string s, εs = sε = s. Therefore, the set Σ* and the concatenation operation form a monoid, the freemonoid generated by Σ. In addition, the length function defines a monoid homomorphism from Σ* to the non-negativeintegers (that is, a function L : Σ∗ 7→ N ∪ {0} , such that L(st) = L(s) + L(t) ∀s, t ∈ Σ∗ ).A string s is said to be a substring or factor of t if there exist (possibly empty) strings u and v such that t = usv. Therelation “is a substring of” defines a partial order on Σ*, the least element of which is the empty string.

4.1.2 Prefixes and suffixes

A string s is said to be a prefix of t if there exists a string u such that t = su. If u is nonempty, s is said to be a properprefix of t. Symmetrically, a string s is said to be a suffix of t if there exists a string u such that t = us. If u is nonempty,s is said to be a proper suffix of t. Suffixes and prefixes are substrings of t. Both the relations “is a prefix of” and “is asuffix of” are prefix orders.

4.1.3 Rotations

A string s = uv is said to be a rotation of t if t = vu. For example, if Σ = {0, 1} the string 0011001 is a rotation of0100110, where u = 00110 and v = 01.

Page 15: Word

12 CHAPTER 4. STRING (COMPUTER SCIENCE)

4.1.4 Reversal

The reverse of a string is a string with the same symbols but in reverse order. For example, if s = abc (where a, b,and c are symbols of the alphabet), then the reverse of s is cba. A string that is the reverse of itself (e.g., s = madam)is called a palindrome, which also includes the empty string and all strings of length 1.

4.1.5 Lexicographical ordering

It is often useful to define an ordering on a set of strings. If the alphabet Σ has a total order (cf. alphabetical order)one can define a total order on Σ* called lexicographical order. For example, if Σ = {0, 1} and 0 < 1, then thelexicographical order on Σ* includes the relationships ε < 0 < 00 < 000 < ... < 0001 < 001 < 01 < 010 < 011 < 0110< 01111 < 1 < 10 < 100 < 101 < 111 < 1111 < 11111 ... The lexicographical order is total if the alphabetical orderis, but isn't well-founded for any nontrivial alphabet, even if the alphabetical order is.See Shortlex for an alternative string ordering that preserves well-foundedness.

4.1.6 String operations

A number of additional operations on strings commonly occur in the formal theory. These are given in the article onstring operations.

4.1.7 Topology

000 001

010

100

011

111

101

110

(Hyper)cube of binary strings of length 3

Strings admit the following interpretation as nodes on a graph:

Page 16: Word

4.2. STRING DATATYPES 13

• Fixed-length strings can be viewed as nodes on a hypercube• Variable-length strings (of finite length) can be viewed as nodes on the k-ary tree, where k is the number ofsymbols in Σ

• Infinite strings (otherwise not considered here) can be viewed as infinite paths on the k-ary tree.

The natural topology on the set of fixed-length strings or variable-length strings is the discrete topology, but thenatural topology on the set of infinite strings is the limit topology, viewing the set of infinite strings as the inverselimit of the sets of finite strings. This is the construction used for the p-adic numbers and some constructions of theCantor set, and yields the same topology.Isomorphisms between string representations of topologies can be found by normalizing according to the lexicographicallyminimal string rotation.

4.2 String datatypes

See also: Comparison of programming languages (string functions)

A string datatype is a datatype modeled on the idea of a formal string. Strings are such an important and usefuldatatype that they are implemented in nearly every programming language. In some languages they are available asprimitive types and in others as composite types. The syntax of most high-level programming languages allows for astring, usually quoted in some way, to represent an instance of a string datatype; such a meta-string is called a literalor string literal.

4.2.1 String length

Although formal strings can have an arbitrary (but finite) length, the length of strings in real languages is oftenconstrained to an artificial maximum. In general, there are two types of string datatypes: fixed-length strings, whichhave a fixed maximum length to be determined at compile time and which use the same amount of memory whetherthis maximum is needed or not, and variable-length strings, whose length is not arbitrarily fixed and which can usevarying amounts of memory depending on the actual requirements at run time. Most strings in modern programminglanguages are variable-length strings. Of course, even variable-length strings are limited in length – theoretically bythe number of bits available to a pointer, practically by the current size of memory. The string length can be storedas a separate integer (which may put an artificial limit on the length) or implicitly through a termination character,usually a character value with all bits zero. See also “Null-terminated” below.

4.2.2 Character encoding

String datatypes have historically allocated one byte per character, and, although the exact character set varied byregion, character encodings were similar enough that programmers could often get away with ignoring this, sincecharacters a program treated specially (such as period and space and comma) were in the same place in all theencodings a program would encounter. These character sets were typically based on ASCII or EBCDIC.Logographic languages such as Chinese, Japanese, and Korean (known collectively as CJK) need far more than 256characters (the limit of a one 8-bit byte per-character encoding) for reasonable representation. The normal solutionsinvolved keeping single-byte representations for ASCII and using two-byte representations for CJK ideographs. Useof these with existing code led to problems with matching and cutting of strings, the severity of which depended onhow the character encoding was designed. Some encodings such as the EUC family guarantee that a byte value in theASCII range will represent only that ASCII character, making the encoding safe for systems that use those charactersas field separators. Other encodings such as ISO-2022 and Shift-JIS do not make such guarantees, making matchingon byte codes unsafe. These encodings also were not “self-synchronizing”, so that locating character boundariesrequired backing up to the start of a string, and pasting two strings together could result in corruption of the secondstring (these problems were much less with EUC as any ASCII character did synchronize the encoding).Unicode has simplified the picture somewhat. Most programming languages now have a datatype for Unicode strings.Unicode’s preferred byte stream format UTF-8 is designed not to have the problems described above for older multi-byte encodings. UTF-8, UTF-16 and UTF-32 require the programmer to know that the fixed-size code units are

Page 17: Word

14 CHAPTER 4. STRING (COMPUTER SCIENCE)

different than the “characters”, the main difficulty currently is incorrectly designed APIs that attempt to hide thisdifference (UTF-32 does make code points fixed-sized, but these are not “characters” due to composing codes).

4.2.3 Implementations

Some languages like C++ implement strings as templates that can be used with any datatype, but this is the exception,not the rule.Some languages, such as C++ and Ruby, normally allow the contents of a string to be changed after it has beencreated; these are termed mutable strings. In other languages, such as Java and Python, the value is fixed and a newstring must be created if any alteration is to be made; these are termed immutable strings.Strings are typically implemented as arrays of bytes, characters, or code units, in order to allow fast access to individualunits or substrings—including characters when they have a fixed length. A few languages such as Haskell implementthem as linked lists instead.Some languages, such as Prolog and Erlang, avoid implementing a dedicated string datatype at all, instead adoptingthe convention of representing strings as lists of character codes.

4.2.4 Representations

Representations of strings depend heavily on the choice of character repertoire and the method of character encoding.Older string implementations were designed to work with repertoire and encoding defined by ASCII, or more recentextensions like the ISO 8859 series. Modern implementations often use the extensive repertoire defined by Unicodealong with a variety of complex encodings such as UTF-8 and UTF-16.The term byte string usually indicates a general-purpose string of bytes, rather than strings of only (readable) charac-ters, strings of bits, or such. Byte strings often imply that bytes can take any value and any data can be stored as-is,meaning that there should be no value interpreted as a termination value.Most string implementations are very similar to variable-length arrays with the entries storing the character codes ofcorresponding characters. The principal difference is that, with certain encodings, a single logical character may takeup more than one entry in the array. This happens for example with UTF-8, where single codes (UCS code points)can take anywhere from one to four bytes, and single characters can take an arbitrary number of codes. In these cases,the logical length of the string (number of characters) differs from the logical length of the array (number of bytes inuse). UTF-32 avoids the first part of the problem.

Null-terminated

Main article: Null-terminated string

The length of a string can be stored implicitly by using a special terminating character; often this is the null character(NUL), which has all bits zero, a convention used and perpetuated by the popular C programming language.[4] Hence,this representation is commonly referred to as a C string. This representation of an n-character string takes n + 1space (1 for the terminator), and is thus an implicit data structure.In terminated strings, the terminating code is not an allowable character in any string. Strings with length field donot have this limitation and can also store arbitrary binary data. In C two things are needed to handle binary data: acharacter pointer and the length of the data.An example of a null-terminated string stored in a 10-byte buffer, along with its ASCII (or more modern UTF-8)representation as 8-bit hexadecimal numbers is:The length of the string in the above example, “FRANK”, is 5 characters, but it occupies 6 bytes. Characters after theterminator do not form part of the representation; they may be either part of another string or just garbage. (Stringsof this form are sometimes called ASCIZ strings, after the original assembly language directive used to declare them.)

Page 18: Word

4.2. STRING DATATYPES 15

Length-prefixed

The length of a string can also be stored explicitly, for example by prefixing the string with the length as a byte value(a convention used in many Pascal dialects): as a consequence, some people call it a Pascal string or P-string.Storing the string length as byte limits the maximum string length to 255. To avoid such limitations, improvedimplementations of P-strings use 16-, 32-, or 64-bit words to store the string length. When the length field coversthe address space, strings are limited only by the available memory. Encoding the length n takes log(n) space (seefixed-length code), so length-prefixed strings are a succinct data structure, encoding a string of length n in log(n) +n space. However, if the length is bounded, then the length can be encoded in constant space, typically a machineword, and thus is an implicit data structure, taking n + k space, where k is the number of characters in a word (8 for8-bit ASCII on a 64-bit machine, 1 for 32-bit UTF-32/UCS-4 on a 32-bit machine, etc.).Here is the equivalent Pascal string stored in a 10-byte buffer, along with its ASCII / UTF-8 representation:

Strings as records

Many languages, including object-oriented ones, implement strings as records in a structure like:class string { unsigned int length; char *text; };

Although this implementation is hidden, and accessed through member functions. The “text” will be a dynamicallyallocated memory area, that might be expanded if needed. See also string (C++).

Linked-list

Both character termination and length codes limit strings: For example, C character arrays that contain null (NUL)characters cannot be handled directly by C string library functions: Strings using a length code are limited to themaximum value of the length code.Both of these limitations can be overcome by clever programming, but such workarounds are by definition not stan-dard.Rough equivalents of the C termination method have historically appeared in both hardware and software. Forexample, “data processing” machines like the IBM 1401 used a special word mark bit to delimit strings at the left,where the operation would start at the right. This meant that, while the IBM 1401 had a seven-bit word in “reality”,almost no-one ever thought to use this as a feature, and override the assignment of the seventh bit to (for example)handle ASCII codes.It is possible to create data structures and functions that manipulate them that do not have the problems associatedwith character termination and can in principle overcome length code bounds. It is also possible to optimize the stringrepresented using techniques from run length encoding (replacing repeated characters by the character value and alength) and Hamming encoding.While these representations are common, others are possible. Using ropes makes certain string operations, such asinsertions, deletions, and concatenations more efficient.

4.2.5 Security concerns

The differing memory layout and storage requirements of strings can affect the security of the program accessingthe string data. String representations requiring a terminating character are commonly susceptible to buffer overflowproblems if the terminating character is not present, caused by a coding error or an attacker deliberately altering thedata. String representations adopting a separate length field are also susceptible if the length can be manipulated. Insuch cases, program code accessing the string data requires bounds checking to ensure that it does not inadvertentlyaccess or change data outside of the string memory limits.String data is frequently obtained from user-input to a program. As such, it is the responsibility of the program tovalidate the string to ensure that it represents the expected format. Performing limited or no validation of user-inputcan cause a program to be vulnerable to code injection attacks.

Page 19: Word

16 CHAPTER 4. STRING (COMPUTER SCIENCE)

4.3 Text file strings

In computer readable text files, for example programming language source files or configuration files, strings can berepresented. The NUL byte is normally not used as terminator since that does not correspond to the ASCII textstandard, and the length is usually not stored, since the file should be human editable without bugs.Two common representations are:

• Surrounded by quotation marks (ASCII 2216), used by most programming languages. To be able to includequotation marks, newline characters etc., escape sequences are often available, usually using the backslashcharacter (ASCII 5C16).

• Terminated by a newline sequence, for example in Windows INI files.

See also: String literal

4.4 Non-text strings

While character strings are very common uses of strings, a string in computer science may refer generically to anysequence of homogeneously typed data. A string of bits or bytes, for example, may be used to represent non-textualbinary data retrieved from a communications medium. This data may or may not be represented by a string-specificdatatype, depending on the needs of the application, the desire of the programmer, and the capabilities of the pro-gramming language being used. If the programming language’s string implementation is not 8-bit clean, data cor-ruption may ensue.

4.5 String processing algorithms

There aremany algorithms for processing strings, each with various trade-offs. Some categories of algorithms include:

• String searching algorithms for finding a given substring or pattern

• String manipulation algorithms

• Sorting algorithms

• Regular expression algorithms

• Parsing a string

• Sequence mining

Advanced string algorithms often employ complex mechanisms and data structures, among them suffix trees and finitestate machines.The name stringologywas coined in 1984 by computer scientist Zvi Galil for the issue of algorithms and data structuresused for string processing.[5]

4.6 Character string-oriented languages and utilities

Character strings are such a useful datatype that several languages have been designed in order to make string pro-cessing applications easy to write. Examples include the following languages:

• awk

• Icon

Page 20: Word

4.7. CHARACTER STRING FUNCTIONS 17

• MUMPS

• Perl

• Rexx

• Ruby

• sed

• SNOBOL

• Tcl

• TTM

Many Unix utilities perform simple string manipulations and can be used to easily program some powerful stringprocessing algorithms. Files and finite streams may be viewed as strings.Some APIs like Multimedia Control Interface, embedded SQL or printf use strings to hold commands that will beinterpreted.Recent scripting programming languages, including Perl, Python, Ruby, and Tcl employ regular expressions to fa-cilitate text operations. Perl is particularly noted for its regular expression use,[6] and many other languages andapplications implement Perl compatible regular expressions.Some languages such as Perl and Ruby support string interpolation, which permits arbitrary expressions to be evalu-ated and included in string literals.

4.7 Character string functions

See also: Comparison of programming languages (string functions)

String functions are used to manipulate a string or change or edit the contents of a string. They also are used to queryinformation about a string. They are usually used within the context of a computer programming language.The most basic example of a string function is the string length function – the function that returns the length ofa string (not counting any terminator characters or any of the string’s internal structural information) and does notmodify the string. This function is often named length or len. For example, length(“hello world”) would return 11.

4.8 String buffers

In some programming languages, a string buffer is an alternative to a string. It has the ability to be altered throughadding or appending, whereas a String is normally fixed or immutable.

4.8.1 In Java

Theory

Java's standard way to handle text is to use its String class. Any given String in Java is an immutable object, whichmeans its state cannot be changed. A String has an array of characters. Whenever a String must be manipulated, anychanges require the creation of a new String (which, in turn, involves the creation of a new array of characters, andcopying of the original array). This happens even if the original String’s value or intermediate Strings used for themanipulation are not kept.Java provides an alternate class for string manipulation, called StringBuffer. A StringBuffer, like a String, has anarray to hold characters. It, however, is mutable (its state can be altered). Its array of characters is not necessarilycompletely filled (as opposed to a String, whose array is always the exact required length for its contents). Thus, ithas the capability to add, remove, or change its state without creating a new object (and without the creation of a new

Page 21: Word

18 CHAPTER 4. STRING (COMPUTER SCIENCE)

array, and array copying). The exception to this is when its array is no longer of suitable length to hold its content.In this case, it is required to create a new array, and copy the contents.For these reasons, Java would handle an expression likeString newString = aString + anInt + aChar + aDouble;

like this:String newString = (new StringBuilder(aString)).append(anInt).append(aChar).append(aDouble).toString();

Implications

Generally, a StringBuffer is more efficient than a String in string handling. However, this is not necessarily the case,since a StringBuffer will be required to recreate its character array when it runs out of space. Theoretically, this ispossible to happen the same number of times as a new String would be required, although this is unlikely (and theprogrammer can provide length hints to prevent this). Either way, the effect is not noticeable in modern desktopcomputers.As well, the shortcomings of arrays are inherent in a StringBuffer. In order to insert or remove characters at arbitrarypositions, whole sections of arrays must be moved.The method by which a StringBuffer is attractive in an environment with low processing power takes this ability byusing too much memory, which is likely also at a premium in this environment. This point, however, is trivial, con-sidering the space required for creating many instances of Strings in order to process them. As well, the StringBuffercan be optimized to “waste” as little memory as possible.The StringBuilder class, introduced in J2SE 5.0, differs from StringBuffer in that it is unsynchronized. When only asingle thread at a time will access the object, using a StringBuilder processes more efficiently than using a StringBuffer.StringBuffer and StringBuilder are included in the java.lang package.

4.8.2 In .NET

Microsoft’s .NET Framework has a StringBuilder class in its Base Class Library.

4.8.3 In other languages

• In C++ and Ruby, the standard string class is already mutable, with the ability to change the contents andappend strings, etc., so a separate mutable string class is unnecessary.

• InObjective-C (Cocoa/OpenStep frameworks), theNSMutableString class is themutable version of theNSStringclass.

4.9 See also

• Formal language — a (possibly infinite) set of strings in theoretical computer science

• Connection string — passed to a driver to initiate a connection e.g. to a database

• Rope — a data structure for efficiently manipulating long strings

• Bitstring — a string of binary digits

• Binary-safe — a property of string manipulating functions treating their input as raw data stream

• Improper input validation— a type of software security vulnerability particularly relevant for user-given strings

• Incompressible string — a string that cannot be compressed by any algorithm

Page 22: Word

4.10. REFERENCES 19

• Empty string — its properties and representation in programming languages

• String metric — notions of similarity between strings

• string (C++) — overview of C++ string handling

• string.h — overview of C string handling

• Analysis of algorithms — determining time and storage needed by a particular (e.g. string manipulation)algorithm

4.10 References[1] “Introduction To Java - MFC 158 G”. String literals (or constants) are called ‘anonymous strings’

[2] Barbara H. Partee; Alice ter Meulen; Robert E. Wall (1990). Mathematical Methods in Linguistics. Kluwer.

[3] John E. Hopcroft, Jeffrey D. Ullman (1979). Introduction to Automata Theory, Languages, and Computation. Addison-Wesley. ISBN 0-201-02988-X. Here: sect.1.1, p.1

[4] Bryant, Randal E.; David, O'Hallaron (2003), Computer Systems: A Programmer’s Perspective (2003 ed.), Upper SaddleRiver, NJ: Pearson Education, p. 40, ISBN 0-13-034074-X

[5] “The Prague Stringology Club”. stringology.org. Retrieved 23 May 2015.

[6] “Essential Perl”. Perl’s most famous strength is in string manipulation with regular expressions.

Page 23: Word

Chapter 5

Well-formed formula

Symbols andstrings of symbols

Well-formed formulas

Theorems

This diagram shows the syntactic entities which may be constructed from formal languages. The symbols and strings of symbolsmay be broadly divided into nonsense and well-formed formulas. A formal language can be thought of as identical to the set of itswell-formed formulas. The set of well-formed formulas may be broadly divided into theorems and non-theorems.

In mathematical logic, a well-formed formula, shortly wff, often simply formula, is a word (i.e. a finite sequenceof symbols from a given alphabet) that is part of a formal language.[1] A formal language can be considered to beidentical to the set containing all and only its formulas.A formula is a syntactic formal object that can be given a semantic meaning by means of semantics.

20

Page 24: Word

5.1. INTRODUCTION 21

5.1 Introduction

A key use of formulae is in propositional logic and predicate logics such as first-order logic. In those contexts, aformula is a string of symbols φ for which it makes sense to ask “is φ true?", once any free variables in φ have beeninstantiated. In formal logic, proofs can be represented by sequences of formulas with certain properties, and thefinal formula in the sequence is what is proven.Although the term “formula” may be used for written marks (for instance, on a piece of paper or chalkboard), it ismore precisely understood as the sequence being expressed, with the marks being a token instance of formula. It isnot necessary for the existence of a formula that there be any actual tokens of it. A formal language may thus have aninfinite number of formulas regardless whether each formula has a token instance. Moreover, a single formula mayhave more than one token instance, if it is written more than once.Formulas are quite often interpreted as propositions (as, for instance, in propositional logic). However formulas aresyntactic entities, and as such must be specified in a formal language without regard to any interpretation of them.An interpreted formula may be the name of something, an adjective, an adverb, a preposition, a phrase, a clause, animperative sentence, a string of sentences, a string of names, etc.. A formula may even turn out to be nonsense, if thesymbols of the language are specified so that it does. Furthermore, a formula need not be given any interpretation.

5.2 Propositional calculus

The formulas of propositional calculus, also called propositional formulas,[2] are expressions such as (A ∧ (B ∨C)). Their definition begins with the arbitrary choice of a set V of propositional variables. The alphabet consists of theletters in V along with the symbols for the propositional connectives and parentheses "(" and ")", all of which areassumed to not be in V. The formulas will be certain expressions (that is, strings of symbols) over this alphabet.The formulas are inductively defined as follows:

• Each propositional variable is, on its own, a formula.

• If φ is a formula, then ¬ φ is a formula.

• If φ and ψ are formulas, and • is any binary connective, then ( φ • ψ) is a formula. Here • could be (but is notlimited to) the usual operators ∨, ∧, →, or ↔.

This definition can also be written as a formal grammar in Backus–Naur form, provided the set of variables is finite:

<alpha set> ::= p | q | r | s | t | u | ... (the arbitrary finite set of propositional variables)<form> ::= <alpha set> | ¬ <form> | (<form> ∧ <form>) | (<form> ∨ <form>) | (<form>→ <form>) |(<form>↔ <form>)

Using this grammar, the sequence of symbols

(((p→ q) ∧ (r→ s)) ∨ ( ¬ q ∧ ¬ s))

is a formula, because it is grammatically correct. The sequence of symbols

((p→ q)→ (qq))p))

is not a formula, because it does not conform to the grammar.A complex formula may be difficult to read, owing to, for example, the proliferation of parentheses. To alleviatethis last phenomenon, precedence rules (akin to the standard mathematical order of operations) are assumed amongthe operators, making some operators more binding than others. For example, assuming the precedence (from mostbinding to least binding) 1. ¬ 2. → 3. ∧ 4. ∨ . Then the formula

(((p→ q) ∧ (r→ s)) ∨ ( ¬ q ∧ ¬ s))

Page 25: Word

22 CHAPTER 5. WELL-FORMED FORMULA

may be abbreviated as

p→ q ∧ r→ s ∨ ¬ q ∧ ¬ s

This is, however, only a convention used to simplify the written representation of a formula. If the precedence wasassumed, for example, to be left-right associative, in following order: 1. ¬ 2. ∧ 3. ∨ 4. → , then the same formulaabove (without parentheses) would be rewritten as

(p→ (q ∧ r))→ (s ∨ (( ¬ q) ∧ ( ¬ s)))

5.3 Predicate logic

The definition of a formula in first-order logic QS is relative to the signature of the theory at hand. This signaturespecifies the constant symbols, relation symbols, and function symbols of the theory at hand, along with the arities ofthe function and relation symbols.The definition of a formula comes in several parts. First, the set of terms is defined recursively. Terms, informally,are expressions that represent objects from the domain of discourse.

1. Any variable is a term.

2. Any constant symbol from the signature is a term

3. an expression of the form f(t1,...,tn), where f is an n-ary function symbol, and t1,...,tn are terms, is again aterm.

The next step is to define the atomic formulas.

1. If t1 and t2 are terms then t1=t2 is an atomic formula

2. If R is an n-ary relation symbol, and t1,...,tn are terms, then R(t1,...,tn) is an atomic formula

Finally, the set of formulas is defined to be the smallest set containing the set of atomic formulas such that thefollowing holds:

1. ¬ϕ is a formula when ϕ is a formula

2. (ϕ ∧ ψ) and (ϕ ∨ ψ) are formulas when ϕ and ψ are formulas;

3. ∃xϕ is a formula when x is a variable and ϕ is a formula;

4. ∀xϕ is a formula when x is a variable and ϕ is a formula (alternatively, ∀xϕ could be defined as an abbreviationfor ¬∃x¬ϕ ).

If a formula has no occurrences of ∃x or ∀x , for any variable x , then it is called quantifier-free. An existentialformula is a formula starting with a sequence of existential quantification followed by a quantifier-free formula.

5.4 Atomic and open formulas

Main article: Atomic formula

An atomic formula is a formula that contains no logical connectives nor quantifiers, or equivalently a formula that hasno strict subformulas. The precise form of atomic formulas depends on the formal system under consideration; forpropositional logic, for example, the atomic formulas are the propositional variables. For predicate logic, the atomsare predicate symbols together with their arguments, each argument being a term.According to some terminology, an open formula is formed by combining atomic formulas using only logical con-nectives, to the exclusion of quantifiers.[3] This has not to be confused with a formula which is not closed.

Page 26: Word

5.5. CLOSED FORMULAS 23

5.5 Closed formulas

Main article: Sentence (mathematical logic)

A closed formula, also ground formula or sentence, is a formula in which there are no free occurrences of any variable.If A is a formula of a first-order language in which the variables v1, ..., vn have free occurrences, then A preceded byv1 ... vn is a closure of A.

5.6 Properties applicable to formulas

• A formula A in a language Q is valid if it is true for every interpretation of Q .

• A formula A in a language Q is satisfiable if it is true for some interpretation of Q .

• A formula A of the language of arithmetic is decidable if it represents a decidable set, i.e. if there is aneffective method which, given a substitution of the free variables of A, says that either the resulting instance ofA is provable or its negation is.

5.7 Usage of the terminology

In earlier works on mathematical logic (e.g. by Church[4]), formulas referred to any strings of symbols and amongthese strings, well-formed formulas were the strings that followed the formation rules of (correct) formulas.Several authors simply say formula.[5][6][7][8] Modern usages (especially in the context of computer science withmathematical software such as model checkers, automated theorem provers, interactive theorem provers) tend toretain of the notion of formula only the algebraic concept and to leave the question of well-formedness, i.e. of theconcrete string representation of formulas (using this or that symbol for connectives and quantifiers, using this or thatparenthesizing convention, using Polish or infix notation, etc.) as a mere notational problem.However, the expression well-formed formulas can still be found in various works,[9][10][11] these authors using thename well-formed formula without necessarily opposing it to the old sense of formula as arbitrary string of symbols sothat it is no longer common in mathematical logic to refer to arbitrary strings of symbols in the old sense of formulas.The expression “well-formed formulas” (WFF) also pervaded in popular culture. Indeed,WFF is part of an esotericpun used in the name of the academic game "WFF 'N PROOF: The Game of Modern Logic,” by Layman Allen,[12]developed while he was at Yale Law School (he was later a professor at the University of Michigan). The suite ofgames is designed to teach the principles of symbolic logic to children (in Polish notation).[13] Its name is an echoof whiffenpoof, a nonsense word used as a cheer at Yale University made popular in The Whiffenpoof Song and TheWhiffenpoofs.[14]

5.8 See also

• Ground expression

5.9 Notes[1] Formulas are a standard topic in introductory logic, and are covered by all introductory textbooks, including Enderton

(2001), Gamut (1990), and Kleene (1967)

[2] First-order logic and automated theorem proving, Melvin Fitting, Springer, 1996

[3] Handbook of the history of logic, (Vol 5, Logic from Russell to Church), Tarski’s logic by Keith Simmons, D. Gabbay andJ. Woods Eds, p568 .

[4] Alonzo Church, [1996] (1944), Introduction to mathematical logic, page 49

Page 27: Word

24 CHAPTER 5. WELL-FORMED FORMULA

[5] Hilbert, David; Ackermann, Wilhelm (1950) [1937], Principles of Mathematical Logic, New York: Chelsea

[6] Hodges, Wilfrid (1997), A shorter model theory, Cambridge University Press, ISBN 978-0-521-58713-6

[7] Barwise, Jon, ed. (1982), Handbook of Mathematical Logic, Studies in Logic and the Foundations of Mathematics, Am-sterdam: North-Holland, ISBN 978-0-444-86388-1

[8] Cori, Rene; Lascar, Daniel (2000), Mathematical Logic: A Course with Exercises, Oxford University Press, ISBN 978-0-19-850048-3

[9] Enderton, Herbert [2001] (1972), A mathematical introduction to logic (2nd ed.), Boston, MA: Academic Press, ISBN978-0-12-238452-3

[10] R. L. Simpson (1999), Essentials of Symbolic Logic, page 12

[11] Mendelson, Elliott [2010] (1964), An Introduction to Mathematical Logic (5th ed.), London: Chapman & Hall

[12] Ehrenburg 2002

[13] More technically, propositional logic using the Fitch-style calculus.

[14] Allen (1965) acknowledges the pun.

5.10 References• Allen, Layman E. (1965), “TowardAutotelic Learning ofMathematical Logic by theWFF 'N PROOFGames”,Mathematical Learning: Report of a Conference Sponsored by the Committee on Intellective Processes Researchof the Social Science Research Council, Monographs of the Society for Research in Child Development 30 (1):29–41

• Boolos, George; Burgess, John; Jeffrey, Richard (2002), Computability and Logic (4th ed.), Cambridge Uni-versity Press, ISBN 978-0-521-00758-0

• Ehrenberg, Rachel (Spring 2002). “He’s Positively Logical”. Michigan Today (University of Michigan). Re-trieved 2007-08-19.

• Enderton, Herbert (2001), A mathematical introduction to logic (2nd ed.), Boston, MA: Academic Press, ISBN978-0-12-238452-3

• Gamut, L.T.F. (1990), Logic, Language, and Meaning, Volume 1: Introduction to Logic, University Of ChicagoPress, ISBN 0-226-28085-3

• Hodges, Wilfrid (2001), “Classical Logic I: First-Order Logic”, in Goble, Lou, The Blackwell Guide to Philo-sophical Logic, Blackwell, ISBN 978-0-631-20692-7

• Hofstadter, Douglas (1980), Gödel, Escher, Bach: An Eternal Golden Braid, Penguin Books, ISBN 978-0-14-005579-5

• Kleene, Stephen Cole (2002) [1967], Mathematical logic, New York: Dover Publications, ISBN 978-0-486-42533-7, MR 1950307

• Rautenberg, Wolfgang (2010), A Concise Introduction to Mathematical Logic (3rd ed.), New York: SpringerScience+Business Media, doi:10.1007/978-1-4419-1221-3, ISBN 978-1-4419-1220-6

5.11 External links• Well-Formed Formula for First Order Predicate Logic - includes a short Java quiz.

• Well-Formed Formula at ProvenMath

• WFF N PROOF game site

Page 28: Word

5.12. TEXT AND IMAGE SOURCES, CONTRIBUTORS, AND LICENSES 25

5.12 Text and image sources, contributors, and licenses

5.12.1 Text• Free variables and bound variables Source: https://en.wikipedia.org/wiki/Free_variables_and_bound_variables?oldid=671743800Con-tributors: Toby Bartels, Edward, Michael Hardy, Emperorbma, Charles Matthews, Bevo, Robbot, MathMartin, Pengo, Tobias Bergemann,Ssd, CSTAR, SeanProctor, Spayrard, Shenme, Homerjay, DiegoMoya, Ish ishwar, Daira Hopwood, MFH, BD2412, R.e.b., Eubot, Fresh-eneesz, Algebraist, YurikBot, SimonMorgan, Wasseralm, Mustard~enwiki, SmackBot, Mhss, Jerome Charles Potts, Shunpiker, Cyberco-bra, Jon Awbrey, Henning Makholm, Ysoldak, MagnaMopus, Physis, Paul Foxworthy, CBM, Gregbard, Nick Number, JohnPaulPagano,AnAj, Abcarter, Faizhaider, Usien6, R'n'B, Arronax50, Trumpet marietta 45750, Xnuala, Camrn86, Aaron Rotenberg, Reuqr, Ddxc,Maxalbanese, Classicalecon, 718 Bot, SchreiberBike, Franklin.vp, Subversive.sound, Addbot, Ojb500, Yobot, Pcap, Gongshow, 4th-otaku, Iitmadras, Cmccormick8, FrescoBot, Winterst, Lotje, WikitanvirBot, BattyBot, TrebDozer and Anonymous: 41

• Open sentence Source: https://en.wikipedia.org/wiki/Open_sentence?oldid=671189026 Contributors: Toby Bartels, Michael Hardy,Oliver Pereira, AugPi, Pizza Puzzle, Ruakh, Alan Liefting, Jason Quinn, Klemen Kocjancic, Rgdboer, EmilJ, Oleg Alexandrov, Linas,LOL, Ledy, BD2412, Kbdank71, Jshadias, Mathbot, DevastatorIIC, Wimt, ENeville, Malcolma, Sharkb, Melchoir, Bigbluefish, Mhss,Chris the speller, Clconway, Atoll, CBM, Gregbard, AndrewHowse, Cydebot, Alaibot, Nemti, Mhaitham.shammaa, JamesBWatson,JaGa, Unisonus, AlnoktaBOT, Randomblue, ClueBot, Addbot, Magog the Ogre, Etincelles, ClueBot NG, Suelru and Anonymous: 15

• Sentence (logic) Source: https://en.wikipedia.org/wiki/Sentence_(logic)?oldid=670287163Contributors: Michael Hardy, Silverfish, CharlesMatthews, Giftlite, Spayrard, Rgdboer, Oleg Alexandrov, Linas, BD2412, Qwertyus, Mkehrt, 4C~enwiki, Ihope127, Rick Norwood,Trovatore, Bbaumer, Maksim-e~enwiki, Bigbluefish, Mhss, Mets501, CBM, Gregbard, Skier Dude, Anonymous Dissident, Philogo,Ctxppc, DesolateReality, Addbot, TaBOT-zerem, Citation bot, MastiBot, Masssly, MerlIwBot, Helpful Pixie Bot and Anonymous: 4

• String (computer science) Source: https://en.wikipedia.org/wiki/String_(computer_science)?oldid=671439373 Contributors: DamianYerrick, AxelBoldt, Eloquence, Hornlo, Bryan Derksen, Zundark, The Anome, Stephen Gilbert, Koyaanis Qatsi, Drj, Boleslav Bobcik,Perique des Palottes, Mjb, B4hand, Patrick, RTC, Michael Hardy, Pnm, TakuyaMurata, Mkweise, Ahoerstemeier, Александър, ArthurFrayn, Error, Bogdangiusca, Andres, Ghewgill, Charles Matthews, Dcoetzee, Dysprosia, Furrykef, Bevo, Sewing, Robbot, Murray Lang-ton, Scarfboy, Pengo, Tobias Bergemann, Giftlite, DavidCary, Castaa, Fropuff, Jorge Stolfi, Christopherlin, Vadmium, Fudo, Beland,Kusunose, Maximaximax, Sebbe, Pinguin.tk~enwiki, Andreas Kaufmann, Shahab, Slady, Murtasa, Plugwash, Spitzak, MisterSheik, Can-isRufus, Anphanax, Cedders, Richard W.M. Jones, Spearhead, Sietse Snel, R. S. Shaw, Minghong, Obradovic Goran, Nevyn, Wayfarer,Hippophaë~enwiki, Ubermonkey, Seec77, Alai, Forderud, Oleg Alexandrov, Linas, Bkkbrad, MattGiuca, Ruud Koot, Urod, AnthonyBorla, Jonnabuz, Gwil, Qwertyus, Kbdank71, TheIncredibleEdibleOompaLoompa, StuartBrady, FlaBot, Ian Pitchford, Stoph, Margos-bot~enwiki, Gparker, Gurch, Pexatus, Chobot, YurikBot, Borgx, Hairy Dude, Fabartus, Howcheng, Mikeblas, Black Falcon, JLaTondre,SmackBot, BurntSky, AnOddName, Chris the speller, Sahirshah, Gaiacarra, Thumperward, Nbarth, Jeremysr, BIL, Cybercobra, Dread-star, Tompsci, Drphilharmonic, Mlpkr, Lambiam, Doug Bell, Derek farn, Witharebelyell, Shirifan, Loadmaster, Dr.K., Rory O'Kane,Dreftymac, Pimlottc, Courcelles, Georg Peter, Neelix, Gregbard, Peterdjones, Gogo Dodo, Christian75, Mojo Hand, John254, Icep,AntiVandalBot, JonathanCross, JAnDbot, Dereckson, David Eppstein, Philg88, Tigrisek, Gwern, DorganBot, WinterSpw, Tortoise3,VolkovBot, AlnoktaBOT, Andy Dingley, C45207, S.Örvarr.S, Bentogoa, Taemyr, Doctorfluffy, OKBot, Anchor Link Bot, Treekids,Elassint, ClueBot, The Thing That Should Not Be, Garyzx, Mild Bill Hiccup, Alexbot, OpinionPerson, Mad Tinman, Marc van Leeuwen,Gumum, SilvonenBot, Addbot, Jncraton, IOLJeff, Numbo3-bot, Teles, Jarble, Legobot, Yobot, Gyro Copter, Denispir, AnomieBOT,Ma-terialscientist, LilHelpa, Xqbot, 4twenty42o, Nasnema, GenQuest, SassoBot, Kyng, Charvest, GNRY09, Jordandanford, Jc3s5h, Ptarjan,FoxBot, TBloemink, Ripchip Bot, EmausBot, RogerofRomsey, GoingBatty, Wikipelli, Slawekb, Nomen4Omen, Dennis714, SporkBot,Underrated1 17, Jay-Sebastos, Uuf6429, Cgt, ClueBot NG, Jiri 1984, Fatboar, CanadianMaritimer, Doorknob747, Luke Igoe, Dainomite,Joydeep, Andrew Helwer, Local.empire, Alfabalon, Frosty, Jochen Burghardt, Pantser, A4b3c2d1e0f, Tentinator, Captain Conundrum,DavidLeighEllis, Komarov om, Mythas11, L Manju, Sofia Koutsouveli, IAMBLAQTHOVEN, Stawny, PJ editing and Anonymous: 135

• Well-formed formula Source: https://en.wikipedia.org/wiki/Well-formed_formula?oldid=660313819 Contributors: Edward, MichaelHardy, DavidWBrooks, Charles Matthews, Wik, Hyacinth, Onebyone, Josh Cherry, Tobias Bergemann, Giftlite, Andy, Jeffwarnica,Abdull, Mh, Dolda2000, Spayrard, Linas, GregorB, BD2412, Qwertyus, MithrandirMage, SpuriousQ, IanManka, Ihope127, Trovatore,Pawyilee, Ripper234, Arthur Rubin, Otto ter Haar, SmackBot, Pokipsy76,Mhss, Ioscius, Jgoulden, B7T,Midnighttonight, CRGreathouse,CBM, Gregbard, Cydebot, Julian Mendez, Forgot, Nick Number, Behco, Laymanal, CountingPine, Epsilon0, Dessources, Philogo,Paradoctor, DeathByNukes, Kumioko (renamed), Martarius, ClueBot, PixelBot, Hans Adler, Jonverve, Hugo Herbelin, LheaJLove, Ad-dbot, Yobot, Ptbotgourou, Notacupcakebaker, GrouchoBot, Tkuvho, Jonesey95, Dude1818, Gamewizard71, BillyPreset, GoingBatty,Bamyers99, Pyy999, Wcherowi, Helpful Pixie Bot, Laymanallen, CitationCleanerBot, Blakehill, Jochen Burghardt and Anonymous: 38

5.12.2 Images• File:0321_DNA_Macrostructure.jpg Source: https://upload.wikimedia.org/wikipedia/commons/b/b4/0321_DNA_Macrostructure.jpgLicense: CC BY 3.0 Contributors: Anatomy & Physiology, Connexions Web site. http://cnx.org/content/col11496/1.6/, Jun 19, 2013.Original artist: OpenStax College

• File:Binary_math_expression_tree.svg Source: https://upload.wikimedia.org/wikipedia/commons/2/2a/Binary_math_expression_tree.svg License: CC BY-SA 3.0 Contributors: Own work Original artist: Jozef Sivek

• File:Formal_languages.svg Source: https://upload.wikimedia.org/wikipedia/commons/d/da/Formal_languages.svg License: CC BY-SA 3.0 Contributors: Own work based on: en:Image:Formal languages.png by Gregbard. Original artist: MithrandirMage

• File:Hamming_distance_3_bit_binary.svg Source: https://upload.wikimedia.org/wikipedia/commons/b/b4/Hamming_distance_3_bit_binary.svg License: CC-BY-SA-3.0 Contributors: This vector image was created with Inkscape. Original artist: en:User:Cburnett

• File:Logic_portal.svg Source: https://upload.wikimedia.org/wikipedia/commons/7/7c/Logic_portal.svg License: CC BY-SA 3.0 Con-tributors: Own work Original artist: Watchduck (a.k.a. Tilman Piesk)

• File:Merge-arrow.svg Source: https://upload.wikimedia.org/wikipedia/commons/a/aa/Merge-arrow.svg License: Public domain Con-tributors: ? Original artist: ?

Page 29: Word

26 CHAPTER 5. WELL-FORMED FORMULA

• File:Question_book-new.svg Source: https://upload.wikimedia.org/wikipedia/en/9/99/Question_book-new.svg License: Cc-by-sa-3.0Contributors:Created from scratch in Adobe Illustrator. Based on Image:Question book.png created by User:Equazcion Original artist:Tkgd2007

• File:Text_document_with_red_question_mark.svg Source: https://upload.wikimedia.org/wikipedia/commons/a/a4/Text_document_with_red_question_mark.svg License: Public domain Contributors: Created by bdesham with Inkscape; based upon Text-x-generic.svgfrom the Tango project. Original artist: Benjamin D. Esham (bdesham)

• File:Wiki_letter_w_cropped.svg Source: https://upload.wikimedia.org/wikipedia/commons/1/1c/Wiki_letter_w_cropped.svg License:CC-BY-SA-3.0 Contributors:

• Wiki_letter_w.svg Original artist: Wiki_letter_w.svg: Jarkko Piiroinen

5.12.3 Content license• Creative Commons Attribution-Share Alike 3.0