Overview



           www.tudorgirba.com
computation



information                 information
              computer
Computer science is the systematic study of
information and computation.
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
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
+           +

    a = 0       a = 1


    y = 0       y = 1
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
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)
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)
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)
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
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
∀ 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
De Morgan’s Axiom ¬∃ :
¬(∃ x: U(x): F(x))       ∀ x: U(x): ¬ F(x)


De Morgan’s Axiom ¬∀ :
¬(∀ x: U(x): F(x))       ∃ x: U(x): ¬ F(x)
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
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
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’)
Reflexivity
A ⊆ A.



Anti-symmetry
A ⊆ B ∧ B ⊆ A   A = B.



Transitivity
A ⊆ B ∧ B ⊆ C   A ⊆ C
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
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).
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
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
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
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 ) )
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 ∪ ...
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
n1
               n10
     n2


                     n9
n3


                     n8
n4



     n5        n7
          n6
n1
               n10
     n2


                     n9
n3


                     n8
n4



     n5        n7
          n6
n1



     n2         n3        n4



n5        n6         n7   n8   n9



          n10
not a binary tree                  binary tree

                n1                                n1


     n2                       n3        n2                  n3


n4         n5                 n6   n4        n5        n6




                                        complete binary tree

                                                  n1


                                        n2                  n3


                                   n4        n5        n6        n7
breadth-first traversal



                              1

                              n1

               2                        3

              n2                        n3

     4                   5         6

     n4                  n5        n6
preorder(node)
visit(node).
preorder(node.left).
preorder(node.right).        1

                             n1

                 2                     5

              n2                       n3

     3                  4         6

     n4                 n5        n6
inorder(node)
inorder(node.left).
visit(node).
inorder(node.right).        4

                            n1

                2                     6

                n2                    n3

     1                 3         5

     n4                n5        n6
postorder (node)
postorder(node.left).
postorder(node.right).
visit(node).                  6

                              n1

              3                         5

              n2                        n3

     1                   2         4

     n4                  n5        n6
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
G = (V, E)
E = { {u,v} | u,v ∈ V}



 a                       e




           c         d       g



 b                       f
Path                       Cycle

     a                         e

             c        d                 g

     b                         f



Path: (b, a, c); Length (b, a, c) = 2
Path: (b, d, f)
Cycle: (f, g, e, d, f); Length (f, g, e, d, f) = 4
Hamiltonian path           Eulerian path


a                  e       a                   e

     c      d          g       c     d             g

b                  f       b                   f
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
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 }
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 }
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 }
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
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))
O(1) ∈ O(log n) ∈ O(n) ∈ O(n2) ∈ O(nk) ∈ O(2n)

                        !"#$%$&'()("'*$+ ,'-.$/'--
O(1)      Constant


O(log n) Logarithmic


O(n)      Linear


O(n2)     Quadratic


O(nk)     Polynomial


O(kn)     Exponential
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))
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))
solvable
 in O(nk)   P ⊂ NP   verifiable
                     in O(nk)
solvable
 in O(nk)   P = NP
              ?      verifiable
                     in O(nk)
NP-complete
 NP, and one cannot do better
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
program
                  S



    {P}                      {Q}

precondition             postcondition
Weakest Precondition wp(S, Q)

∀ {P} S {Q} :: P           wp(S,Q)




Verification of {P} S {Q}

1. Compute wp(S, Q)

2. Prove P         wp(S, Q)
Assignment
wp(x:=A, Q) = Qx←A


Sequencing
wp(S1; S2, Q)	 wp(S1, wp(S2, Q))
             =	



Conditional
wp(if (B) then S1 else S2, Q)	 =
              (B     wp(S1, Q)) ∧ (¬B   wp(S2, Q))
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.
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
meta-meta-model

         instanceOf


  meta-model

         instanceOf


    model

         representedBy


    subject
A language is a set of sequences of symbols that
we interpret to attribute meaning.
-         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
Please, stand up by sitting down!
       Syntactically correct sentences
      do not necessarily have a meaning
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
A programming language is a a language for
communicating software designs.
in g, 1937
Alan Tur
Imperative           Functional
data + algorithms    stateless + pure functions




Object-oriented      Logic
objects + messages   facts + rules
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)
programming = modeling
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
computation



information                 information
              computer
computational thinking
              computation



information                 information
              computer
Reflection
Class aClass = Class.forName(“java.lang.Object”);
Method m[] aClass.getDeclaredMethods();
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()
computational thinking
              computation



information                 information
              computer
Tudor Gîrba
        www.tudorgirba.com




creativecommons.org/licenses/by/3.0/

12 - Overview

  • 1.
    Overview www.tudorgirba.com
  • 2.
    computation information information computer
  • 3.
    Computer science isthe systematic study of information and computation.
  • 4.
    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
  • 5.
    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
  • 6.
    + + a = 0 a = 1 y = 0 y = 1
  • 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
  • 14.
    De Morgan’s Axiom¬∃ : ¬(∃ x: U(x): F(x)) ∀ x: U(x): ¬ F(x) De Morgan’s Axiom ¬∀ : ¬(∀ x: U(x): F(x)) ∃ x: U(x): ¬ F(x)
  • 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’)
  • 18.
    Reflexivity A ⊆ A. Anti-symmetry A⊆ B ∧ B ⊆ A A = B. Transitivity A ⊆ B ∧ B ⊆ C A ⊆ C
  • 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 elementx 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 areno 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
  • 27.
    n1 n10 n2 n9 n3 n8 n4 n5 n7 n6
  • 28.
    n1 n10 n2 n9 n3 n8 n4 n5 n7 n6
  • 29.
    n1 n2 n3 n4 n5 n6 n7 n8 n9 n10
  • 30.
    not a binarytree binary tree n1 n1 n2 n3 n2 n3 n4 n5 n6 n4 n5 n6 complete binary tree n1 n2 n3 n4 n5 n6 n7
  • 31.
    breadth-first traversal 1 n1 2 3 n2 n3 4 5 6 n4 n5 n6
  • 32.
  • 33.
  • 34.
  • 35.
    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
  • 36.
    G = (V,E) E = { {u,v} | u,v ∈ V} a e c d g b f
  • 37.
    Path Cycle a e c d g b f Path: (b, a, c); Length (b, a, c) = 2 Path: (b, d, f) Cycle: (f, g, e, d, f); Length (f, g, e, d, f) = 4
  • 38.
    Hamiltonian path Eulerian path a e a e c d g c d g b f b f
  • 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 longfactorial (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 longfactorial (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 longfactorial (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 longfactorial (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))
  • 45.
    O(1) ∈ O(logn) ∈ O(n) ∈ O(n2) ∈ O(nk) ∈ O(2n) !"#$%$&'()("'*$+ ,'-.$/'-- O(1) Constant O(log n) Logarithmic O(n) Linear O(n2) Quadratic O(nk) Polynomial O(kn) Exponential
  • 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))
  • 48.
    solvable in O(nk) P ⊂ NP verifiable in O(nk)
  • 49.
    solvable in O(nk) P = NP ? verifiable in O(nk)
  • 50.
    NP-complete NP, andone cannot do better
  • 51.
    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
  • 52.
    program S {P} {Q} precondition postcondition
  • 53.
    Weakest Precondition wp(S,Q) ∀ {P} S {Q} :: P wp(S,Q) Verification of {P} S {Q} 1. Compute wp(S, Q) 2. Prove P wp(S, Q)
  • 54.
    Assignment wp(x:=A, Q) =Qx←A Sequencing wp(S1; S2, Q) wp(S1, wp(S2, Q)) = Conditional wp(if (B) then S1 else S2, Q) = (B wp(S1, Q)) ∧ (¬B wp(S2, Q))
  • 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
  • 58.
    meta-meta-model instanceOf meta-model instanceOf model representedBy subject
  • 59.
    A language isa 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 upby 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
  • 63.
    A programming languageis a a language for communicating software designs.
  • 64.
  • 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)
  • 68.
  • 69.
    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
  • 71.
    computation information information computer
  • 72.
    computational thinking computation information information computer
  • 74.
  • 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()
  • 77.
    computational thinking computation information information computer
  • 78.
    Tudor Gîrba www.tudorgirba.com creativecommons.org/licenses/by/3.0/