Go backward to 2.3.3 Equality Go up to 2.3 Predicate Logic Go forward to 2.3.5 Local Definitions |
If every variable in a syntactic phrase is bound by a quantifier, the phrase is said to be closed (geschlossen).
The meaning of a phrase does not depend on the name of the bound variable; we can replace this name by any other name without making a difference. Above definition implies that the meaning of a closed phrase does not depend on a given variable assignment but only on the considered domain.
In predicate logic, we have two important kinds of quantified formulas.
(forall x: A)
(exists x: A)
When writing a quantified formula like (forall f: A) it is clear that any occurrence of f within A should denote a variable (not a constant). Consequently, we do not need to rely on any special convention for the names of quantified variables to distinguish them from function constants.
Alternative Forms The formula forall x: A appears in various syntactic forms:
forall(x:A)
.
The last line denotes the input syntax of the Logic Evaluator.
Likewise, exists x: A may be expressed as:
exists(x:A)
.
Again, the last line is the input syntax of the Logic Evaluator.
forall x: ~(x < 0);
exists x: isPrime(x).
The correct syntactic structure of formulas with nested quantifiers has to be often deduced from the free variables; parentheses should be used whenever necessary to resolve ambiguities.
forall x: p(x) => exists y: q(f(x), y)is to be interpreted as
forall x: (p(x) => exists y: q(f(x), y)).and not as (forall x: p(x)) => exists y: q(f(x), y).
0 <= 0, 0 <= 1, 0 <= 2, ...Likewise, the existential formula exists x: x | 15 is true for every assignment over the natural numbers with `|' interpreted as `divides', because x | 15 is true for some natural number x (e.g. for 3):
3 | 15.
forall x: a(x) => b(x, f(x)).In the domain of integer numbers with a interpreted as "is non-negative", f interpreted as "square of" and b interpreted as "is less than or equal", the formula expresses the (true) statement
Every non-negative integer number is less than or equal its square.In the domain of character strings with a interpreted as "is non-empty", f interpreted as "string without first character" and b interpreted as "is longer than", the formula expresses the (true) statement
Every non-empty character string is longer than the string without the first character.
Free and Bound Variables As said above, the meaning of a formula does not depend on the name of a bound variable. For instance, the meaning of
forall x: exists y: x*y <= zis the same as the meaning of
forall y: exists w: y*w <= zbut it is not the same as the meaning of
forall x: exists y: x*y <= w.(because a free variable must not be renamed).
When stating a proposition, we usually operate with closed formulas, since their meaning is independent of any variable assignment. For instance, assume that we consider the domain of natural numbers with ` <= ' interpreted as usual. The statement
forall y: x <= yis true, if the current assignment maps the free variable x to 0, and false, otherwise. On the contrary, the closed formula
exists x: forall y: x <= yis true independently of the variable assignment. Sometimes, it is assumed that all free variables in a formula are universally quantified such that a formula
forall x: forall y: x <= x+ycould be also written as
x <= x+y.We recommend to always write all quantifiers to avoid misinterpretations.
We will sometimes use the following notation.
P[x <- T]the phrase we get from P by replacing every free occurrence of x by T.
F[x <- 1] = p(1) /\ r(1, y) /\ forall x: p(x)
Patterns A frequently occuring formula pattern is forall x: Ax => B where Ax is a formula with free variable x. Such a formula is often written as
forall Ax: Bprovided that the quantified variable x is clear from the context. Another such pattern is exists x: Ax /\ B which is typically written as
exists Ax: B.
forall x: exists 0 <= y <= x: | x - 2*y | <= 1is an abbreviation for the formula
forall x: (exists y: (0 <= y) /\ (y <= x) /\ (| x - 2*y | <= 1)).
"All Ferraris are red"is an abbreviation for the sentence
"It holds for all objects that, if the object is a Ferrari, then the object is red"which is represented by the formula
forall x: isFerrari(x) => isRed(x).
"Some Ferraris are black"is an abbreviation for the sentence
"There exists an object such that the object is a Ferrari and the object is black"which is represented by the formula
exists x: isFerrari(x) /\ isBlack(x).
The Logic Evaluator can evaluate quantified formulas that are input in prefix form; however, we have to denote the domain that we consider (which must be finite). In the following example, our domain is the range of natural numbers less than or equal 100.
We may however also explicitly set the domain for a quantified variable:
Operational Interpretation Variables are implemented by the following Java class:
public final class Variable implements Term { private String variable; public Variable(String _variable) { variable = _variable; } public String name() { return variable; } public Value eval() throws EvalException { Value value = Context.get(variable); if (value == null) throw new EvalException("no variable " + variable + " in context"); return value; } }
As we can see, the value of a variable is just determined by the context (the current variable assignment). This context is, e.g. provided by a universally quantified formula as an instance of the following Java class:
The Java expressionpublic final class ForAll implements Formula { private String variable; private Term domain; private Formula formula; public ForAll(String _variable, Term _domain, Formula _formula) { variable = _variable; domain = _domain; formula = _formula; } public boolean eval() throws EvalException { Iterator iterator = Model.iterator(domain); while (iterator.hasNext()) { Context.begin(variable, iterator.next()); boolean result = formula.eval(); Context.end(); if (!result) return false; } return true; } }
(new Forall(x, d, A)).eval()
computes the truth value of forall x: A in domain d.
As one can see, we iterate over d and establish new contexts in which
x is assigned each value of the domain in turn. In each context, we
evaluate A. Only if the result is true for every value, the overall
result is true.
Likewise, we have the following implementation of existential quantification:
To compute the value of the expressionpublic final class Exists implements Formula { private String variable; private Term domain; private Formula formula; public Exists(String _variable, Term _domain, Formula _formula) { variable = _variable; domain = _domain; formula = _formula; } public boolean eval() throws EvalException { Iterator iterator = Model.iterator(domain); while (iterator.hasNext()) { Context.begin(variable, iterator.next()); boolean result = formula.eval(); Context.end(); if (result) return true; } return false; } }
(new Exists(x,
d, A)).eval()
, we iterate over d and establish
all contexts in which A is evaluated. If we find some value for which
this result is true, the overall result is true.
Convention Multiple quantifiers of the same kind are often "merged", i.e., instead of writing forall x: forall y: A we often write
forall x, y: Aand instead of writing exists x: exists y: A we write
exists x, y: A.
The same is true for the Logic Evaluator where you can write
with any number of quantified variables.forall(x_0, ..., x_n-1: A) exists(x_0, ..., x_n-1: A)
Duality Existential and universal quantification are dual concepts:
In other words, "not all x have A" means the same as "there exists some x such that not A" and "there does not exist an x with A" means the same as "for all x, not A".
~forall x: A iff exists x: ~A ~exists x: A iff forall x: ~A
From these laws, it follows that exists x: A means the same as ~forall x: ~A; therefore frequently existential quantification is defined just as a syntactic abbreviation in terms of universal quantification (or vice versa).