Map Coloring with Logic Two Formulations of Map Coloring - PowerPoint PPT Presentation

About This Presentation
Title:

Map Coloring with Logic Two Formulations of Map Coloring

Description:

Title: PowerPoint Presentation Author: Tim Hinrichs Last modified by: Tim Hinrichs Created Date: 12/11/2005 8:04:29 PM Document presentation format – PowerPoint PPT presentation

Number of Views:232
Avg rating:3.0/5.0
Slides: 104
Provided by: TimHin9
Learn more at: https://www.cs.uic.edu
Category:

less

Transcript and Presenter's Notes

Title: Map Coloring with Logic Two Formulations of Map Coloring


1
Map Coloring with LogicTwo Formulations of Map
Coloring
  • Tim Hinrichs
  • Stanford Logic Group

2
Map Coloring
3
Map Coloring
  • Color the nodes of the graph so that
  • no two adjacent nodes are the same color

4
Map Coloring
  • Color the nodes of the graph so that
  • no two adjacent nodes are the same color

5
Student Formulation
  • Premises
  • color(X,C) gt region(X)
  • color(X,C) gt hue(C)
  • adjacent(X1,X2) color(X1,C) gt -color(X2,C)
  • region(X) gt ?Y.color(X,Y)
  • ltground atoms for adjacent, region, huegt
  • Query
  • TUVXYZ color(r1,T) color(r2,U) color(r3,V)

- This is not the formulation used in the CSP/LP
literature. - LP engines today do not understand
this formulation.
6
Logic Programming Formulation
  • Axioms
  • next(red,blue)
  • next(red,green)
  • next(red,yellow)
  • next(blue,red)
  • next(blue,green)
  • Query
  • R1 R2 R3 R4 R5 R6 next(R1,R2) next(R1,R3)
    next(R1,R5)
  • next(R1,R6) next(R2,R3)
    next(R2,R4)
  • next(R2,R5) next(R2,R6) next(R3,R4)
  • next(R3,R6) next(R5,R6)

This is the typical formulation used in the
literature. This form (deductive) is required by
LP.
7
Map Coloring with Logic
  • Two formulations
  • The one students produce in CS157 every year
  • The one used in the literature McCarthy82
  • (1) is more natural (and non-deductive)
  • (2) is more efficient (and deductive)
  • Question for the day
  • How do we translate (1) into (2)?

8
Agenda
  1. Consistency to Deduction Reformulate
    non-deductive problem into deductive problem (a
    form of closing a theory)
  2. Database Reformulation turn output of (1) into
    the Logic Programming formulation.
  3. Bilevel Reasoning speeding up (1)

9
Running Example
  • Example a very simple graph and two colors
  • 3 nodes, 2 edges
  • red and blue

Problem
Solutions
10
Constraint Satisfaction
  • Definition (Constraint Satisfaction Problem)
  • Input
  • ltV, DV, CVgt
  • V set of variables v1,v2,
  • DV domain for each variable -- dom(vi)
  • CV constraints on values of variables
  • Output Assignment of values to variables so that
  • 1. val(vi) in dom(vi)
  • 2. all the constraints are satisfied

11
Map Coloring as a CSP
  • Variables (V) nodes
  • Domains (DV) same for each variable
  • for every i, dom(vi) the set of colors
  • Constraints (CV) mathematically, a set of
    permissible tables, i.e. for every pair of
    variables x and y, a table for all the allowed
    values of x and y.

12
Example
r1 r2 r3
  • V R1, R2, R3
  • DV
  • dom(R1) r, b
  • dom(R2) r, b
  • dom(R3) r, b

R1 R2
r b
b r
R2 R3
r b
b r
CV
13
Example Solution
r1 r2 r3
  • V R1, R2, R3
  • DV
  • dom(R1) r, b
  • dom(R2) r, b
  • dom(R3) r, b

R1 R2
r b
b r
R2 R3
r b
b r
CV
14
All Solutions
r1 r2 r3
  • V R1, R2, R3
  • DV
  • dom(R1) r, b
  • dom(R2) r, b
  • dom(R3) r, b

R1 R2
r b
b r
R2 R3
r b
b r
CV
15
All Solutions as a DB Query
r1 r2 r3
  • The set of all solutions can also be computed
    using the natural join operator.

R1 R2
r b
b r
R2 R3
r b
b r
R1 R2 R3
r b r
b r b

16
Constraint Representations
  • Representing constraints as permissible tables
    can be expensive and cumbersome.
  • Often, constraints are more naturally and
    economically represented as logical sentences.

17
Student Formulation
  • Premises
  • color(X,C) gt region(X)
  • color(X,C) gt hue(C)
  • adjacent(X1,X2) color(X1,C) gt -color(X2,C)
  • region(X) gt ?Y.color(X,Y)
  • adjacent(r1,r2) adjacent(r2,r3) hue(r)
    hue(b)
  • region(r1) region(r2) region(r3)
  • Entailment Query
  • XYZ color(r1,X) color(r2,Y) color(r3,Z)
  • ?
  • Models

18
Student Formulation
  • Premises
  • color(X,C) gt region(X)
  • color(X,C) gt hue(C)
  • adjacent(X1,X2) color(X1,C) gt -color(X2,C)
  • region(X) gt ?Y.color(X,Y)
  • adjacent(r1,r2) adjacent(r2,r3) hue(r)
    hue(b)
  • region(r1) region(r2) region(r3)
  • Build a model
  • XYZ color(r1,X) color(r2,Y) color(r3,Z)
  • ?
  • Models

19
Logic Programming Formulation
  • Is different than the student formulation
  • McCarthy82 borrowed from Pereira and Porto
    1980
  • McCarthy started with their formulation and
    showed various reformulations that improved
    efficiency.
  • Served as an exploration of Kowalskis doctrine
  • Algorithm Logic Control
  • Originally used to illustrate issues in
    Constraint Satisfaction/Logic Programming

20
LP Formulation
  • Axioms
  • next(r,b)
  • next(b,r)
  • Entailment query
  • R1 R2 R3 next(R1,R2) next(R2,R3)

r1 r2 r3
Deductive
21
Problem Statement
  • Produce an algorithm that converts
  • Axioms
  • color(X,C) gt region(X)
  • color(X,C) gt hue(C)
  • adjacent(X1,X2) color(X1,C) gt -color(X2,C)
  • region(X) gt ?Y.color(X,Y)
  • Build Model XYZ color(r1,X) color(r2,Y)
    color(r3,Z)
  • into
  • Axioms
  • next(red,blue)
  • next(blue,red)
  • Entailment Query XYZ next(X,Y) next(Y,Z)

22
Herbrand Logic
  • Assume no function constants
  • The axioms include a
  • DCA over all ground terms
  • UNA over all ground terms
  • Assume these hold implicitly
  • Finite Herbrand Logic

23
An Observation Student
  • color(X,C) gt region(X)
  • color(X,C) gt hue(C)
  • adjacent(X,Y) color(X,C) gt -color(Y,C)
  • Write the last with V instead of gt
  • -adjacent(X,Y) V -color(X,C) V -color(Y,C)
  • Except for typing, these constraints are entirely
    negative
  • Entail what colorings are invalid.
  • Every other coloring is valid.

24
Student Colorings
  • adjacent(X,Y) color(X,C) gt -color(Y,C)
  • Invalid answers (entailed)
  • XYZ -(color(r1,X) color(r2,Y)
    color(r3,Z))
  • Remaining answers


25
Idea
  • To reformulate from Student to LP,
  • Compute all invalid colorings (which are
    entailed).
  • Compute the complement of that set.



26
Implementation
  • ? the set of Student constraints
  • Query color(r1,X) color(r2,Y) color(r3,Z)
  • Reify the notion of an invalid coloring.
  • () invalid(X,Y,Z) ltgt
  • -(color(r1,X) color(r2,Y)
    color(r3,Z))
  • Ask for all the invalid colorings that are
    logically entailed.
  • XYZ ? () invalid(X,Y,Z)

27
Implementation
  • XYZ invalid(X,Y,Z)
  • The following expression is logically entailed
    and represents the set of all invalid colorings
  • Xr1 v Xr2 v Xr3 v
  • Yr1 v Yr2 v Yr3 v
  • Zr1 v Zr2 v Zr3 v
  • XY v YZ

X Y Z
28
Implementation
  • To compute an expression that represents the
    complement of that set, it turns out that all we
    need to do is negate that expression.
  • X?r1 X?r2 X?r3
  • Y?r1 Y?r2 Y?r3
  • Z?r1 Z?r2 Z?r3
  • X?Y Y?Z
  • The above (with unique names axioms) entails all
    the valid colorings.

X Y Z
29
Progress Both are deductive
  • Student after reformulation all deductive
    answers to
  • XYZ X?r1 X?r2 X?r3
  • Y?r1 Y?r2 Y?r3
  • Z?r1 Z?r2 Z?r3
  • X?Z Y?Z
  • UNAr,b,r1,r2,r3
  • LP formulation all deductive answers to
  • XYZ next(X,Y) next(Y,Z)
  • next(r,b)
  • next(b,r)

X Y Z
30
Student as Database Query
?
  • Because Student is now a query over a complete
    theory (?), it can be viewed as a DB query.
  • XYZ
  • X?r1 X?r2 X?r3
  • Y?r1 Y?r2 Y?r3
  • Z?r1 Z?r2 Z?r3
  • X?Z Y?Z

r1 r2
r1 r3
r1 r
r1 b
r2 r1
r2 r3
r2 r
r2 b
r3 r1

31
Database Reformulation
  • Given one database query, find an equivalent
    query that is more efficient.
  • Includes performing transformations on the data
    itself, with a space limit.
  • Theorem Chirkova There are infinitely many
    distinct transformations.
  • Theorem Chirkova There is an algorithm that
    given the query constructs a finite space of
    queries that is guaranteed to include the optimal
    one.

32
Back to Map Coloring
  • Given the query
  • X?r1 X?r2 X?r3 Y?r1 Z?r3 X?Y Y?Z
  • one of the transformations Chirkovas work
    considers is
  • view(X,Y) lt X?r1 X?r2 X?r3
  • Y?r1 Y?r2 Y?r3
  • X?Y
  • which can be used to rewrite the above query as
  • view(X,Y) view(Y,Z)

33
Comparison
  • Student
  • XYZ view(X,Y) view(Y,Z)
  • view(r,b)
  • view(b,r)
  • Logic Programming
  • XYZ next(X,Y) next(Y,Z)
  • next(r,b)
  • next(b,r)

34
Overview
  • Starting with the Student formulation,
  • XYZ color(r1,X) color(r2,Y) color(r3,Z)
  • color(X,C) gt region(X)
  • color(X,C) gt hue(C)
  • adjacent(X1,X2) color(X1,C) gt -color(X2,C)
  • use logical entailment to find an expression for
    all the invalid colorings and negate it.
  • XYZ X?r1 X?r2 X?r3 X?Y Y?Z
  • Then apply Chirkovas work to produce the LP
    formulation, or one that is at least as good as
    LP.
  • XYZ view(X,Y) view(Y,Z)

35
Another Example
  • N-Queens place N queens on an NxN chessboard
    s.t.
  • No queen can be attacked by another queen.
  • That is
  • No two queens share the same row
  • No two queens share the same column
  • No two queens share the same diagonal

36
8 Queens Solution
37
N-Queens Constraints
  • All queens in different rows
  • X?Y row(X,R) gt -row(Y,R)
  • All queens in different columns
  • X?Y col(X,C) gt -col(Y,C)
  • All queens in different diagonals
  • X?Y diag(X,D1,D2)
  • gt -diag(Y,D1,D2)

38
N-Queens Diagonals
  • Row, Col is enough to compute the two diagonals
  • diag(X,pos,D) lt
  • row(X,R) col(X,C)
  • sub(C, R, D)
  • diag(X,neg,D) lt
  • row(X,R) col(X,C)
  • add(C, R, D)
  • Diagonals represented by their slope and
    y-intercepts

4
3
2
1
0
39
4 Queens Query
  • Satisfiability Query
  • (X1 Y1 X2 Y2 X3 Y3 X4 Y4)
  • row(q1,X1) col(q1,Y1)
  • row(q2,X2) col(q2,Y2)
  • row(q3,X3) col(q3,Y3)
  • row(q4,X4) col(q4,Y4)

40
Efficiency in N-Queens
  • The expression that represents all invalid
    positions can become quite large and might take a
    long time to compute because of the add and sub
    facts.
  • About 150 conjuncts
  • Idea produce an expression in terms of add and
    sub, as well as .

41
Bilevel Reasoning
  • Separate constraints from data.

X?Y row(X,R) gt -row(Y,R) X?Y col(X,C) gt
-col(Y,C) X?Y diag(X,D1,D2) gt
-diag(Y,D1,D2) diag(X,pos,D) lt row(X,R)
col(X,C) sub(C, R, D) diag(X,neg,D) lt row(X,R)
col(X,C) add(C, R, D) add(1,1,2) add(1,1,3) ..
. add(4,4,8) sub(1,1,0) sub(1,2,-1) ... sub(4,4,0)

42
Bilevel Reasoning
  • Separate constraints from data.

X?Y row(X,R) gt -row(Y,R) X?Y col(X,C) gt
-col(Y,C) X?Y diag(X,D1,D2) gt
-diag(Y,D1,D2) diag(X,pos,D) lt row(X,R)
col(X,C) sub(C, R, D) diag(X,neg,D) lt row(X,R)
col(X,C) add(C, R, D) add(1,1,2) add(1,1,3) ..
. add(4,4,8) sub(1,1,0) sub(1,2,-1) ... sub(4,4,0)

43
Bilevel Reasoning
  • Separate constraints from data.

X?Y row(X,R) gt -row(Y,R) X?Y col(X,C) gt
-col(Y,C) X?Y diag(X,D1,D2) gt
-diag(Y,D1,D2) diag(X,pos,D) lt row(X,R)
col(X,C) sub(C, R, D) diag(X,neg,D) lt row(X,R)
col(X,C) add(C, R, D)
add(1,1,2) add(1,1,3) ... add(4,4,8) sub(1,1,0) su
b(1,2,-1) ... sub(4,4,0)
44
Implementation
  • ? the set of n-queens constraints w/o
    add/sub
  • Query row(q1,X1) col(q2,Y1) row(q3,X2)
    ...
  • Reify the notion of an invalid coloring.
  • () invalid(X1,Y1,X2,Y2,X3,Y3,X4,Y4) ltgt
  • -(row(q1,X1) col(q2,Y1) row(q3,X2)
    ...)
  • Ask for all the invalid colorings where add/sub
    can be assumed, i.e. use residues (a form of
    abduction).
  • XYZ ? () invalid(X,Y,Z)

45
4-Queens Partial Reformulation
  • goal(X1,Y1,X2,Y2,X3,Y3,X4,Y4) lt
  • X1 ? X2
  • Y1 ? Y2
  • (-sub(Y2,X2,Z) v -sub(Y1,X1,Z))
  • (-add(Y2,X2,Z)) v -add(Y1,X1,Z))
  • X1 ? X3
  • Y1 ? Y3
  • X2 ? X3
  • Y2 ? Y3
  • (-sub(Y3,X3,Z) v -sub(Y1,X1,Z))
  • (-sub(Y3,X3,Z) v -sub(Y2,X2,Z))
  • (-add(Y3,X3,Z) v -add(Y1,X1,Z))
  • (-add(Y3,X3,Z) v -add(Y2,X2,Z))
  • ...

46
Consistency to Deduction
  • Computing the sentences that are consistent with
    the premises and making them deductive
    consequences.
  • Definition (query consistency to deduction)
  • qC2D?, ?(xbar)
  • tbar ? ? ?(tbar) is satisfiable
  • In map coloring,
  • ? the set of map coloring axioms
  • ?(xbar) color(r1,X) color(r2,Y) color(r3,Z)
  • qC2D ltr,b,rgt, ltb,r,bgt

47
Descriptions
  • Definition (Description) e(xbar) is a
    description for the set of n-tuples S, where
    xbar n if and only if
  • e(tbar) if tbar ? S
  • -e(tbar) if tbar ? S
  • Example XY V YZ describes
    rrr,rrb,brr,bbr,rbb,bbb in FHL
  • H rr V rr H rr V rb H br V rr
  • H bb V br H rb V bb H bb V bb
  • and
  • H -(rb V br)
  • H -(br V rb)

48
Algorithm
  • Input
  • ? a finite set of FHL sentences
  • ?(xbar) a query in the vocabulary of Delta
  • Using algorithm Alg, compute an expression
    e(xbar) in terms of equality such that for any
    model M in R,
  • M e(tbar) if and only if ? -?(tbar)
  • Output -e(xbar)

49
Theorems
  • Theorem (Soundness and Completeness)
  • Let Alg(?, ?(xbar)) -e(xbar).
  • M -e(tbar) if and only if ?(tbar) ? qC2D?,
    ?(xbar)
  • Proof Nontrivial
  • Theorem (Decidability) qC2D?, ?(xbar) for FHL
    is decidable.
  • Proof Walk over Herbrand models and if M ? ,
    collect all tbar s.t. M ?(tbar)

50
Relationship to CWA
  • CWA? includes -p(tbar) whenever ? p(tbar)
  • CWA? ? ? is inconsistent whenever
  • Delta entails some disjunction d1 v v dn and
  • Delta entails none of the di.
  • Adding the map coloring answers to the Student
    formulation is inconsistent.

51
Relationship to CWA
  • Student axioms entail a disjunctive answer
  • color(r1,b) color(r2,r) color(r3,b)
  • v
  • color(r1,r) color(r2,b) color(r3,r)
  • but they entail neither disjunct alone.
  • Adding both answers to the axioms produces an
    inconsistency
  • color(r1,b) (by the first answer) and
  • color(r2,b) (by the second answer)

52
Relationship to CWA
  • CWA for every ground p, add -p if p is not
    entailed.
  • C2D for every ground p, add p if -p is not
    entailed.

53
Map Coloring with Logic
  • McCarthy82 McCarthy. Coloring Maps and the
    Kowalski Doctrine. Stanford Tech Report 1982.
  • Pereira80 Pereira and Porto. Selective
    Backtracking for Logic Programs. CADE 1980.
  • Chirkova2002 Chirkova. Automated Database
    Restructuring. Stanford thesis 2002.

54
Scrap starts here
55
Bilevel Reasoning
  • Separate constraints from data.

color(X,C) gt region(X) color(X,C) gt
hue(C) adjacent(X1,X2) color(X1,C) gt
-color(X2,C) adjacent(r1,r2) adjacent(r2,r3) hue(r
) hue(b) region(r1) region(r2) region(r3)
56
Bilevel Reasoning
  • Separate constraints from data.

color(X,C) gt region(X) color(X,C) gt
hue(C) adjacent(X1,X2) color(X1,C) gt
-color(X2,C) adjacent(r1,r2) adjacent(r2,r3) hue(r
) hue(b) region(r1) region(r2) region(r3)
57
Bilevel Reasoning
  • Separate constraints from data.

58
Bilevel Map coloring
  • It turns out that separating hue off from the
    rest of the axioms is an interesting case.

color(X,C) gt region(X) color(X,C) gt
hue(C) adjacent(X1,X2) color(X1,C) gt
-color(X2,C) adjacent(r1,r2) adjacent(r2,r3) regio
n(r1) region(r2) region(r3)
59
Partial Reformulation
  • The algorithm presented earlier started with
    axioms talking about hues, regions, adjacency,
    and color
  • adjacent(X,Y) color(X,C) gt -color(Y,C)
  • to produce
  • XYZ X?r1 X?r2 X?r3
  • Y?r1 Y?r2 Y?r3
  • Z?r1 Z?r2 Z?r3
  • X?Z Y?Z
  • but if we separate hue we should get the
    following result
  • XYZ hue(X) hue(Y) hue(Z) X?Y Y?Z

60
Implementation
  • Epilog (the Logic Groups theorem prover)
    produces an expression that represents the set of
    all invalid colorings, in terms of hue
  • XYZ invalid(X,Y,Z), wrt hue
  • gt -hue(X) v -hue(Y) v -hue(Z) v XY v YZ
  • Negating (just as before) gives us
  • hue(X) hue(Y) hue(Z) X?Y Y?Z

61
Database Reformulation
  • Given a schema R and a set of queries
    QQ1,,Qn
  • Compute a set of views on R that minimize the
    cost of evaluating all the Qi.
  • (Each relation in R is assigned a size.)
  • Rada Chirkova Chirkova2002 conjunctive
    queries.
  • Decidable.
  • Triply exponential upper bound (in Q).
  • Exponential lower bound (in Q).

62
Database Reformulation
Find views V on R producing schema T such that
Eval(Q,T) lt Eval(Q,R)
Viewset V
R
T
63
Example
  • Schema parent(x,y)
  • Query XY samefamily(X,Y)
  • samefamily(X,Y) lt anc(X,Z) anc(Y,Z)
  • anc(X,Y) lt parent(X,Y)
  • anc(X,Y) lt anc(X,Z) anc(Z,Y)
  • Can be evaluated more efficiently as
  • samefamily(X,Y) lt
  • foundingfather(X,F) foundingfather(Y,F)

64
Map Coloring in Math
  • 1852 Guthrie makes Four Colour Conjecture
  • Any planar graph can be colored using only four
    colors.
  • Definition(Planar graph) Graph that can be drawn
    on the plane without edges crossing.
  • Incorrect proofs given by Kempe (1879) and Tait
    (1880). Kempes was accepted for over a decade.
  • 1977 Appel and Haken wrote a program to
    exhaustively check a large number of cases. They
    (debatably) proved the conjecture.

65
Map Coloring in AI
  • Used to illustrate Constraint Satisfaction
    techniques, e.g. Russell and Norvig
  • Trying to color a particular graph
  • Not trying to show every graph with particular
    characteristics can be colored.

66
Student Formulation (2)
  • Premises
  • color(X,C) gt region(X)
  • color(X,C) gt hue(C)
  • adjacent(X1,X2) color(X1,C) gt -color(X2,C)
  • adjacent(r1,r2) adjacent(r2,r3) hue(r)
    hue(b)
  • region(r1) region(r2) region(r3)
  • Build a model

67
DB Reformulation Again
  • Given the query
  • hue(X) hue(Y) hue(Z) X?Y Y?Z
  • one of the views Radas work considers is
  • view(X,Y) lt hue(X) hue(Y) X?Y
  • which can be used to rewrite the above query as
  • view(X,Y) view(Y,Z)

68
Back to Map coloring
  • In Student, the schema consists of a single
    relation ?.
  • The query
  • XYZ X?r1 X?r2 X?r3
  • Y?r1 Y?r2 Y?r3
  • Z?r1 Z?r2 Z?r3
  • X?Z Y?Z
  • Unfortunately, this query includes constants,
    which Radas work does not cover.
  • Notice that this query is defined in terms of
    -hue.

X Y Z
69
Efficiency
  • It is unsettling and inefficient to have the
    answer defined in terms of -hue when it is more
    natural to define it in terms of hue.
  • hue(X)
  • hue(Y)
  • hue(Z)
  • X ? Y
  • Y ? Z
  • Independent of which colors are available
  • No constants

X Y Z
70
A Technical Note about Descriptions
  • e(X,Y,Z) ltgt XY V YZ
  • describes S rrr,rrb,brr,bbr,rbb,bbb
  • For every tuple tbar in S, H e(tbar)
  • For every tuple tbar not in S, H -e(tbar)
  • In Herbrand logic, suppose we know that
  • H e(tbar) implies tbar in S
  • e(xbar) is built on a single relation constant
    .
  • Then e(xbar) is a description of S.

71
Issues
  • Need efficient algorithm for computing all
    solutions in FHL that terminates.
  • Would settle for termination on clausal form.
  • OSHLZhu,Plaisted
  • Model EvolutionBaumgartner
  • Computing the complement via negation worked well
    for map coloring, but in general it may be
    expensive when converting to clausal form (CNF to
    DNF).

72
An Observation about McCarthy
  • XYZ next(X,Y) next(Y,Z)
  • The valid colorings are entailed

73
Complexity Analysis
  • CS157
  • hue(X) hue(Y) hue(Z) X?Y Y?Z
  • hue(red) red ? blue
  • hue(blue) blue ? red
  • McCarthy
  • next(X,Y) next(Y,Z)
  • next(red,blue)
  • next(blue,red)
  • Compare on trees. C of colors, N of nodes

74
Asymptotic Complexity Results for Trees
  • hue(X) hue(Y) hue(Z) X?Y Y?Z
  • O(CN)
  • hue(X) hue(Y) X?Y hue(Z) Y?Z
  • O(CN-1)
  • next(X,Y) next(Y,Z)
  • O(CN-2)
  • Same as 3 but indexed on first argument of next.
  • O(CN-3)

75
Back to FOL
  • If we are using first-order deduction procedures
    to answer finite Herbrand entailment queries,
    need a DCA and UNA.
  • Reiter80 showed that for ? queries, DCA is
    unnecessary.

76
Looks can be deceiving
  • Suppose there were object constants besides red
    and blue, e.g. paperclip
  • New axioms
  • -r1(X) V -r2(X)
  • -r3(X) V -r2(X)
  • r1(X) V r2(X) V r3(X) gt hue(X)
  • hue(red)
  • hue(blue)
  • -hue(paperclip)

77
Running the algorithm
  • After conversion
  • goal(X,Y,Z) ltgt
  • X ? paperclip
  • X ? Y
  • Y ? paperclip
  • Y ? Z
  • Z ? paperclip
  • Linear in the size of -hue(x)
  • Not the same as the McCarthy formulation

78
Solving CSPs as DB queries
  • Can every CSP be formulated as a DB query?
  • Map coloring can be formulated as a DB query.
  • When is it beneficial to solve a CSP by
    translating it into a DB query?
  • Under some conditions, it is beneficial for map
    coloring.
  • Can the transformation be automated?

79
Language of Study
  • Option 1 (Mathematics) Explore algorithms of the
    following sort.
  • Input ltV, DV, CVgt, i.e. a set, a set of
    functions, and a set of tables.
  • Output ltD, ?(x1,,xn)gt, i.e. a database and a
    query over that database.
  • Option 2 (Logic) Explore algorithms of the
    following sort.
  • Input Description of a CSP in logic.
  • Output Description of the database and the query
    in logic.

80
CS157 Orderings
  • hue(X) hue(Y) hue(Z) X?Y Y?Z
  • Walk hue space and check each point.
  • X?Y Y?Z hue(X) hue(Y) hue(Z)
  • Walk ? space and check each point.
  • hue(X) hue(Y) X?Y hue(Z) Y?Z
  • Walk hue space, pruning as we go.
  • X?Y hue(X) hue(Y) Y?Z hue(Z)
  • Walk ? space, pruning as we go.

81
On the Complexity of Query Evaluation
  • Complexity depends heavily on indexing.
  • Four options
  • Relational index only on the relation of facts
  • Relational attach eval ? in code
  • Arguments index on reln and each argument
    position
  • Arguments attach

82
Some Connections
  • Some connections to other work
  • CWA
  • Applicability to Datalog queries

83
Closed World Assumption
  • qC2D and CWA are closely related
  • In fact, a generalization of qC2D and CWA are
    nearly equivalent.
  • If we could compute CWA efficiently, that might
    help us compute qC2D efficiently.

84
A Property of qC2D
  • Consider adding our solutions to the map coloring
    axioms.
  • -r1(X) lt r2(X)
  • -r2(X) lt r3(X)
  • r1(r) r2(b) r3(r)
  • r1(b) r2(r) r3(b)
  • These axioms are inconsistent.
  • Very similar to the inconsistency that can be
    produced by Closed World Assumption.

85
Closed World
  • Definition (Set-based CWA) Let Pp1,,pn be a
    set of closed sentences.
  • sCWA?, P -pi ? pi
  • Example
  • ? q(a), q(b)
  • P q(a), q(c)
  • sCWA?, P -q(c)
  • sCWA generalizes the standard definition for CWA

86
sC2D
  • For comparison to sCWA, we define sC2D.
  • Definition (sC2D) Let Pp1,,pn be a set of
    sentences.
  • sC2D?, P pi ? ? pi is satisfiable
  • Theorem Let p1,,pn be a set of ground atoms.
  • sCWA?, p1,,pn sC2D?, -p1,,-pn

87
An Application
  • Suppose we have some set of Datalog sentences and
    a negative query.
  • - not r(X), not s(Y), not p(Z)
  • One approach
  • goal(X,Y,Z) - univ(X), univ(Y), univ(Z),
  • not r(X), not s(Y), not p(Z)
  • Cost univ3
  • If we had an explicit definition for the negative
    theory, the cost might be substantially less.

88
An Application (2)
  • Data
  • p(a,b) p(b,a) p(c,a) p(d,a)
  • p(a,c) p(b,c) p(c,b) p(d,b)
  • p(a,d) p(b,d) p(c,d) p(d,c)
  • Query univ(X), univ(Y), not p(X,Y)
  • Cost univ2
  • Query univ(X), not p(X,X)
  • Cost univ

89
Computing the Complement
  • In Map Coloring
  • Expression for invalid colors
  • XY V YZ
  • Negation of that expression
  • XY YZ
  • Final reformulation
  • goal(X,Y,Z) lt XY YZ
  • More generally
  • Expression for entailed negations of query
  • ?(xbar)
  • Negation of that expression
  • -?(xbar)
  • Final reformulation
  • goal(xbar) lt -?(xbar)

90
Questions
  • Every relation in a theory with a DCA can be
    defined entirely in terms of equality.
  • Question When can we use fullfinds to compute
    that definition? (logically justified)
  • Question When should we use fullfinds to compute
    that definition? (computability/complexity
    justified)

91
Consistency
  • No coloring of the map is entailed by the axioms.
  • But both colorings are consistent with the
    axioms.
  • How do we compute consistency?
  • With a DCA, consistency is decidable.
  • How do we compute consistency efficiently?
  • Sort of sounds like abduction.

92
Abduction
  • Definition (Abduction) ? explains ? ? in the
    language L if and only if
  • ? ? ? ?
  • ? ? ? is consistent
  • ? is in L
  • Let ? be the map coloring axioms
  • r1(r) r2(b) r3(r) explains
  • ? ?XYZ. r1(X) r2(Y) r3(Z)

93
Attempt 3
  • Residue attempts to compute abductive
    consequences
  • -r1(X) lt r2(X)
  • -r2(X) lt r3(X)
  • goal(X,Y,Z) lt r1(X) r2(Y) r3(Z)
  • ? (fullresidue '(goal ?x ?y ?z) 'mapc)
  • Call (GOAL ?X ?Y ?Z)
  • Call (R1 ?X)
  • Fail (R1 ?X)
  • Fail (GOAL ?X ?Y ?Z)
  • Equality does not help.

94
An observation
  • The constraints only talk about the negative part
    of the theory.
  • -r1(X) lt r2(X) or -r1(X) -r2(X)
  • -r2(X) lt r3(X) or -r2(X) -r3(X)
  • The query only talks about the positive part of
    the theory.
  • ?XYZ. r1(X) r2(Y) r3(Z)
  • If we could define the negative part of the
    theory and then negate it, we would have an
    explicit definition for the positive theory, on
    which we could use entailment tools.

95
Reformulation and Completion
  • Temporarily add the goal to the original axioms.
  • -r1(X) lt r2(X)
  • -r2(X) lt r3(X)
  • goal(X,Y,Z) ltgt r1(X) r2(Y) r3(Z)
  • Capture the negative query in terms of equality.
  • -goal(X,Y,Z) lt XY YZ
  • Apply predicate completion
  • -goal(X,Y,Z) ltgt XY YZ
  • goal(X,Y,Z) ltgt XY YZ
  • Assuming UNAxioms, ask for goal(X,Y,Z).

96
Step 4
  • goal(X,Y,Z) lt XY YZ
  • r b
  • b r
  • ? (fullfindx '(?x ?y ?z) '(goal ?x ?y ?z) 'mapcc)
  • Call (GOAL ?X ?Y ?Z)
  • Call (NOT ( ?X ?Y))
  • Exit (NOT ( R B))
  • Call (NOT ( B ?Z))
  • Exit (NOT ( B R))
  • Exit (GOAL R B R)

97
Step 2
  • -r1(X) lt r2(X)
  • -r2(X) lt r3(X)
  • goal(X,Y,Z) lt r1(X) r2(Y) r3(Z)
  • -goal(X,Y,Z) lt -r1(X)
  • -goal(X,Y,Z) lt -r2(X)
  • -goal(X,Y,Z) lt -r3(X)
  • r1(X) lt goal(X,Y,Z)
  • r2(Y) lt goal(X,Y,Z)
  • r3(Z) lt goal(X,Y,Z)
  • ? (fullfinds '(?x ?y ?z) '(not (goal ?x ?y ?z))
    'mapc)
  • ((?u ?u ?w) (?u ?w ?w))

98
Back to the CSP Version
goal(X,Y,Z) lt XY YZ r b b r
  • V v1,v2,v3
  • DV r, b,r, b,r, b
  • CV

v1 v2
r b
b r
v2 v3
r b
b r
99
CS157 Formulation (3)
  • Premises Models
  • Xred Xblue
  • -r1(X) lt r2(X)
  • -r2(X) lt r3(X)
  • ?X.r1(X)
  • ?X.r2(X)
  • ?X.r3(X)
  • Satisfaction Query XYZ r1(X) r2(Y) r3(Z)
  • All resolution-style t.p. return something like

In general, adding these sentences may cause
inconsistency.
k1, k2, k3
100
Example
  • V v1,,v7
  • DV
  • dom(v1) r,y,b
  • dom(v7) r,y,b

v1 v2
r y
r b
y b
y r
b y
b r
v6 v7
r y
r b
y b
y r
b y
b r
CV ,,
101
Example
  • V v1,,v7
  • DV
  • dom(v1) r,y,b
  • dom(v7) r,y,b

v1 v2
r y
r b
y b
y r
b y
b r
v6 v7
r y
r b
y b
y r
b y
b r
CV ,,
102
Pereira, Porto, and McCarthy
  • Peireira and Porto 1980 treated map coloring in
    the context of Logic Programming
  • goal lt next(V1,V2), next(V1,V4), next(V1,V5),
    next(V2,V3), next(V3,V4), next(V3,V5), next(V3,
    V7), next(V4,V5), next(V5,V6), next(V6,V7)
  • next(r,y) next(y,b) next(b,y)
  • next(r,b) next(y,r) next(b,r)

103
Why does this work?
  • Reformulation (Step 2) rewrites the negation of
    the query in terms of just equality.
  • For larger map colorings, there will be O(n2)
    answers to -goal(X,Y,Z), where n of regions.
  • At an abstract level, it enumerates all the cases
    where
  • -goal(X,Y,Z) is directly entailed
  • Everything else is thrown into goal.
Write a Comment
User Comments (0)
About PowerShow.com