Professional Documents
Culture Documents
Matei Popovici1
1 POLITEHNICA University of Bucharest Computer Science and Engineering Department, Bucharest, Romania
9 noiembrie 2012
Matei Popovici
Motivation
Matei Popovici
Motivation
Code !
Matei Popovici
Motivation
The ListVector implementation:
Matei Popovici
Motivation
The ListVector implementation: relies on a primitive Array datatype
Matei Popovici
Motivation
The ListVector implementation: relies on a primitive Array datatype full encapsulation (operations modify the object) The PointerVector implementation: relies on Java references partial encapsulation (two kinds of objects)
Matei Popovici
Motivation
The ListVector implementation: relies on a primitive Array datatype full encapsulation (operations modify the object) insert may be (1) or O(n) The PointerVector implementation: relies on Java references partial encapsulation (two kinds of objects) insertion is always be (1)
Matei Popovici
Motivation
The ListVector implementation: relies on a primitive Array datatype full encapsulation (operations modify the object) insert may be (1) or O(n) The PointerVector implementation: relies on Java references partial encapsulation (two kinds of objects) insertion is always be (1) Open problems: Algorithms with complex data structures
Matei Popovici
Motivation
The ListVector implementation: relies on a primitive Array datatype full encapsulation (operations modify the object) insert may be (1) or O(n) The PointerVector implementation: relies on Java references partial encapsulation (two kinds of objects) insertion is always be (1) Open problems: Algorithms with complex data structures how to we reason about complexity ?
Matei Popovici
Motivation
The ListVector implementation: relies on a primitive Array datatype full encapsulation (operations modify the object) insert may be (1) or O(n) The PointerVector implementation: relies on Java references partial encapsulation (two kinds of objects) insertion is always be (1) Open problems: Algorithms with complex data structures how to we reason about complexity ? how do we know algorithms are correct ?
Matei Popovici
Motivation
Consider another implementation of the List of integers datatype (this time, not in Java)
Matei Popovici
Motivation
Consider another implementation of the List of integers datatype (this time, not in Java) Code !
Matei Popovici
Motivation
The previous program:
Matei Popovici
Motivation
The previous program: species how values of type List of integers can be built
Matei Popovici
Motivation
The previous program: species how values of type List of integers can be built species operations dened for our type
Matei Popovici
Motivation
The previous program: species how values of type List of integers can be built species operations dened for our type does not specify what a list of integers is
Matei Popovici
Motivation
The previous program: species how values of type List of integers can be built species operations dened for our type does not specify what a list of integers is Ignoring implementation
Matei Popovici
Motivation
The previous program: species how values of type List of integers can be built species operations dened for our type does not specify what a list of integers is Ignoring implementation we do this all the time !
Matei Popovici
Motivation
The previous program: species how values of type List of integers can be built species operations dened for our type does not specify what a list of integers is Ignoring implementation we do this all the time ! how is a double represented (in Java) ?
Matei Popovici
Motivation
The previous program: species how values of type List of integers can be built species operations dened for our type does not specify what a list of integers is Ignoring implementation we do this all the time ! how is a double represented (in Java) ? do we care about the representation when we add doubles ?
Matei Popovici
Matei Popovici
Matei Popovici
Matei Popovici
Matei Popovici
Matei Popovici
Matei Popovici
Matei Popovici
Matei Popovici
Matei Popovici
Taxonomy
Void : List Cons : Integer List List extract : List \ {Void} Integer
extract (Cons(e,l)) = e
Taxonomy:
Matei Popovici
Taxonomy
Void : List Cons : Integer List List extract : List \ {Void} Integer
extract (Cons(e,l)) = e
Matei Popovici
Taxonomy
Void : List Cons : Integer List List extract : List \ {Void} Integer
extract (Cons(e,l)) = e
Taxonomy: Base constructors: Those constructors which can jointly generate all values of the type
Matei Popovici
Taxonomy
Void : List Cons : Integer List List extract : List \ {Void} Integer
extract (Cons(e,l)) = e
Taxonomy: Base constructors: Those constructors which can jointly generate all values of the type (Simple) constructors
Matei Popovici
Taxonomy
Void : List Cons : Integer List List extract : List \ {Void} Integer
extract (Cons(e,l)) = e
Taxonomy: Base constructors: Those constructors which can jointly generate all values of the type (Simple) constructors All the rest.
Matei Popovici
Taxonomy
Void : List Cons : Integer List List extract : List \ {Void} Integer
extract (Cons(e,l)) = e
Taxonomy: Base constructors: Those constructors which can jointly generate all values of the type (Simple) constructors All the rest. Axioms
Matei Popovici
Taxonomy
Void : List Cons : Integer List List extract : List \ {Void} Integer
extract (Cons(e,l)) = e
Taxonomy: Base constructors: Those constructors which can jointly generate all values of the type (Simple) constructors All the rest. Axioms
Matei Popovici
Taxonomy
void : List cons : Integer List List extract : List \ {Void} Integer
extract (cons(e,l)) = e
Taxonomy:
Matei Popovici
Taxonomy
Void : List cons : Integer List List extract : List \ {Void} Integer
extract (cons(e,l)) = e
Matei Popovici
Taxonomy
void : List cons : Integer List List extract : List \ {Void} Integer
extract (cons(e,l)) = e
Matei Popovici
Taxonomy
void : List cons : Integer List List extract : List \ {Void} Integer
extract (cons(e,l)) = e
Matei Popovici
Taxonomy
void : List cons : Integer List List extract : List \ {Void} Integer
extract (cons(e,l)) = e
Taxonomy: Nullary constructors External constructors: constructors that use values which do not belong to the datatype at hand
Matei Popovici
Taxonomy
void : List cons : Integer List List extract : List \ {Void} Integer
extract (cons(e,l)) = e
Taxonomy: Nullary constructors External constructors: constructors that use values which do not belong to the datatype at hand Internal constructors
Matei Popovici
Taxonomy
void : List cons : Integer List List extract : List \ {Void} Integer
extract (cons(e,l)) = e
Taxonomy: Nullary constructors External constructors: constructors that use values which do not belong to the datatype at hand Internal constructors: constructors that use only values of the datatype at hand
Matei Popovici
Taxonomy
Let T denote an ADT, and a base constructor of T . Then:
Matei Popovici
Taxonomy
Let T denote an ADT, and a base constructor of T . Then: 0 = { | : T }
Matei Popovici
Taxonomy
Let T denote an ADT, and a base constructor of T . Then: 0 = { | : T } e = { | : A1 . . . An T such that i Ai = T }
Matei Popovici
Taxonomy
Let T denote an ADT, and a base constructor of T . Then: 0 = { | : T } e = { | : A1 . . . An T such that i Ai = T } i = { | : A1 . . . Am T such that j Xj = T }
Matei Popovici
Taxonomy
Matei Popovici
Matei Popovici
Matei Popovici
Matei Popovici
Matei Popovici
Matei Popovici
Matei Popovici
Advantages of circular buffers: no memory handling necessary useful in drivers: 8 bit registers can be used as memory addresses (natural overow)
Matei Popovici
Advantages of circular buffers: no memory handling necessary useful in drivers: 8 bit registers can be used as memory addresses (natural overow) can be easily parallelized (if reads/writes are atomic)
Matei Popovici
Advantages of circular buffers: no memory handling necessary useful in drivers: 8 bit registers can be used as memory addresses (natural overow) can be easily parallelized (if reads/writes are atomic) suitable implementation for Queue (FIFO) of xed size
Matei Popovici
Implementation of the Ring ADT (a rather simpler version, with only one pointer, and unlimited size) - blackboard -
Matei Popovici
Matei Popovici
void : List cons : Integer List List extract : List \ {void} Integer remove : List \ {void} List reverse : List List rev : List List List concat : List List List L : List List Bool (ext) extract(cons(e, l)) = e (rem) remove(cons(e, l)) = l (rev1) rev (l, void) = l (rev2) rev (l1 , cons(e, l2 )) = rev (cons(e, l1 ), l2 ) (rev) reverse(l) = rev (void, l) (con1) concat(void, l) = l (con2) concat(cons(e, l1 ), l2 ) = cons(e, concat(l1 , l2 )) (equivL1) void L void = true (equivL2) void L cons(e, l) = cons(e, l) L void = false (equivL3) cons(e1 , l1 ) L cons(e2 , l2 ) = e1 Integer e2 l1 L l2
Matei Popovici Abstract Data Types
Matei Popovici
empty : Ring ins : Integer Ring Ring del : Ring \ {empty } Ring top : Ring \ {empty } Integer move : Ring \ {empty } Ring isempty : Ring Bool (del) del(ins(e, X )) = X (top) top(ins(e, X )) = e (mov1) move(ins(e, empty )) = ins(e, empty ) (mov2) move(ins(e, ins(f , l))) = ins(f , move(ins(e, l)))
Matei Popovici
Matei Popovici
the same operators as for Ring normalize : IRing IRing : IRing IRing IRing (norm1) normalize(< L, cons(e, R) >) =< L, cons(e : R) > (norm2) normalize(< L, void >) =< void, reverse(L) > (equivR) < L1 , R1 >R < L2 , R2 >= concat(R1 , reverse(L1 )) L concat(R2 , reverse(L2 )) (emptyImpl) empty =impl < void, void > (insImpl) ins(e, < L, R >) =impl < L, cons(e, R) > (delImpl) del(< L, R >) =impl normalize(< L, remove(R) >) (topImpl) top(< L, R >) =impl extract(R) (moveImpl) move(< L, R >) =impl normalize(< cons(extract(R), L), remove(R) >) (isemptyImpl) isEmpty (< L, R >) = null(R)
Matei Popovici
Correctness
Matei Popovici
Correctness
Matei Popovici
Correctness
Matei Popovici
Correctness
Correctness: Verifying whether: (i) certain useful properties of ADTs hold (ii) checking that a data type implementation obeys the ADT specication
Matei Popovici
Matei Popovici
Matei Popovici
Matei Popovici
Matei Popovici
Matei Popovici
an extension of mathematical induction suitable for proving properties of recursively-dened ADTs the induction step (k k + 1) is generalised to a c construction step (d d , where d, d are values of a ADT)
Matei Popovici
Analogy
Assume we have cells with a virus in a container
Matei Popovici
Analogy
Assume we have cells with a virus in a container New cells can be formed by:
Matei Popovici
Analogy
Assume we have cells with a virus in a container New cells can be formed by:
merging
Matei Popovici
Analogy
Assume we have cells with a virus in a container New cells can be formed by:
merging division
Matei Popovici
Analogy
Assume we have cells with a virus in a container New cells can be formed by:
merging division
Matei Popovici
Analogy
cell value of an ADT
Matei Popovici
Analogy
cell value of an ADT with virus property P of the values of the ADT
Matei Popovici
Analogy
cell value of an ADT with virus property P of the values of the ADT division and merging base constructors of the ADT
Matei Popovici
Analogy
cell value of an ADT with virus property P of the values of the ADT division and merging base constructors of the ADT The structural induction scheme (where t1 , . . . tk T ): P(t1 ) . . . P(tk ) P() 0 i P((e)) e e dom() P((. . . , t1 , . . . tk , . . .)) t T , P(t)
Matei Popovici
Examples
- Blackboard -
Matei Popovici
Bibliography I
David J. Eck. Data structures and algorithms. Lecture notes, 2004. Militon Freniu. t Correctness: A very important quality factor in programming. STUDIA UNIV. BABES BOLYAI, INFORMATICA, 2005.
Matei Popovici