Extending Answer Set Programs with Interpreted Functions as - - PowerPoint PPT Presentation

extending answer set programs with interpreted functions
SMART_READER_LITE
LIVE PREVIEW

Extending Answer Set Programs with Interpreted Functions as - - PowerPoint PPT Presentation

Extending Answer Set Programs with Interpreted Functions as First-class Citizens Christoph Redl redl@kr.tuwien.ac.at January 16, 2017 Redl C. (TU Vienna) HEX-Programs January 16, 2017 1 / 19 Motivation Outline Motivation 1 Interpreted


slide-1
SLIDE 1

Extending Answer Set Programs with Interpreted Functions as First-class Citizens

Christoph Redl

redl@kr.tuwien.ac.at

January 16, 2017

Redl C. (TU Vienna) HEX-Programs January 16, 2017 1 / 19

slide-2
SLIDE 2

Motivation

Outline

1

Motivation

2

Interpreted Functions as First-class Citzens

3

Excursus: HEX-Programs

4

Implementation of Interpreted Functions on Top of HEX-Programs

5

Applications

6

Conclusion

Redl C. (TU Vienna) HEX-Programs January 16, 2017 2 / 19

slide-3
SLIDE 3

Motivation

Motivation

Function Symbols in Answer Set Programs

Function symbols are often uninterpreted and are used for structuring information.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 3 / 19

slide-4
SLIDE 4

Motivation

Motivation

Function Symbols in Answer Set Programs

Function symbols are often uninterpreted and are used for structuring information. Example: multiply(add(4, 5), 3) represents the expression (4 + 5) · 3, but does not actually evaluate it.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 3 / 19

slide-5
SLIDE 5

Motivation

Motivation

Function Symbols in Answer Set Programs

Function symbols are often uninterpreted and are used for structuring information. Example: multiply(add(4, 5), 3) represents the expression (4 + 5) · 3, but does not actually evaluate it. Existing approaches towards interpreted functions typically define functions as part of the program.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 3 / 19

slide-6
SLIDE 6

Motivation

Motivation

Function Symbols in Answer Set Programs

Function symbols are often uninterpreted and are used for structuring information. Example: multiply(add(4, 5), 3) represents the expression (4 + 5) · 3, but does not actually evaluate it. Existing approaches towards interpreted functions typically define functions as part of the program. Example: loc(X) = garage ← car(X), not loc(X) = garage

Redl C. (TU Vienna) HEX-Programs January 16, 2017 3 / 19

slide-7
SLIDE 7

Motivation

Motivation

Function Symbols in Answer Set Programs

Function symbols are often uninterpreted and are used for structuring information. Example: multiply(add(4, 5), 3) represents the expression (4 + 5) · 3, but does not actually evaluate it. Existing approaches towards interpreted functions typically define functions as part of the program. Example: loc(X) = garage ← car(X), not loc(X) = garage Externally defined semantics of function symbols are supported by only few approaches (e.g. HEX-programs, VI-programs, Clingo5).

Redl C. (TU Vienna) HEX-Programs January 16, 2017 3 / 19

slide-8
SLIDE 8

Motivation

Motivation

Function Symbols in Answer Set Programs

Function symbols are often uninterpreted and are used for structuring information. Example: multiply(add(4, 5), 3) represents the expression (4 + 5) · 3, but does not actually evaluate it. Existing approaches towards interpreted functions typically define functions as part of the program. Example: loc(X) = garage ← car(X), not loc(X) = garage Externally defined semantics of function symbols are supported by only few approaches (e.g. HEX-programs, VI-programs, Clingo5). Example: result(Y) ← & add[4, 5](X), & multiply[X, 3](Y)

Redl C. (TU Vienna) HEX-Programs January 16, 2017 3 / 19

slide-9
SLIDE 9

Motivation

Motivation

Function Symbols in Answer Set Programs

Function symbols are often uninterpreted and are used for structuring information. Example: multiply(add(4, 5), 3) represents the expression (4 + 5) · 3, but does not actually evaluate it. Existing approaches towards interpreted functions typically define functions as part of the program. Example: loc(X) = garage ← car(X), not loc(X) = garage Externally defined semantics of function symbols are supported by only few approaches (e.g. HEX-programs, VI-programs, Clingo5). Example: result(Y) ← & add[4, 5](X), & multiply[X, 3](Y) But the functions are not first-class citizens ⇒ this inhibits higher-order functions.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 3 / 19

slide-10
SLIDE 10

Motivation

Motivation

Function Symbols in Answer Set Programs

Function symbols are often uninterpreted and are used for structuring information. Example: multiply(add(4, 5), 3) represents the expression (4 + 5) · 3, but does not actually evaluate it. Existing approaches towards interpreted functions typically define functions as part of the program. Example: loc(X) = garage ← car(X), not loc(X) = garage Externally defined semantics of function symbols are supported by only few approaches (e.g. HEX-programs, VI-programs, Clingo5). Example: result(Y) ← & add[4, 5](X), & multiply[X, 3](Y) But the functions are not first-class citizens ⇒ this inhibits higher-order functions. Goal: Using externally defined functions, but being able to access them as

  • bjects, compose them to new functions and pass them to other functions.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 3 / 19

slide-11
SLIDE 11

Motivation

Motivation

Main idea

Represent interpreted functions themselves by terms in the program. This turns them into first-class citizens, i.e., accessible objects.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 4 / 19

slide-12
SLIDE 12

Motivation

Motivation

Main idea

Represent interpreted functions themselves by terms in the program. This turns them into first-class citizens, i.e., accessible objects. Since they are objects in the program, they can be passed to other functions.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 4 / 19

slide-13
SLIDE 13

Motivation

Motivation

Main idea

Represent interpreted functions themselves by terms in the program. This turns them into first-class citizens, i.e., accessible objects. Since they are objects in the program, they can be passed to other functions. At specific points, they can be applied to a list of parameters.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 4 / 19

slide-14
SLIDE 14

Motivation

Motivation

Main idea

Represent interpreted functions themselves by terms in the program. This turns them into first-class citizens, i.e., accessible objects. Since they are objects in the program, they can be passed to other functions. At specific points, they can be applied to a list of parameters. This paves the way for new modeling techniques: abstract usage of functions, import of functions from outside, design patterns, higher-order techniques from functional programming.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 4 / 19

slide-15
SLIDE 15

Motivation

Motivation

Main idea

Represent interpreted functions themselves by terms in the program. This turns them into first-class citizens, i.e., accessible objects. Since they are objects in the program, they can be passed to other functions. At specific points, they can be applied to a list of parameters. This paves the way for new modeling techniques: abstract usage of functions, import of functions from outside, design patterns, higher-order techniques from functional programming.

Contribution

Representation of functions as terms. Based on this representation, we present HEXIFU-programs. A translation of such programs to traditional HEX-programs. Applications.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 4 / 19

slide-16
SLIDE 16

Interpreted Functions as First-class Citzens

Outline

1

Motivation

2

Interpreted Functions as First-class Citzens

3

Excursus: HEX-Programs

4

Implementation of Interpreted Functions on Top of HEX-Programs

5

Applications

6

Conclusion

Redl C. (TU Vienna) HEX-Programs January 16, 2017 5 / 19

slide-17
SLIDE 17

Interpreted Functions as First-class Citzens

Representing Interpreted Functions by Terms

Basic functions

Function symbols f ∈ F are basic function associated with an arity ℓ. We assume that each f ∈ F has an associated (total) semantics function semf ( y): Cℓ → T defined for all ℓ-ary vectors y ∈ Cℓ of constants T . . . set of all function terms constructible over F and C.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 6 / 19

slide-18
SLIDE 18

Interpreted Functions as First-class Citzens

Representing Interpreted Functions by Terms

Basic functions

Function symbols f ∈ F are basic function associated with an arity ℓ. We assume that each f ∈ F has an associated (total) semantics function semf ( y): Cℓ → T defined for all ℓ-ary vectors y ∈ Cℓ of constants T . . . set of all function terms constructible over F and C.

Representing general (possibly composed) functions

We let C contain constant symbols #i for all integers i ≥ 1 (placeholders), which are used to represent function parameters. We use T as function-representing (fr-)terms to turn interpreted functions into accessible objects.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 6 / 19

slide-19
SLIDE 19

Interpreted Functions as First-class Citzens

Representing Interpreted Functions by Terms

Example

Assume that the basic functions multiply and add have the expected semantics. Then the fr-term t1 = multiply(add(#1, #2), #3) represents in standard mathematical notation the function ˆ t1(p1, p2, p3) = (p1 + p2) · p3.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 7 / 19

slide-20
SLIDE 20

Interpreted Functions as First-class Citzens

Representing Interpreted Functions by Terms

Example

Assume that the basic functions multiply and add have the expected semantics. Then the fr-term t1 = multiply(add(#1, #2), #3) represents in standard mathematical notation the function ˆ t1(p1, p2, p3) = (p1 + p2) · p3.

Note

An fr-term t = f(t1, . . . , tℓ) with f ∈ F and t1, . . . , tℓ ∈ T does not represent the application of f to t1, . . . , tℓ, but does itself represents a (composed) function.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 7 / 19

slide-21
SLIDE 21

Interpreted Functions as First-class Citzens

Representing Interpreted Functions by Terms

Definition

For a list of ground terms t, p1, . . . , pγ(t) we let val(t, p1, . . . , pγ(t)) be given by          val(semf ( t′), p1, . . . , pγ(t)) if t = f(

  • t) and

t′ is free of #i, f( t′) if t = f(

  • t) and there is a #i in

t′, pi if t = #i for some 1 ≤ i ≤ γ(t), t

  • therwise,

where t and t′ are ℓ-ary vectors with t′

i = val(ti, p1, . . . , pγ(t)) for all 1 ≤ i ≤ ℓ.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 8 / 19

slide-22
SLIDE 22

Interpreted Functions as First-class Citzens

Representing Interpreted Functions by Terms

Definition

For a list of ground terms t, p1, . . . , pγ(t) we let val(t, p1, . . . , pγ(t)) be given by          val(semf ( t′), p1, . . . , pγ(t)) if t = f(

  • t) and

t′ is free of #i, f( t′) if t = f(

  • t) and there is a #i in

t′, pi if t = #i for some 1 ≤ i ≤ γ(t), t

  • therwise,

where t and t′ are ℓ-ary vectors with t′

i = val(ti, p1, . . . , pγ(t)) for all 1 ≤ i ≤ ℓ.

Example

Consider t = multiply(add(

t1

  • #1 ,

t2

  • #2 )
  • t4

,

t3

  • #3 ) and suppose to evaluate ˆ

t(4, 5, 3). t′

1 = val(#1, 4, 5, 3) = 4, t′ 2 = val(#2, 4, 5, 3) = 5, t′ 3 = val(#3, 4, 5, 3) = 3

t′

4 = val(add(#1, #2), t′ 1, t′ 2, t′ 3) = val(add(#1, #2), 4, 5, 3) = 9

t′ = val(semmultiply(t′

4, t′ 3)) = val(semmultiply(9, 3)) = 27

Redl C. (TU Vienna) HEX-Programs January 16, 2017 8 / 19

slide-23
SLIDE 23

Interpreted Functions as First-class Citzens

Using FR-Terms in Programs

Definition

An interpreted function (ifu-)atom is of kind ¯ R =$ ¯ T[ ¯ P1, . . . , ¯ Pℓ], where ¯ R ∈ T is a comparison operand, ¯ T ∈ T is an fr-term, and ¯ P1, . . . , ¯ Pℓ ∈ T are parameters.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 9 / 19

slide-24
SLIDE 24

Interpreted Functions as First-class Citzens

Using FR-Terms in Programs

Definition

An interpreted function (ifu-)atom is of kind ¯ R =$ ¯ T[ ¯ P1, . . . , ¯ Pℓ], where ¯ R ∈ T is a comparison operand, ¯ T ∈ T is an fr-term, and ¯ P1, . . . , ¯ Pℓ ∈ T are parameters.

Definition

A ground ifu-atom a of form r =$ t[t1, . . . , tn] is true wrt. assignment A, denoted A | = a, if n = γ(t) and r has the value of val(t, t1, . . . , tn), and false, denoted A | = a, otherwise.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 9 / 19

slide-25
SLIDE 25

Interpreted Functions as First-class Citzens

Using FR-Terms in Programs

Definition

An interpreted function (ifu-)atom is of kind ¯ R =$ ¯ T[ ¯ P1, . . . , ¯ Pℓ], where ¯ R ∈ T is a comparison operand, ¯ T ∈ T is an fr-term, and ¯ P1, . . . , ¯ Pℓ ∈ T are parameters.

Definition

A ground ifu-atom a of form r =$ t[t1, . . . , tn] is true wrt. assignment A, denoted A | = a, if n = γ(t) and r has the value of val(t, t1, . . . , tn), and false, denoted A | = a, otherwise.

Example

The fr-term add(#1, 1) represents the increment function. The ifu-atom X =$ add(#1, 1)[Y] applies it to the parameter Y and compares the result with X.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 9 / 19

slide-26
SLIDE 26

Interpreted Functions as First-class Citzens

Using FR-Terms in Programs

Definition

An ASP- resp. HEX-program with interpreted functions (ASPIFUresp. HEXIFU) is an ASP- resp. HEX-program, where rule bodies may contain ifu-atoms.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 10 / 19

slide-27
SLIDE 27

Interpreted Functions as First-class Citzens

Using FR-Terms in Programs

Definition

An ASP- resp. HEX-program with interpreted functions (ASPIFUresp. HEXIFU) is an ASP- resp. HEX-program, where rule bodies may contain ifu-atoms.

Example

Consider compInitials( concat(firstchar(#1), firstchar(#2)) ) ← Consider facts of kind person(F, L) ← represent persons with first name F and last name L.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 10 / 19

slide-28
SLIDE 28

Interpreted Functions as First-class Citzens

Using FR-Terms in Programs

Definition

An ASP- resp. HEX-program with interpreted functions (ASPIFUresp. HEXIFU) is an ASP- resp. HEX-program, where rule bodies may contain ifu-atoms.

Example

Consider compInitials( concat(firstchar(#1), firstchar(#2)) ) ← Consider facts of kind person(F, L) ← represent persons with first name F and last name L. Then initials(F, L, I) ← person(F, L), compInitials(C), I =$ C[F, L] computes the initials of all persons by applying the function.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 10 / 19

slide-29
SLIDE 29

Excursus: HEX-Programs

Outline

1

Motivation

2

Interpreted Functions as First-class Citzens

3

Excursus: HEX-Programs

4

Implementation of Interpreted Functions on Top of HEX-Programs

5

Applications

6

Conclusion

Redl C. (TU Vienna) HEX-Programs January 16, 2017 11 / 19

slide-30
SLIDE 30

Excursus: HEX-Programs

HEX-Programs

HEX-programs extend ordinary ASP programs by external sources

Definition (HEX-programs)

A HEX-program consists of rules of form a1 ∨ · · · ∨ an ← b1, . . . , bm, not bm+1, . . . , not bn, with classical literals ai, and classical literals or an external atoms bj.

Definition (External Atoms)

An external atom is of the form & p[q1, . . . , qk](t1, . . . , tl), p . . . external predicate name qi . . . predicate names or constants tj . . . terms Semantics: 1 + k + l-ary Boolean oracle function f&p: & p[q1, . . . , qk](t1, . . . , tl) is true under assignment A iff f&p(A, q1, . . . , qk, t1, . . . , tl) = 1. HEX- program Reasoner Implementation

  • f &p

Redl C. (TU Vienna) HEX-Programs January 16, 2017 12 / 19

slide-31
SLIDE 31

Implementation of Interpreted Functions on Top of HEX-Programs

Outline

1

Motivation

2

Interpreted Functions as First-class Citzens

3

Excursus: HEX-Programs

4

Implementation of Interpreted Functions on Top of HEX-Programs

5

Applications

6

Conclusion

Redl C. (TU Vienna) HEX-Programs January 16, 2017 13 / 19

slide-32
SLIDE 32

Implementation of Interpreted Functions on Top of HEX-Programs

Evaluation of HEXIFU-Programs

Evaluation is based on a translation to traditional HEX-programs.

Definition

For an assignment A and list of ground terms t, p1, . . . , pn s.t. γ(t) = n, let f&eval(A, t, p1, . . . , pn, r) = σ where σ = T if r = val(t, p1, . . . , pn) and σ = F

  • therwise.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 14 / 19

slide-33
SLIDE 33

Implementation of Interpreted Functions on Top of HEX-Programs

Evaluation of HEXIFU-Programs

Evaluation is based on a translation to traditional HEX-programs.

Definition

For an assignment A and list of ground terms t, p1, . . . , pn s.t. γ(t) = n, let f&eval(A, t, p1, . . . , pn, r) = σ where σ = T if r = val(t, p1, . . . , pn) and σ = F

  • therwise.

Definition

The translation of an ifu-atom a of kind ¯ R =$ ¯ T[ ¯ P1, . . . , ¯ Pℓ] to an external atom is given by τ(a) = & eval[¯ T, ¯ P1, . . . , ¯ Pℓ](¯ R). For HEXIFU-program Π, we let τ(Π) be Π after replacing each ifu-atom a by τ(a).

Redl C. (TU Vienna) HEX-Programs January 16, 2017 14 / 19

slide-34
SLIDE 34

Implementation of Interpreted Functions on Top of HEX-Programs

Evaluation of HEXIFU-Programs

Evaluation is based on a translation to traditional HEX-programs.

Definition

For an assignment A and list of ground terms t, p1, . . . , pn s.t. γ(t) = n, let f&eval(A, t, p1, . . . , pn, r) = σ where σ = T if r = val(t, p1, . . . , pn) and σ = F

  • therwise.

Definition

The translation of an ifu-atom a of kind ¯ R =$ ¯ T[ ¯ P1, . . . , ¯ Pℓ] to an external atom is given by τ(a) = & eval[¯ T, ¯ P1, . . . , ¯ Pℓ](¯ R). For HEXIFU-program Π, we let τ(Π) be Π after replacing each ifu-atom a by τ(a).

Proposition

An assignment A is an answer set of a HEXIFU-program Π if and only if it is an answer set of the HEX-program τ(Π).

Redl C. (TU Vienna) HEX-Programs January 16, 2017 14 / 19

slide-35
SLIDE 35

Applications

Outline

1

Motivation

2

Interpreted Functions as First-class Citzens

3

Excursus: HEX-Programs

4

Implementation of Interpreted Functions on Top of HEX-Programs

5

Applications

6

Conclusion

Redl C. (TU Vienna) HEX-Programs January 16, 2017 15 / 19

slide-36
SLIDE 36

Applications

Applications of HEXIFU-Programs

Software design patterns

Consider & getValidator[type](V) which returns for a given type of data type ∈ {phone, email, url, . . .} a validator.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 16 / 19

slide-37
SLIDE 37

Applications

Applications of HEXIFU-Programs

Software design patterns

Consider & getValidator[type](V) which returns for a given type of data type ∈ {phone, email, url, . . .} a validator. Data can be verified using: r1 : validators(AttType, V) ← emp(Id, AttType, AttValue), & getValidator[AttType](V). r2 : invalid(Id) ← emp(Id, AttType, AttValue), validators(AttType, V), 0 =$ V[AttValue].

Redl C. (TU Vienna) HEX-Programs January 16, 2017 16 / 19

slide-38
SLIDE 38

Applications

Applications of HEXIFU-Programs

Integration of heterogeneous knowledge bases

Suppose lookup(#1) provides access to the central dictionary and is accessible via predicate l. Then data(A) ← l(D), K =$ D[employee], A =$ K[query] can be used to answer queries over the employee knowledge-base using the access function D.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 17 / 19

slide-39
SLIDE 39

Applications

Applications of HEXIFU-Programs

Integration of heterogeneous knowledge bases

Suppose lookup(#1) provides access to the central dictionary and is accessible via predicate l. Then data(A) ← l(D), K =$ D[employee], A =$ K[query] can be used to answer queries over the employee knowledge-base using the access function D.

Traditional higher-order functions

Consider the external atom & map[f, p](X) which applies function f , given as an fr-term, to all elements in the extension of predicate p. Then res(R) ← compInitials(C), R =$ & map[C, person](X) can be used to compute the initials of all persons in the extension of predicate person.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 17 / 19

slide-40
SLIDE 40

Conclusion

Outline

1

Motivation

2

Interpreted Functions as First-class Citzens

3

Excursus: HEX-Programs

4

Implementation of Interpreted Functions on Top of HEX-Programs

5

Applications

6

Conclusion

Redl C. (TU Vienna) HEX-Programs January 16, 2017 18 / 19

slide-41
SLIDE 41

Conclusion

Conclusion

ASP Programs with Interpreted Functions

Traditionally, functions are mostly either uninterpreted or interpreted but defined within the program. Our approach uses externally defined functions. In contrast to few existing approaches towards such externally defined functions, ours treats them as first-class citizens, i.e., accessible objects. This paves the way for higher-order functions.

Future Work

Functions with predicate parameters. Additional means for defining functions such as currying.

Redl C. (TU Vienna) HEX-Programs January 16, 2017 19 / 19