I used this set of slides for an Overview lecture I gave at the University of Zurich for the 1st year students following the course of Formale Grundlagen der Informatik.
7. Conjunction (AND) Disjunction (OR) Negation (NOT)
a ∧ b = y a ∨ b = y ¬ a = y
0 0 0 0 0 0 0 1
0 1 0 0 1 1 1 0
1 0 0 1 0 1
1 1 1 1 1 1
8. Neutral elements Commutativity
a ∧ 1 = a a ∨ b = b ∨ a
a ∨ 0 = a a ∧ b = b ∧ a
Zero elements Associativity
a ∧ 0 = 0 a ∧ (b ∧ c) = (a ∧ b) ∧ c
a ∨ 1 = 1 a ∨ (b ∨ c) = (a ∨ b) ∨ c
Idempotence Distributivity
a ∧ a = a a ∧ (b ∨ c) = (a ∧ b) ∨ (a ∧ c)
a ∨ a = a a ∨ (b ∧ c) = (a ∨ b) ∧ (a ∨ c)
Negation DeMorgan’s
a ∧ ¬ a = 0 ¬ (a ∧ b) = (¬ a) ∨ (¬ b)
a ∨ ¬ a = 1 ¬ (a ∨ b) = (¬ a) ∧ (¬ b)
9. Boolean algebra Propositional logic
0, 1 True, False
boolean variables: a∈{0, 1} atomic formulas: p∈{True,False}
boolean operators: ¬ ∧ ∨ logical connectives: ¬ ∧ ∨
boolean functions: propositional formulas (propositions):
0, 1 True and False
boolean variables atomic formulas
if a is a boolean function, then ¬a is a if a is a propositional formula, then ¬a
boolean function is a propositional formula
if a and b are boolean functions, then if a and b are propositional formulas,
a∧b, a∨b, a b, a b are boolean then a∧b, a∨b, a b, a b are
functions propositional formulas
truth value of a boolean function (truth truth value of a propositional formula (truth
tables) tables)
10. Boolean algebra Propositional logic
0, 1 True, False
boolean variables: a∈{0, 1} atomic formulas: p∈{True,False}
boolean operators: ¬ ∧ ∨ logical connectives: ¬ ∧ ∨
boolean functions: propositional formulas (propositions):
0, 1 True and False
boolean variables atomic formulas
if a is a boolean function, then ¬a is a if a is a propositional formula, then ¬a
boolean function is a propositional formula
if a and b are boolean functions, then if a and b are propositional formulas,
a∧b, a∨b, a b, a b are boolean then a∧b, a∨b, a b, a b are
functions propositional formulas
truth value of a boolean function (truth truth value of a propositional formula (truth
tables) tables)
11. Boolean algebra Predicate logic
1, 0, ∧, ∨, ¬ ∃, ∀
Sets Relations
U, ∅, ∈, ∪, ∩, , ⊆ AxB, aRb
Trees Graphs
node, edge, path, binary node, edge, cycle, path
Complexity Program verification
O(g), Ω(g), θ(g) {P} S {Q}, wp(S,Q)
Models and languages Programming languages
model, meta, syntax, semantics programming = modeling
12. Universal quantifier ∀ : Existential quantifiers ∃ :
∀x: U(x): F(x) ∃x: U(x): F(x)
∀x:x∈N:x>5 ∃x:x∈N:x>5
for all natural numbers x, for some natural numbers x,
x is greater than 5 x is greater than 5
13. ∀ i: 0≤i<N: ai=0 ∃ i: 0≤i<N: ai ≠ 0
all elements ai of array a (of length N) are at least one element of array a (of length N) is
zero not zero
∀ i: 1≤i<N: ai-1 ≤ ai ∃ i: 1≤i<N: ai-1 > ai
elements of array a are monotonically elements of array a are not monotonically
increasing increasing
∀ i,j: 0≤i<j<N: ai ≤ aj ∃ i,j: 0≤i<j<N: ai > aj
elements of array a are monotonically elements of array a are not monotonically
increasing increasing
∀ i,j: 0≤i,j<N: ai = aj ∃ i,j: 0≤i<j<N: ai ≠ aj
all elements of array a are equal not all elements of array a are equal
∀ i: 0<i<N: ai ≤ a0 ∃ i: 0<i<N: ai > a0
a0 is the greatest element of array a a0 is not the greatest element of array a
s
E xample
15. ambiguous
All elements of an array a of length N are either zero or one
(1) ∀i: 0≤i<N: ( ai=0 ∨ ai=1 )
(2) (∀i: 0≤i<N: ai=0) ∨ (∀i: 0≤i<N: ai=1)
Example
16. Boolean algebra Predicate logic
1, 0, ∧, ∨, ¬ ∃, ∀
Sets Relations
U, ∅, ∈, ∪, ∩, , ⊆ AxB, aRb
Trees Graphs
node, edge, path, binary node, edge, cycle, path
Complexity Program verification
O(g), Ω(g), θ(g) {P} S {Q}, wp(S,Q)
Models and languages Programming languages
model, meta, syntax, semantics programming = modeling
17. Neutral elements Commutativity
A ∩ U = A A ∪ B = B ∪ A
A ∪ ∅ = A A ∩ B = B ∩ A
Zero elements Associativity
A ∩ ∅ = ∅ A ∩ (B ∩ C) = (A ∩ B) ∩ C
A ∪ U = U A ∪ (B ∪ C) = (A ∪ B) ∪ C
Idempotence Distributivity
A ∩ A = A A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)
A ∪ A = A A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
Complement DeMorgan’s
A ∩ A’ = ∅ (A ∩ B)’ = (A’) ∪ (B’)
A ∪ A’ = U (A ∪ B)’ = (A’) ∩ (B’)
19. Boolean algebra Predicate logic
1, 0, ∧, ∨, ¬ ∃, ∀
Sets Relations
U, ∅, ∈, ∪, ∩, , ⊆ AxB, aRb
Trees Graphs
node, edge, path, binary node, edge, cycle, path
Complexity Program verification
O(g), Ω(g), θ(g) {P} S {Q}, wp(S,Q)
Models and languages Programming languages
model, meta, syntax, semantics programming = modeling
20. Cartesian product AxB
AxB={ (a,b) | a∈A and b∈B }
A × ∅ = ∅.
A × (B ∪ C) = (A × B) ∪ (A × C).
(A ∪ B) × C = (A × C) ∪ (B × C).
21. N-ary Relation
A1, A2, ..., An
R ⊆ A1 x A2 x...x An
Binary Relation
A 1, A 2
R ⊆ A1 x A2
(a,b) ∈ R
aRb
22. Reflexive relation
every element x of A is in relation R with itself
∀x: x∈A: xRx
Equivalent relation
Symmetric relation
if there is a relation between x and y, then there is a relation between y and x
∀x,y: x,y∈A: xRy yRx
Transitive relation
...
∀x,y,z: x,y,z∈A: (xRy ∧ yRz) xRz
23. Irreflexive relation
no element x of A is in relation R with itself
∀x: x∈A: ¬(xRx)
Antisymmetric relation
if there is a relation between x and y and one between y and x, then x equals y
∀x,y: x,y∈A: (xRy ∧ yRx) x=y
Asymmetric relation
xRy and yRx cannot hold at the same time
∀x,y: x,y∈A: xRy ¬(yRx)
Non-symmetric relation
a relation that is not symmetric
∀x,y: x,y∈A: (xRy) ∧ ¬(yRx)
Total relation
R is defined on the entire A.
∀x,y: x,y∈A: xRy ∨ yRx
24. Acyclic relation
there are no elements with transitive closure to themselves
∀n: n∈N:
( ¬(∃x1, x2, ...,xn:
x1, x2, ...,xn∈A:
x1Rx2 ∧ x2Rx3 ∧ ... ∧ xn-1Rxn ∧ xnRx1 ) )
25. R ⊆ AxA
{(a,b), (b,c), (c,d)} a b c d
Transitive closure
R1 = R;
∀i:i>1:Ri = Ri-1 ∪ {(a,b) | ∃c:: (a,c)∈Ri-1 ∧ (c,b)∈Ri-1}.
Rt = ∪i≥1Ri = R1 ∪ R2 ∪ R3 ∪ ...
26. Boolean algebra Predicate logic
1, 0, ∧, ∨, ¬ ∃, ∀
Sets Relations
U, ∅, ∈, ∪, ∩, , ⊆ AxB, aRb
Trees Graphs
node, edge, path, binary node, edge, cycle, path
Complexity Program verification
O(g), Ω(g), θ(g) {P} S {Q}, wp(S,Q)
Models and languages Programming languages
model, meta, syntax, semantics programming = modeling
39. Boolean algebra Predicate logic
1, 0, ∧, ∨, ¬ ∃, ∀
Sets Relations
U, ∅, ∈, ∪, ∩, , ⊆ AxB, aRb
Trees Graphs
node, edge, path, binary node, edge, cycle, path
Complexity Program verification
O(g), Ω(g), θ(g) {P} S {Q}, wp(S,Q)
Models and languages Programming languages
model, meta, syntax, semantics programming = modeling
40. 1 public long factorial (int n) {
2 long factorial = 1;
3 int i = 1;
4 while ( i ≤ n ) {
5 factorial = factorial * i;
6 i = i + 1;
7 }
8 return factorial
9 }
41. 1 public long factorial (int n) {
2 long factorial = 1; 1
3 int i = 1; 1
4 while ( i ≤ n ) { 4
5 factorial = factorial * i; 4
6 i = i + 1; 3
7 }
8 return factorial 1
9 }
42. 1 public long factorial (int n) {
2 long factorial = 1; 1 1
3 int i = 1; 1 1
4 while ( i ≤ n ) { 4 n
5 factorial = factorial * i; 4 n
6 i = i + 1; 3 n
7 }
8 return factorial 1 1
9 }
43. 1 public long factorial (int n) {
2 long factorial = 1; 1 1
3 int i = 1; 1 1
4 while ( i ≤ n ) { 4 n
5 factorial = factorial * i; 4 n
6 i = i + 1; 3 n
7 }
8 return factorial 1 1
9 }
f(n) = 1+1+4*n+4*n+3*n+1 = 11*n+3
44. Big O Notation
f: N -> N
g: N -> N
f ∈ O(g)
∃ c, n0 :
(c,n0∈N) ∧ (c>0) :
(∀n : n∈N ∧ n>n0 : f(n) ≤ c*g(n))
46. Best case estimation
f: N -> N
g: N -> N
f ∈ Ω(g)
∃ c, n0 :
(c,n0∈N) ∧ (c>0) :
(∀n : n∈N ∧ n>n0 : f(n) ≥ c*g(n))
47. Average case estimation
f: N -> N
g: N -> N
f ∈ θ(g)
∃ c 1, c 2, n 0 :
(c1,c2,n0∈N) ∧ (c1>0) ∧ (c2>0):
(∀n : n∈N ∧ n≥n0 : c1*g(n) ≤ f(n) ≤ c2*g(n))
55. While loop
L = while (B) do S end
wp(L,Q) I ∧
=
∀y, ((B ∧ I) wp(S, I ∧ x < y))
∀y, ((¬B ∧ I) Q)
Loop verification
I = property which stays true before and after every loop
0. P I;
1. I∧B wp(s, I);
2. I∧¬B Q.
56. Boolean algebra Predicate logic
1, 0, ∧, ∨, ¬ ∃, ∀
Sets Relations
U, ∅, ∈, ∪, ∩, , ⊆ AxB, aRb
Trees Graphs
node, edge, path, binary node, edge, cycle, path
Complexity Program verification
O(g), Ω(g), θ(g) {P} S {Q}, wp(S,Q)
Models and languages Programming languages
model, meta, syntax, semantics programming = modeling
57.
58. meta-meta-model
instanceOf
meta-model
instanceOf
model
representedBy
subject
59. A language is a set of sequences of symbols that
we interpret to attribute meaning.
60. - digit . digit
part = {digit} x
Nonter
decimal_part “.” part
= "x" mi
Termin nal
number = [-] part [decimal_part] x y al
Sequen
x|y ce
Alterna
{ x } tiv
Iteratio e
( x ) n
Binding
[ x ]
Option
y = x.
Definiti
on
61. Please, stand up by sitting down!
Syntactically correct sentences
do not necessarily have a meaning
62. Boolean algebra Predicate logic
1, 0, ∧, ∨, ¬ ∃, ∀
Sets Relations
U, ∅, ∈, ∪, ∩, , ⊆ AxB, aRb
Trees Graphs
node, edge, path, binary node, edge, cycle, path
Complexity Program verification
O(g), Ω(g), θ(g) {P} S {Q}, wp(S,Q)
Models and languages Programming languages
model, meta, syntax, semantics programming = modeling
65. Imperative Functional
data + algorithms stateless + pure functions
Object-oriented Logic
objects + messages facts + rules
66. comments functions
# Compute factorials variables
def fact(n)
if n == 0
literals
1
else
control n * fact(n-1) expression
constructs end
end
statements puts fact(ARGV[0].to_i)
75. Class aClass = Class.forName(“java.lang.Object”);
Method m[] aClass.getDeclaredMethods();
76. Class aClass = Class.forName(“java.lang.Object”);
Method m[] aClass.getDeclaredMethods();
protected void java.lang.Object.finalize() throws java.lang.Throwable
public final void java.lang.Object.wait() throws java.lang.InterruptedException
public final native void java.lang.Object.wait(long) throws
java.lang.InterruptedException
public final void java.lang.Object.wait(long,int) throws
java.lang.InterruptedException
public boolean java.lang.Object.equals(java.lang.Object)
public java.lang.String java.lang.Object.toString()
public native int java.lang.Object.hashCode()
public final native java.lang.Class java.lang.Object.getClass()
protected native java.lang.Object java.lang.Object.clone() throws
java.lang.CloneNotSupportedException
private static native void java.lang.Object.registerNatives()
public final native void java.lang.Object.notify()
public final native void java.lang.Object.notifyAll()