Top Banner
Abstract State Machines and Computationally Complete Query Languages Andreas Blass, U Michigan Yuri Gurevich, Microsoft Research & U Michigan Jan Van den Bussche, U Limburg
57

Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Dec 25, 2015

Download

Documents

Milton Rose
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Abstract State Machinesand

Computationally Complete Query Languages

Andreas Blass, U Michigan

Yuri Gurevich, Microsoft Research & U Michigan

Jan Van den Bussche,U Limburg

Page 2: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Outline

• Databases and queries• Query languages:

– whilenew, whilenewsets

– ASMs• Notions of polynomial time• Comparisons

Page 3: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

• Database schema = Finite set of relation names with associated arities

• Database B over = Finite structure over – Finite domain D of atomic values– For each R , a k-ary relation RB on D

Relational databases

Page 4: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

• Database schema = Finite set of relation names with associated arities

• Database B over = Finite structure over – Finite domain D of atomic values– For each R , a k-ary relation RB on D

Relational databases

arity associated to R in

Page 5: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

• Database schema = Finite set of relation names with associated arities

• Database B over = Finite structure over – Finite domain D of atomic values– For each R , a k-ary relation RB on D

E.g. Graph:

Relational databases

arity associated to R in

Page 6: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

• Database schema = Finite set of relation names with associated arities

• Database B over = Finite structure over – Finite domain D of atomic values– For each R , a k-ary relation RB on D

E.g. Graph:

Relational databases

arity associated to R in

1 2

3

4

Page 7: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

• Database schema = Finite set of relation names with associated arities

• Database B over = Finite structure over – Finite domain D of atomic values– For each R , a k-ary relation RB on D

E.g. Graph:

Relational databases

arity associated to R in

1 2

3

4

D

1234

E

(1,2)(2,3)(2,4)(3,4)

Page 8: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Queries

• General definition of query: a (partial, computable) mapping Q– from databases– to relations (of a common arity)

(over a common schema)

Page 9: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Queries

• General definition of query: a (partial, computable) mapping Q– from databases– to relations

Q(B) is the answer to the query Q on database B.

(of a common arity)

(over a common schema)

Page 10: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Queries

• General definition of query: a (partial, computable) mapping Q– from databases– to relations

Q(B) is the answer to the query Q on database B.• Arity 0: {( )} or { } Boolean query

(of a common arity)

(over a common schema)

Page 11: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Queries

• General definition of query: a (partial, computable) mapping Q– from databases– to relations

Q(B) is the answer to the query Q on database B.• Arity 0: {( )} or { } Boolean query

E.g. On a graph:– Give all pairs of nodes that are targets of a

common source.

(of a common arity)

(over a common schema)

Page 12: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Queries

• General definition of query: a (partial, computable) mapping Q– from databases– to relations

Q(B) is the answer to the query Q on database B.• Arity 0: {( )} or { } Boolean query

E.g. On a graph:– Give all pairs of nodes that are targets of a

common source.– Is f(m)=2000?

(of a common arity)

(over a common schema)

Page 13: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Queries

• General definition of query: a (partial, computable) mapping Q– from databases– to relations

Q(B) is the answer to the query Q on database B.• Arity 0: {( )} or { } Boolean query

E.g. On a graph:– Give all pairs of nodes that are targets of a

common source.– Is f(m)=2000?

(of a common arity)

(over a common schema)

number of edges in graph

Page 14: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Queries

• General definition of query: a (partial, computable) mapping Q– from databases– to relations

Q(B) is the answer to the query Q on database B.• Arity 0: {( )} or { } Boolean query

E.g. On a graph:– Give all pairs of nodes that are targets of a

common source.– Is f(m)=2000?

(of a common arity)

(over a common schema)

arbitrary computable function on N

Page 15: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

The consistency criterion

• The answer of a query on a database can depend only on information that is logically contained in that database.

If h is an isomorphism B B, then h is also an isomorphism Q(B) Q(B).

Page 16: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Query languages

• In practice: SQLfirst-order logic + counting, summation, …

E.g. Give all pairs of nodes that are targets of a common source:

Page 17: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Query languages

• In practice: SQLfirst-order logic + counting, summation, …

E.g. Give all pairs of nodes that are targets of a common source:

select E1.target, E2.targetfrom E E1, E E2where E1.source = E2.source

Page 18: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Query languages

• In practice: SQLfirst-order logic + counting, summation, …

E.g. Give all pairs of nodes that are targets of a common source:

select E1.target, E2.targetfrom E E1, E E2where E1.source = E2.source

(x,y) z (E(z,x) E(z,y))

Page 19: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Expressiveness of first-order logic (FO)

• Many useful queries are expressible in FO.• But many others are not:

– Connectivity: Is the graph connected?– Is f(m)=2000, where

if m is even

if m is odd

2000

0f(m) =

Page 20: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Expressiveness of first-order logic (FO)

• Many useful queries are expressible in FO.• But many others are not:

– Connectivity: Is the graph connected?– Is f(m)=2000, where

(parity query)

if m is even

if m is odd

2000

0f(m) =

Page 21: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Towards a complete language: while

• Make FO basis of a small programming language for working with relations:– relation variables (typed by fixed arities)– operations on relations provided by FO– assignment:

X (x1,…,xj)(x1,…,xj)

Page 22: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Towards a complete language: while

• Make FO basis of a small programming language for working with relations:– relation variables (typed by fixed arities)– operations on relations provided by FO– assignment:

X (x1,…,xj)(x1,…,xj)

relation variable of arity j

Page 23: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Towards a complete language: while

• Make FO basis of a small programming language for working with relations:– relation variables (typed by fixed arities)– operations on relations provided by FO– assignment:

X (x1,…,xj)(x1,…,xj)

FO-formula over db relations and relation variables

Page 24: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Towards a complete language: while

• Make FO basis of a small programming language for working with relations:– relation variables (typed by fixed arities)– operations on relations provided by FO– assignment:

X (x1,…,xj)(x1,…,xj)

– sequential composition

Page 25: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Towards a complete language: while

• Make FO basis of a small programming language for working with relations:– relation variables (typed by fixed arities)– operations on relations provided by FO– assignment:

X (x1,…,xj)(x1,…,xj)

– sequential composition– while-loops:

while do … od

Page 26: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Towards a complete language: while

• Make FO basis of a small programming language for working with relations:– relation variables (typed by fixed arities)– operations on relations provided by FO– assignment:

X (x1,…,xj)(x1,…,xj)

– sequential composition– while-loops:

while do … od

FO-sentence

Page 27: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Towards a complete language: while

• Make FO basis of a small programming language for working with relations:– relation variables (typed by fixed arities)– operations on relations provided by FO– assignment:

X (x1,…,xj)(x1,…,xj)

– sequential composition– while-loops:

while do … od• Chandra & Harel [1982]

Page 28: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Example while-program

• Connectivity query:

Seen(2) ;Path(2) E;while Path Seen do

Seen Path;Path Path (x,z) y (Path(x,y) E(y,z));

od.

Page 29: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Example while-program

• Connectivity query:

Seen(2) ;Path(2) E;while Path Seen do

Seen Path;Path Path (x,z) y (Path(x,y) E(y,z));

od.• Parity query:

Page 30: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Example while-program

• Connectivity query:

Seen(2) ;Path(2) E;while Path Seen do

Seen Path;Path Path (x,z) y (Path(x,y) E(y,z));

od.• Parity query: Not!

Page 31: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

A complete language: whilenew

• S. Abiteboul & V. Vianu [1988]• Allow introduction of new domain elements in the

computation.• New operator:

Page 32: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

A complete language: whilenew

• S. Abiteboul & V. Vianu [1988]• Allow introduction of new domain elements in the

computation.• New operator: new

Page 33: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

A complete language: whilenew

• S. Abiteboul & V. Vianu [1988]• Allow introduction of new domain elements in the

computation.• New operator: new

X(3) new R(2)

a bc df g

R

a b c d f g

X

Page 34: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

A complete language: whilenew

• S. Abiteboul & V. Vianu [1988]• Allow introduction of new domain elements in the

computation.• New operator: new

X(3) new R(2)

• Every partial computable query can be programmed in whilenew.

a bc df g

R

a b c d f g

X

Page 35: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Parity in whilenew

1 Easy to check parity of a set S equipped with a successor relation:

Even(0) true;Visit(1) first element of S ;while Visit do

Even Even;Visit succ(x)Visit(x)

od.

Page 36: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Parity in whilenew

2 Make a set S of new elements, one for each edge:

S0 new E;S 3(S0);

Page 37: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Parity in whilenew

3 Compute a successor relation on S:

Impossible!

Page 38: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Parity in whilenew

3 Compute the tree T of all m! successor relations, where m = |S|:

T new ;Seen ;Extend r,xTr Sx;while Extend do

X new Extend;T T 3X; succ succ 1,3X;

Seen Seen n,x n Xn,x,n xx Seenn,x;

Extend n,xn 3X Sx Seen(n,xod.

Page 39: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

We can’t do better!

• whilenew-PSPACE: class of whilenew-programs running in polynomial space.

Theorem: [Abiteboul–Vianu 1991] The parity query cannot be done in whilenew-PSPACE.

• Intuition: In whilenew you cannot make arbitrary choices (recall consistency criterion) Instead of choosing one successor relation, we

must work with them all.

• whilenew-PTIME: class of whilenew-PSPACE-programs running in polynomial time.

Page 40: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

BGS

• Blass, Gurevich, Shelah [1996]:– How can we formalize algorithms that never

have to make arbitrary choices?– What can such algorithms still do in polynomial

time? Instantiation of ASMs for expressing database

queries.

Page 41: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

BGS ASMs

• Universe: HF(D)– every x D is in HF(D);– every finite set of elements of HF(D) is itself in

HF(D).• Infinite, but at any point only finitely many sets are

“active”.• Set-theoretic static functions:

pairing– bounded set-construction

• forall do (parallel ASMs)

Page 42: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Connectivity with a BGS-ASM

if Mode thenforall x D do Frontierx x enddo,Mode

endif,if Mode thenforall x D do

Reachedx := Reachedx FrontierxFrontierx := y D z Frontierx

Ez,y y Reachedx Frontierxenddo,Halt Frontierxx D

endif.

Page 43: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

BGS-PTIME

• BGS-PTIME: class of BGS-ASMs– running for at most polynomially many steps– constructing at most polynomially many sets

• “Choiceless polynomial time”

Page 44: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

BGS-PTIME versus whilenew-PTIME?

• Structure In :

• • •• • •

n n

Page 45: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

BGS-PTIME versus whilenew-PTIME?

• Structure In :

• There is a PTIME BGS-program that outputs:

• • •• • •

n n

Page 46: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

BGS-PTIME versus whilenew-PTIME?

• Structure In :

• There is a PTIME BGS-program that outputs:

– true on every In with n even;

• • •• • •

n n

Page 47: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

BGS-PTIME versus whilenew-PTIME?

• Structure In :

• There is a PTIME BGS-program that outputs:

– true on every In with n even;

– false odd.

• • •• • •

n n

Page 48: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

BGS-PTIME versus whilenew-PTIME?

• Structure In :

• There is a PTIME BGS-program that outputs:

– true on every In with n even;

– false odd. (Just construct all red subsets of even size.)

• • •• • •

n n

Page 49: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

BGS-PTIME versus whilenew-PTIME?

• Structure In :

• There is a PTIME BGS-program that outputs:

– true on every In with n even;

– false odd. (Just construct all red subsets of even size.)

Theorem: There is no such PSPACE whilenew-program (let alone PTIME).

• • •• • •

n n

Page 50: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Sets versus lists

• BGS programs can construct sets.

• whilenew programs can only construct lists.

– operator new works tuple- ( list-) based.• Lists are ordered; sets can be unordered.• If you want to simulate something unordered by

something ordered, you have to work with all orders.

– (Recall parity in whilenew.)

BGS-PTIME strictly encompasses whilenew-PTIME.

Page 51: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

The language whilenewsets

• Theory of object-based query languages, studied late 80s – early 90s.

• Operator new from whilenew is really tuple-new.

We need also a set-new! Language whilenew

sets

Page 52: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

set-new

Y set-new R

a d

a e

b e

b d

c e

c f

c g

R

Page 53: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

set-new

Y set-new R

a d

a e

b e

b d

c e

c f

c g

R

Page 54: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

set-new

Y set-new R

a d

a e

b e

b d

c e

c f

c g

R

Page 55: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

set-new

Y set-new R

a d

a e

b e

b d

c e

c f

c g

R

a

b

c

Y

Page 56: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Equivalence results

• whilenewsets and BGS can simulate each other.

• Simulation:– linear step overhead– polynomial space overhead

BGS-PTIME whilenewsets-PTIME whilenew-PTIME

Page 57: Abstract State Machines and Computationally Complete Query Languages Andreas Blass,U Michigan Yuri Gurevich,Microsoft Research & U Michigan Jan Van den.

Concluding remarks

• ASMs and query languages are quite related, and share the common concern of computation on the “logical” level.

• Purely mathematically,– basic parallel ASMs

– whilenew

are essentially the same thing.• ASMs clearly win from query languages in flexibility,

appeal to practitioners, developed philosophy, and people like Yuri and Egon.

• whilenew never “escaped” database theory!

• Challenge: the Web (querying XML, WWW, …)