Dyna Evaluation of Logic Programs with Built-Ins and Aggregation: - - PowerPoint PPT Presentation

dyna
SMART_READER_LITE
LIVE PREVIEW

Dyna Evaluation of Logic Programs with Built-Ins and Aggregation: - - PowerPoint PPT Presentation

Dyna Evaluation of Logic Programs with Built-Ins and Aggregation: A Calculus for Bag Relations Matthew Francis-Landau , Tim Vieira, Jason Eisner mfl@cs.jhu.edu Johns Hopkins University WRLA 2020 October 21 1 R-exprs (Relational


slide-1
SLIDE 1

Dyna Evaluation of Logic Programs with Built-Ins and Aggregation: A Calculus for Bag Relations

Matthew Francis-Landau, Tim Vieira, Jason Eisner mfl@cs.jhu.edu Johns Hopkins University

1

WRLA 2020 October 21

slide-2
SLIDE 2

2

R-exprs (Relational expressions)

slide-3
SLIDE 3

2

R-exprs (Relational expressions)

Term Rewriting

slide-4
SLIDE 4

2

R-exprs (Relational expressions)

Compile Term Rewriting

slide-5
SLIDE 5

2

Machine Learning Database Deductive Databases Dynamic Programming Logic Programming Search

R-exprs (Relational expressions)

Compile Term Rewriting AI

slide-6
SLIDE 6

2

Machine Learning Database Deductive Databases Dynamic Programming Logic Programming Search

R-exprs (Relational expressions)

Compile Term Rewriting Care about what not how something is computed AI

slide-7
SLIDE 7

Term Rewriting

2

Machine Learning Database Deductive Databases Dynamic Programming Logic Programming Search

R-exprs (Relational expressions)

Compile Term Rewriting + Queries R-exprs (+ Query) Care about what not how something is computed AI

slide-8
SLIDE 8

Term Rewriting

2

Machine Learning Database Deductive Databases Dynamic Programming Logic Programming Search

R-exprs (Relational expressions)

Compile Term Rewriting + Queries Results (Hopefully) Useful Representation for User R-exprs (+ Query) Done Care about what not how something is computed AI

slide-9
SLIDE 9

3

Dyna vs. Prior Work

slide-10
SLIDE 10

3

SQL Datalog Prolog CLP Dyna Finite

✓ ✓ ✓ ✓ ✓

Deductive

✗ ✓ ✓ ✓ ✓

Infinite relations

✗ ✗ ✓ ✓ ✓

Aggregation

✓ ✓ ✗ ✗ ✓

Turing complete

✗ ✗ ✓ ✓ ✓

Constraints

✗ ✗ ✗ ✓ ✓

Dyna vs. Prior Work

slide-11
SLIDE 11

3

SQL Datalog Prolog CLP Dyna Finite

✓ ✓ ✓ ✓ ✓

Deductive

✗ ✓ ✓ ✓ ✓

Infinite relations

✗ ✗ ✓ ✓ ✓

Aggregation

✓ ✓ ✗ ✗ ✓

Turing complete

✗ ✗ ✓ ✓ ✓

Constraints

✗ ✗ ✗ ✓ ✓

Dyna vs. Prior Work

Supported by all. Naïve strategies terminate due to finite.

slide-12
SLIDE 12

3

SQL Datalog Prolog CLP Dyna Finite

✓ ✓ ✓ ✓ ✓

Deductive

✗ ✓ ✓ ✓ ✓

Infinite relations

✗ ✗ ✓ ✓ ✓

Aggregation

✓ ✓ ✗ ✗ ✓

Turing complete

✗ ✗ ✓ ✓ ✓

Constraints

✗ ✗ ✗ ✓ ✓

Dyna vs. Prior Work

Combining rules and “facts” to infer new “facts”

slide-13
SLIDE 13

3

SQL Datalog Prolog CLP Dyna Finite

✓ ✓ ✓ ✓ ✓

Deductive

✗ ✓ ✓ ✓ ✓

Infinite relations

✗ ✗ ✓ ✓ ✓

Aggregation

✓ ✓ ✗ ✗ ✓

Turing complete

✗ ✗ ✓ ✓ ✓

Constraints

✗ ✗ ✗ ✓ ✓

Dyna vs. Prior Work

E.g. can we represent the set

  • f all positive

integers, or all prime numbers

slide-14
SLIDE 14

3

SQL Datalog Prolog CLP Dyna Finite

✓ ✓ ✓ ✓ ✓

Deductive

✗ ✓ ✓ ✓ ✓

Infinite relations

✗ ✗ ✓ ✓ ✓

Aggregation

✓ ✓ ✗ ✗ ✓

Turing complete

✗ ✗ ✓ ✓ ✓

Constraints

✗ ✗ ✗ ✓ ✓

Dyna vs. Prior Work

SELECT sum(column) FROM x Important for weighted programs

slide-15
SLIDE 15

3

SQL Datalog Prolog CLP Dyna Finite

✓ ✓ ✓ ✓ ✓

Deductive

✗ ✓ ✓ ✓ ✓

Infinite relations

✗ ✗ ✓ ✓ ✓

Aggregation

✓ ✓ ✗ ✗ ✓

Turing complete

✗ ✗ ✓ ✓ ✓

Constraints

✗ ✗ ✗ ✓ ✓

Dyna vs. Prior Work

Is this a full programming language

slide-16
SLIDE 16

3

SQL Datalog Prolog CLP Dyna Finite

✓ ✓ ✓ ✓ ✓

Deductive

✗ ✓ ✓ ✓ ✓

Infinite relations

✗ ✗ ✓ ✓ ✓

Aggregation

✓ ✓ ✗ ✗ ✓

Turing complete

✗ ✗ ✓ ✓ ✓

Constraints

✗ ✗ ✗ ✓ ✓

Dyna vs. Prior Work

Can expressions like: 𝑌 < 𝑍 && 𝑍 < 𝑌 be identified as impossible

slide-17
SLIDE 17

3

WANT ALL THE THINGS SQL Datalog Prolog CLP Dyna Finite

✓ ✓ ✓ ✓ ✓

Deductive

✗ ✓ ✓ ✓ ✓

Infinite relations

✗ ✗ ✓ ✓ ✓

Aggregation

✓ ✓ ✗ ✗ ✓

Turing complete

✗ ✗ ✓ ✓ ✓

Constraints

✗ ✗ ✗ ✓ ✓

Dyna vs. Prior Work

slide-18
SLIDE 18

3

WANT ALL THE THINGS SQL Datalog Prolog CLP Dyna Finite

✓ ✓ ✓ ✓ ✓

Deductive

✗ ✓ ✓ ✓ ✓

Infinite relations

✗ ✗ ✓ ✓ ✓

Aggregation

✓ ✓ ✗ ✗ ✓

Turing complete

✗ ✗ ✓ ✓ ✓

Constraints

✗ ✗ ✗ ✓ ✓

Hard to mix

Dyna vs. Prior Work

slide-19
SLIDE 19

Aggregation + Infinite

  • m( 𝑌 ∶ 𝑌 ≥ 5 ) = ∞
  • 𝑌 ∶ 𝑌 ≥ 5 ) = 5
  • 1

2𝑗 = 2

4

slide-20
SLIDE 20

Aggregation + Infinite

Aggregators

  • OR – Exists A True Branch
  • Used in Prolog (:-)
  • Can stop early if find true value
  • m( 𝑌 ∶ 𝑌 ≥ 5 ) = ∞
  • 𝑌 ∶ 𝑌 ≥ 5 ) = 5
  • 1

2𝑗 = 2

4

slide-21
SLIDE 21

Aggregation + Infinite

Aggregators

  • OR – Exists A True Branch
  • Used in Prolog (:-)
  • Can stop early if find true value
  • AND – Not exist false branch
  • m( 𝑌 ∶ 𝑌 ≥ 5 ) = ∞
  • 𝑌 ∶ 𝑌 ≥ 5 ) = 5
  • 1

2𝑗 = 2

4

slide-22
SLIDE 22

Aggregation + Infinite

Aggregators

  • OR – Exists A True Branch
  • Used in Prolog (:-)
  • Can stop early if find true value
  • AND – Not exist false branch
  • Sum/Product – exhaustive

expansion of non-identity contributions

  • m( 𝑌 ∶ 𝑌 ≥ 5 ) = ∞
  • 𝑌 ∶ 𝑌 ≥ 5 ) = 5
  • 1

2𝑗 = 2

4

slide-23
SLIDE 23

Aggregation + Infinite

Aggregators

  • OR – Exists A True Branch
  • Used in Prolog (:-)
  • Can stop early if find true value
  • AND – Not exist false branch
  • Sum/Product – exhaustive

expansion of non-identity contributions

  • Max/Min – Structured Search

problem or exhaustive search

  • m( 𝑌 ∶ 𝑌 ≥ 5 ) = ∞
  • 𝑌 ∶ 𝑌 ≥ 5 ) = 5
  • 1

2𝑗 = 2

4

slide-24
SLIDE 24

Aggregation + Infinite

Aggregators

  • OR – Exists A True Branch
  • Used in Prolog (:-)
  • Can stop early if find true value
  • AND – Not exist false branch
  • Sum/Product – exhaustive

expansion of non-identity contributions

  • Max/Min – Structured Search

problem or exhaustive search

Infinite Relations

  • Infinite …..
  • Can’t use a naïve enumerate strategy

unless it stops early

  • m( 𝑌 ∶ 𝑌 ≥ 5 ) = ∞
  • 𝑌 ∶ 𝑌 ≥ 5 ) = 5
  • 1

2𝑗 = 2

4

slide-25
SLIDE 25

Aggregation + Infinite

Aggregators

  • OR – Exists A True Branch
  • Used in Prolog (:-)
  • Can stop early if find true value
  • AND – Not exist false branch
  • Sum/Product – exhaustive expansion of non-

identity contributions

  • Max/Min – Structured Search problem or

exhaustive search

Infinite Relations

  • ∑ 𝑗=0 ∞ 𝑗𝑗=0 ∑ 𝑗=0 ∞ ∞ ∑ 𝑗=0 ∞ 1 2 𝑗 1 1 2 𝑗 2 𝑗

2 2 𝑗 𝑗𝑗 2 𝑗 1 2 𝑗 = 2

  • 𝑌 :𝑌≥5 𝑌𝑌 :𝑌𝑌≥5 𝑌 :𝑌≥5 )=5
  • m( 𝑌 :𝑌≥5 𝑌𝑌 :𝑌𝑌≥5 𝑌 :𝑌≥5 )=∞
  • : 𝑌𝑌≥5 𝑌 : 𝑌≥5
  • Infinite …..
  • Can’t use a naïve enumerate strategy unless it stops

early

  • Require special rules to understand sequencesm(ሼ

ሽ 𝑌 ∶ 𝑌 ≥ 5 ) = ∞

  • 𝑌 ∶ 𝑌 ≥ 5 ) = 5
  • 1

2𝑗 = 2

4

slide-26
SLIDE 26

Dyna = Logic Programming + Aggregation

5

slide-27
SLIDE 27

Dyna = Logic Programming + Aggregation

a(I) :- b(I), c(I).

  • pointwise logical AND

5

slide-28
SLIDE 28

Dyna = Logic Programming + Aggregation

a(I) :- b(I), c(I).

  • pointwise logical AND

a(I) = b(I) * c(I).

  • pointwise multiplication

5

slide-29
SLIDE 29

Dyna = Logic Programming + Aggregation

a(I) :- b(I), c(I).

  • pointwise logical AND

a(I) = b(I) * c(I).

  • pointwise multiplication

a += b(I) * c(I).

  • dot product

5

slide-30
SLIDE 30

Dyna = Logic Programming + Aggregation

a(I) :- b(I), c(I).

  • pointwise logical AND

a(I) = b(I) * c(I).

  • pointwise multiplication

a += b(I) * c(I).

  • dot product

5

I can range over any value, not just integers

slide-31
SLIDE 31

Dyna = Logic Programming + Aggregation

a(I) :- b(I), c(I).

  • pointwise logical AND

a(I) = b(I) * c(I).

  • pointwise multiplication

a += b(I) * c(I).

  • dot product

a(I,K) += b(I,J) * c(J,K).

  • matrix multiplication; could be sparse
  • J is free on the right-hand side, so we sum over it

5

slide-32
SLIDE 32

Dyna = Logic Programming + Aggregation

a(I) :- b(I), c(I).

  • pointwise logical AND

a(I) = b(I) * c(I).

  • pointwise multiplication

a += b(I) * c(I).

  • dot product

a(I,K) += b(I,J) * c(J,K).

  • matrix multiplication; could be sparse
  • J is free on the right-hand side, so we sum over it

5

slide-33
SLIDE 33

Dyna = Logic Programming + Aggregation

a(I) :- b(I), c(I).

  • pointwise logical AND

a(I) = b(I) * c(I).

  • pointwise multiplication

a += b(I) * c(I).

  • dot product

a(I,K) += b(I,J) * c(J,K).

  • matrix multiplication; could be sparse
  • J is free on the right-hand side, so we sum over it

5

slide-34
SLIDE 34

Dyna = Logic Programming + Aggregation

a(I) :- b(I), c(I).

  • pointwise logical AND

a(I) = b(I) * c(I).

  • pointwise multiplication

a += b(I) * c(I).

  • dot product

a(I,K) += b(I,J) * c(J,K).

  • matrix multiplication; could be sparse
  • J is free on the right-hand side, so we sum over it

b(I,I) += 1. b(I,J) += 0.

  • Infinite identity matrix

5

slide-35
SLIDE 35

Example Program: Shortest path

6

slide-36
SLIDE 36

Example Program: Shortest path

6

distance(Start, Y) min= distance(Start, X) + edge(X, Y). distance(Start, Start) min= 0.

slide-37
SLIDE 37

Example Program: Shortest path

6

distance(Start, Y) min= distance(Start, X) + edge(X, Y). distance(Start, Start) min= 0. Variables not present in the head

  • f an expression are

aggregated over like with the dot product example.

slide-38
SLIDE 38

Example Program: Shortest path

6

distance(Start, Y) min= distance(Start, X) + edge(X, Y). distance(Start, Start) min= 0. Here the “min=“ aggregator only keeps the minimal value that we have computed

slide-39
SLIDE 39

Example Program: Shortest path

6

distance(Start, Y) min= distance(Start, X) + edge(X, Y). distance(Start, Start) min= 0. edge("a", "b") = 10. edge("b", "c") = 2. edge("c", "d") = 7.

slide-40
SLIDE 40

Example Program: Shortest path

6

distance(Start, Y) min= distance(Start, X) + edge(X, Y). distance(Start, Start) min= 0. edge("a", "b") = 10. edge("b", "c") = 2. edge("c", "d") = 7.

Start Y distance(Start, Y) "a" "a" "a" "b" 10 "a" "c" 12 "a" "d" 19 "b" "b" "b" "c" 2 "b" "d" 9 "c" "c" "c" "d" 7 "d" "d"

Dyna programs are equivalent to the set of values they define

slide-41
SLIDE 41

Example Program: Shortest path

6

distance(Start, Y) min= distance(Start, X) + edge(X, Y). distance(Start, Start) min= 0. edge("a", "b") = 10. edge("b", "c") = 2. edge("c", "d") = 7.

Start Y distance(Start, Y) "a" "a" "a" "b" 10 "a" "c" 12 "a" "d" 19 "b" "b" "b" "c" 2 "b" "d" 9 "c" "c" "c" "d" 7 "d" "d" Start Y distance(Start, Y) "foo" "foo" 7 7 3.1415 3.1415

Defined for all cases where both arguments are equal

slide-42
SLIDE 42

Shortest Path (cont.)

7

distance(S, S) = 0.

slide-43
SLIDE 43

Shortest Path (cont.)

7

distance(S, S) = 0.

S Y distance(S, Y) "foo" "foo" 7 7 3.1415 3.1415

slide-44
SLIDE 44

Shortest Path (cont.)

7

distance(S, S) = 0. ሼ 𝐵𝑠𝑕1, 𝐵𝑠𝑕2, 𝑆𝑓𝑡𝑣𝑚𝑢 : 𝐵𝑠𝑕1 = 𝐵𝑠𝑕2 𝐁𝐎𝐄 𝑆𝑓𝑡𝑣𝑚𝑢 = 0ሽ

S Y distance(S, Y) "foo" "foo" 7 7 3.1415 3.1415

slide-45
SLIDE 45

Shortest Path (cont.)

7

distance(S, S) = 0. ሼ 𝐵𝑠𝑕1, 𝐵𝑠𝑕2, 𝑆𝑓𝑡𝑣𝑚𝑢 : 𝐵𝑠𝑕1 = 𝐵𝑠𝑕2 𝐁𝐎𝐄 𝑆𝑓𝑡𝑣𝑚𝑢 = 0ሽ

S Y distance(S, Y) "foo" "foo" 7 7 3.1415 3.1415

slide-46
SLIDE 46

Shortest Path (cont.)

7

distance(S, S) = 0. ሼ 𝐵𝑠𝑕1, 𝐵𝑠𝑕2, 𝑆𝑓𝑡𝑣𝑚𝑢 : 𝐵𝑠𝑕1 = 𝐵𝑠𝑕2 𝐁𝐎𝐄 𝑆𝑓𝑡𝑣𝑚𝑢 = 0ሽ Tuple of Named Variables

S Y distance(S, Y) "foo" "foo" 7 7 3.1415 3.1415

slide-47
SLIDE 47

Shortest Path (cont.)

7

distance(S, S) = 0. ሼ 𝐵𝑠𝑕1, 𝐵𝑠𝑕2, 𝑆𝑓𝑡𝑣𝑚𝑢 : 𝐵𝑠𝑕1 = 𝐵𝑠𝑕2 𝐁𝐎𝐄 𝑆𝑓𝑡𝑣𝑚𝑢 = 0ሽ Tuple of Named Variables Executable Code Defines the Rule

S Y distance(S, Y) "foo" "foo" 7 7 3.1415 3.1415

slide-48
SLIDE 48

Shortest Path (cont.)

7

distance(S, Y) = distance(S, X) + edge(X, Y). distance(S, S) = 0. ሼ 𝐵𝑠𝑕1, 𝐵𝑠𝑕2, 𝑆𝑓𝑡𝑣𝑚𝑢 : 𝐵𝑠𝑕1 = 𝐵𝑠𝑕2 𝐁𝐎𝐄 𝑆𝑓𝑡𝑣𝑚𝑢 = 0ሽ Tuple of Named Variables Executable Code Defines the Rule

S Y distance(S, Y) "foo" "foo" 7 7 3.1415 3.1415

slide-49
SLIDE 49

Shortest Path (cont.)

7

distance(S, Y) = distance(S, X) + edge(X, Y). distance(S, S) = 0. ሼ 𝐵𝑠𝑕1, 𝐵𝑠𝑕2, 𝑆𝑓𝑡𝑣𝑚𝑢 : 𝐵𝑠𝑕1 = 𝐵𝑠𝑕2 𝐁𝐎𝐄 𝑆𝑓𝑡𝑣𝑚𝑢 = 0ሽ Tuple of Named Variables Executable Code Defines the Rule

S Y distance(S, Y) "foo" "foo" 7 7 3.1415 3.1415

Because of recursion, it can not be expressed using the set builder notation

slide-50
SLIDE 50

8

distance(Start, Y) = edge(X, Y) + distance(Start, X).

slide-51
SLIDE 51

8

distance(Start, Y) = edge(X, Y) + distance(Start, X). Result is distance(Arg1, Arg2) :- Result = edge(Arg2, X) + distance(Arg1, X). Normalize with standard names for all arguments

slide-52
SLIDE 52

8

distance(Start, Y) = edge(X, Y) + distance(Start, X). (E is edge(Arg2, X)) Result is distance(Arg1, Arg2) :- Result = edge(Arg2, X) + distance(Arg1, X). R-expr to Call function by name

slide-53
SLIDE 53

8

distance(Start, Y) = edge(X, Y) + distance(Start, X). (E is edge(Arg2, X)) Result is distance(Arg1, Arg2) :- Result = edge(Arg2, X) + distance(Arg1, X). R-expr to Call function by name Intermediate results are mapped to variables

slide-54
SLIDE 54

8

distance(Start, Y) = edge(X, Y) + distance(Start, X). (E is edge(Arg2, X)) (D is distance(Arg1, X)) Result is distance(Arg1, Arg2) :- Result = edge(Arg2, X) + distance(Arg1, X). Recursive call to distance

slide-55
SLIDE 55

8

distance(Start, Y) = edge(X, Y) + distance(Start, X). (E is edge(Arg2, X)) (D is distance(Arg1, X)) builtin_plus(Result, E, D) Result is distance(Arg1, Arg2) :- Result = edge(Arg2, X) + distance(Arg1, X). Built-in represented in the R-expr

slide-56
SLIDE 56

8

distance(Start, Y) = edge(X, Y) + distance(Start, X). (E is edge(Arg2, X)) (D is distance(Arg1, X)) builtin_plus(Result, E, D) Result is distance(Arg1, Arg2) :- Result = edge(Arg2, X) + distance(Arg1, X).

*

* Intersect the bag by multiplying the multiplicities and joining these expressions using the same variable names

slide-57
SLIDE 57

8

distance(Start, Y) = edge(X, Y) + distance(Start, X). (E is edge(Arg2, X)) (D is distance(Arg1, X)) builtin_plus(Result, E, D) Result is distance(Arg1, Arg2) :- Result = edge(Arg2, X) + distance(Arg1, X).

*

* Over the tuple ⟨Arg1, Arg2, Result, E, D, X⟩

slide-58
SLIDE 58

8

distance(Start, Y) = edge(X, Y) + distance(Start, X). (E is edge(Arg2, X)) (D is distance(Arg1, X)) builtin_plus(Result, E, D) Result is distance(Arg1, Arg2) :- Result = edge(Arg2, X) + distance(Arg1, X).

*

* proj(E, proj(D, proj(X, ))) Now Over the tuple ⟨Arg1, Arg2, Result⟩ Project out all local variables

slide-59
SLIDE 59

What about Aggregation?

9

distance(S, X) min= edge(X, Y) + distance(S, Y).

  • Any semi-group: min, max, sum, product, logical OR, logical AND
slide-60
SLIDE 60

What about Aggregation?

9

distance(S, X) min= edge(X, Y) + distance(S, Y).

  • Any semi-group: min, max, sum, product, logical OR, logical AND

(Result=min(MinInputVariable, R))

slide-61
SLIDE 61

What about Aggregation?

9

distance(S, X) min= edge(X, Y) + distance(S, Y).

  • Any semi-group: min, max, sum, product, logical OR, logical AND

R-expr composed on previous slide (Result=min(MinInputVariable, R))

slide-62
SLIDE 62

What about Aggregation?

9

distance(S, X) min= edge(X, Y) + distance(S, Y).

  • Any semi-group: min, max, sum, product, logical OR, logical AND

R-expr composed on previous slide New intermediate variable introduced (Like project) (Result=min(MinInputVariable, R))

slide-63
SLIDE 63

What about Aggregation?

9

distance(S, X) min= edge(X, Y) + distance(S, Y).

  • Any semi-group: min, max, sum, product, logical OR, logical AND

R-expr composed on previous slide New intermediate variable introduced (Like project) Resulting value from aggregation (Result=min(MinInputVariable, R))

slide-64
SLIDE 64

Shortest Path All Together Now

10

distance(S, S) min= 0. distance(S, X) min= edge(X, Y) + distance(S, Y).

slide-65
SLIDE 65

Shortest Path All Together Now

10

distance(S, S) min= 0. distance(S, X) min= edge(X, Y) + distance(S, Y).

Result is distance(Arg1, Arg2) min= Arg1=Arg2, Result=0. Result is distance(Arg1, Arg2) min= Result=edge(Arg2, Y) + distance(Arg1, Y).

slide-66
SLIDE 66

Shortest Path All Together Now

10

distance(S, S) min= 0. distance(S, X) min= edge(X, Y) + distance(S, Y).

Result is distance(Arg1, Arg2) min= Arg1=Arg2, Result=0. Result is distance(Arg1, Arg2) min= Result=edge(Arg2, Y) + distance(Arg1, Y).

(Arg1=Arg2) * (MinInput=0)

slide-67
SLIDE 67

Shortest Path All Together Now

10

distance(S, S) min= 0. distance(S, X) min= edge(X, Y) + distance(S, Y).

Result is distance(Arg1, Arg2) min= Arg1=Arg2, Result=0. Result is distance(Arg1, Arg2) min= Result=edge(Arg2, Y) + distance(Arg1, Y).

proj(E, proj(D, proj(Y, (E is edge(Arg2, Y)) * (D is distance(Arg1, Y)) * builtin_plus(MinInput, E, D) ))) (Arg1=Arg2) * (MinInput=0)

∩ ∩ ∩

slide-68
SLIDE 68

Shortest Path All Together Now

10

distance(S, S) min= 0. distance(S, X) min= edge(X, Y) + distance(S, Y).

Result is distance(Arg1, Arg2) min= Arg1=Arg2, Result=0. Result is distance(Arg1, Arg2) min= Result=edge(Arg2, Y) + distance(Arg1, Y).

proj(E, proj(D, proj(Y, (E is edge(Arg2, Y)) * (D is distance(Arg1, Y)) * builtin_plus(MinInput, E, D) ))) (Arg1=Arg2) * (MinInput=0)

∩ ∩ ∩

( )

( )

+

slide-69
SLIDE 69

Shortest Path All Together Now

10

distance(S, S) min= 0. distance(S, X) min= edge(X, Y) + distance(S, Y).

Result is distance(Arg1, Arg2) min= Arg1=Arg2, Result=0. Result is distance(Arg1, Arg2) min= Result=edge(Arg2, Y) + distance(Arg1, Y).

proj(E, proj(D, proj(Y, (E is edge(Arg2, Y)) * (D is distance(Arg1, Y)) * builtin_plus(MinInput, E, D) ))) (Arg1=Arg2) * (MinInput=0)

∩ ∩ ∩

( )

( )

+

(Result=min(MinInput,

))

The complete distance rule as a R-expr

slide-70
SLIDE 70

Manipulating R-exprs via Rewrites

11

slide-71
SLIDE 71

Manipulating R-exprs via Rewrites

  • A series of semantic preserving rewrites which attempt to simplify the

expression

  • Look for a sub-R-expr which can be rewritten to be simpler, do so!

11

slide-72
SLIDE 72

Manipulating R-exprs via Rewrites

  • A series of semantic preserving rewrites which attempt to simplify the

expression

  • Look for a sub-R-expr which can be rewritten to be simpler, do so!
  • Non-deterministic: Any order of rewrites is acceptable
  • Requires searching through the entire R-expr to identify what can be

rewritten/run

11

slide-73
SLIDE 73

Manipulating R-exprs via Rewrites

  • A series of semantic preserving rewrites which attempt to simplify the

expression

  • Look for a sub-R-expr which can be rewritten to be simpler, do so!
  • Non-deterministic: Any order of rewrites is acceptable
  • Requires searching through the entire R-expr to identify what can be

rewritten/run

  • Fair rewrites: non-normal form sub-expression are eventually

rewritten

  • Important in the case of recursive programs

11

slide-74
SLIDE 74

Manipulating R-exprs via Rewrites

  • A series of semantic preserving rewrites which attempt to simplify the

expression

  • Look for a sub-R-expr which can be rewritten to be simpler, do so!
  • Non-deterministic: Any order of rewrites is acceptable
  • Requires searching through the entire R-expr to identify what can be

rewritten/run

  • Fair rewrites: non-normal form sub-expression are eventually

rewritten

  • Important in the case of recursive programs
  • Core rewrites are presented in the paper

11

slide-75
SLIDE 75

R-expr Rewrites—Built-ins

12

slide-76
SLIDE 76

R-expr Rewrites—Built-ins

12

builtin_plus(X,Y,Z) ≡ ሼ 𝑌, 𝑍, 𝑎 : 𝑌 + 𝑍 = 𝑎ሽ

slide-77
SLIDE 77

R-expr Rewrites—Built-ins

12

builtin_plus(1,2,Z) → (Z=3) builtin_plus(X,Y,Z) ≡ ሼ 𝑌, 𝑍, 𝑎 : 𝑌 + 𝑍 = 𝑎ሽ builtin_plus runs and its result is assigned Z

slide-78
SLIDE 78

R-expr Rewrites—Built-ins

12

builtin_plus(1,2,Z) → (Z=3) builtin_plus(1,Y,Z) builtin_plus(X,Y,Z) ≡ ሼ 𝑌, 𝑍, 𝑎 : 𝑌 + 𝑍 = 𝑎ሽ No rewrites available for: 1+Y=Z Y=1, Z=2 Y=2, Z=3 Y=3, Z=4 ….

slide-79
SLIDE 79

R-expr Rewrites—Built-ins

12

builtin_plus(1,2,Z) → (Z=3) builtin_plus(1,Y,Z) (Z=3)*builtin_plus(1,Y,Z)→(Z=3)*builtin_plus(1,Y,3) builtin_plus(X,Y,Z) ≡ ሼ 𝑌, 𝑍, 𝑎 : 𝑌 + 𝑍 = 𝑎ሽ Propagate the assignment to Z

slide-80
SLIDE 80

R-expr Rewrites—Built-ins

12

builtin_plus(1,2,Z) → (Z=3) builtin_plus(1,Y,Z) (Z=3)*builtin_plus(1,Y,Z)→(Z=3)*builtin_plus(1,Y,3) builtin_plus(X,Y,Z) ≡ ሼ 𝑌, 𝑍, 𝑎 : 𝑌 + 𝑍 = 𝑎ሽ (Z=3)*builtin_plus(1,Y,3)→(Z=3)*(Y=2) Propagate the assignment to Z Built-ins support multiple modes for computation

slide-81
SLIDE 81

R-expr Rewrites—Built-ins

12

builtin_plus(1,2,Z) → (Z=3) builtin_plus(1,Y,Z) (Z=3)*builtin_plus(1,Y,Z)→(Z=3)*builtin_plus(1,Y,3) builtin_plus(1,2,3) → 1 builtin_plus(1,2,4) → 0 builtin_plus(X,Y,Z) ≡ ሼ 𝑌, 𝑍, 𝑎 : 𝑌 + 𝑍 = 𝑎ሽ (Z=3)*builtin_plus(1,Y,3)→(Z=3)*(Y=2) Check assignment is consistent Maps to the multiplicity of being contained in the bag * and + are over the bag’s multiplicity

slide-82
SLIDE 82

Rewriting Example: Shortest Path

13

Distance is distance("a", "c")

slide-83
SLIDE 83

Rewriting Example: Shortest Path

13

Distance is distance("a", "c")

(Result=min(MinInput, (Arg1=Arg2)*(MinInput=0) + proj(E, proj(D, proj(X, (E is edge(Arg2, X))*(D is distance(Argr1,X)*bultin_plus(E,D,MinInput))))

Program

slide-84
SLIDE 84

Rewriting Example: Shortest Path

13

Distance is distance("a", "c")

(Result=min(MinInput, (Arg1=Arg2)*(MinInput=0) + proj(E, proj(D, proj(X, (E is edge(Arg2, X))*(D is distance(Argr1,X)*bultin_plus(E,D,MinInput)))) (Distance=min(MinInput, ("a"="c")*(MinInput=0) + proj(E, proj(D, proj(X, (E is edge("c", X))*(D is distance("a",X)*bultin_plus(E,D,MinInput))))

Program

slide-85
SLIDE 85

Rewriting Example: Shortest Path

13

Distance is distance("a", "c")

(Result=min(MinInput, (Arg1=Arg2)*(MinInput=0) + proj(E, proj(D, proj(X, (E is edge(Arg2, X))*(D is distance(Argr1,X)*bultin_plus(E,D,MinInput)))) (Distance=min(MinInput, ("a"="c")*(MinInput=0) + proj(E, proj(D, proj(X, (E is edge("c", X))*(D is distance("a",X)*bultin_plus(E,D,MinInput))))

Variables not equal ("a"="c") → 0 Variables not equal

Program Rewrites Rules

slide-86
SLIDE 86

Rewriting Example: Shortest Path

13

Distance is distance("a", "c")

(Result=min(MinInput, (Arg1=Arg2)*(MinInput=0) + proj(E, proj(D, proj(X, (E is edge(Arg2, X))*(D is distance(Argr1,X)*bultin_plus(E,D,MinInput)))) (Distance=min(MinInput, ("a"="c")*(MinInput=0) + proj(E, proj(D, proj(X, (E is edge("c", X))*(D is distance("a",X)*bultin_plus(E,D,MinInput))))

Multiplicative annihilation Variables not equal 0 * R → 0 Multiplicative annihilation

Program Rewrites Rules

slide-87
SLIDE 87

Rewriting Example: Shortest Path

13

Distance is distance("a", "c")

(Result=min(MinInput, (Arg1=Arg2)*(MinInput=0) + proj(E, proj(D, proj(X, (E is edge(Arg2, X))*(D is distance(Argr1,X)*bultin_plus(E,D,MinInput)))) (Distance=min(MinInput, ("a"="c")*(MinInput=0) + proj(E, proj(D, proj(X, (E is edge("c", X))*(D is distance("a",X)*bultin_plus(E,D,MinInput))))

R Additive identity Multiplicative annihilation Variables not equal 0 + R → R Additive identity

Program Rewrites Rules

slide-88
SLIDE 88

Rewriting Example: Shortest Path

13

Distance is distance("a", "c")

(Result=min(MinInput, (Arg1=Arg2)*(MinInput=0) + proj(E, proj(D, proj(X, (E is edge(Arg2, X))*(D is distance(Argr1,X)*bultin_plus(E,D,MinInput)))) (Distance=min(MinInput, ("a"="c")*(MinInput=0) + proj(E, proj(D, proj(X, (E is edge("c", X))*(D is distance("a",X)*bultin_plus(E,D,MinInput))))

R Additive identity R Additive identity Multiplicative annihilation 0 + R → R Additive identity 0 + R → R Additive identity

Program Rewrites Rules

slide-89
SLIDE 89

Rewriting Example: Shortest Path

13

Distance is distance("a", "c")

(Result=min(MinInput, (Arg1=Arg2)*(MinInput=0) + proj(E, proj(D, proj(X, (E is edge(Arg2, X))*(D is distance(Argr1,X)*bultin_plus(E,D,MinInput)))) (Distance=min(MinInput, ("a"="c")*(MinInput=0) + proj(E, proj(D, proj(X, (E is edge("c", X))*(D is distance("a",X)*bultin_plus(E,D,MinInput))))

R Additive identity R Additive identity Multiplicative annihilation 0 + R → R Additive identity 0 + R → R Additive identity

(Distance=min(MinInput, proj(E, proj(D, proj(X, (E is edge("c", X))*(D is distance("a",X)*bultin_plus(E,D,MinInput))))

Program Rewrites Rules

slide-90
SLIDE 90

14 (Distance=min(MinInput, proj(E, proj(D, proj(X, (E is edge("c", X))*(D is distance("a",X)*bultin_plus(E,D,MinInput))))

slide-91
SLIDE 91

14 (Distance=min(MinInput, proj(E, proj(D, proj(X, (E is edge("c", X))*(D is distance("a",X)*bultin_plus(E,D,MinInput)))) (Result is edge(Arg1, Arg2)) :- (Arg1="a")*(Arg2="b")*(Result=10) + (Arg1="b")*(Arg2="c")*(Result=2) + (Arg1="c")*(Arg2="d")*(Result=7)

Program

slide-92
SLIDE 92

14 (Distance=min(MinInput, proj(E, proj(D, proj(X, (E is edge("c", X))*(D is distance("a",X)*bultin_plus(E,D,MinInput)))) (Result is edge(Arg1, Arg2)) :- (Arg1="a")*(Arg2="b")*(Result=10) + (Arg1="b")*(Arg2="c")*(Result=2) + (Arg1="c")*(Arg2="d")*(Result=7)

Program

(Distance=min(MinInput, proj(E, proj(D, proj(X, (("c"="a")*(X="b")*(E=10)+ ("c"="b")*(X="c")*(E=2)+ ("c"="c")*(X="d")*(E=7)) *(D is distance("a",X)*bultin_plus(E,D,MinInput))))

slide-93
SLIDE 93

14 (Distance=min(MinInput, proj(E, proj(D, proj(X, (E is edge("c", X))*(D is distance("a",X)*bultin_plus(E,D,MinInput)))) (Result is edge(Arg1, Arg2)) :- (Arg1="a")*(Arg2="b")*(Result=10) + (Arg1="b")*(Arg2="c")*(Result=2) + (Arg1="c")*(Arg2="d")*(Result=7)

Program

(Distance=min(MinInput, proj(E, proj(D, proj(X, (("c"="a")*(X="b")*(E=10)+ ("c"="b")*(X="c")*(E=2)+ ("c"="c")*(X="d")*(E=7)) *(D is distance("a",X)*bultin_plus(E,D,MinInput)))) 1 Equality checks ("c"="c") → 1

slide-94
SLIDE 94

14 (Distance=min(MinInput, proj(E, proj(D, proj(X, (E is edge("c", X))*(D is distance("a",X)*bultin_plus(E,D,MinInput)))) (Result is edge(Arg1, Arg2)) :- (Arg1="a")*(Arg2="b")*(Result=10) + (Arg1="b")*(Arg2="c")*(Result=2) + (Arg1="c")*(Arg2="d")*(Result=7)

Program

(Distance=min(MinInput, proj(E, proj(D, proj(X, (("c"="a")*(X="b")*(E=10)+ ("c"="b")*(X="c")*(E=2)+ ("c"="c")*(X="d")*(E=7)) *(D is distance("a",X)*bultin_plus(E,D,MinInput)))) R Multiplicative identity 1 Equality checks 1 * R → R Multiplicative identity

slide-95
SLIDE 95

14 (Distance=min(MinInput, proj(E, proj(D, proj(X, (E is edge("c", X))*(D is distance("a",X)*bultin_plus(E,D,MinInput)))) (Result is edge(Arg1, Arg2)) :- (Arg1="a")*(Arg2="b")*(Result=10) + (Arg1="b")*(Arg2="c")*(Result=2) + (Arg1="c")*(Arg2="d")*(Result=7)

Program

(Distance=min(MinInput, proj(E, proj(D, proj(X, (("c"="a")*(X="b")*(E=10)+ ("c"="b")*(X="c")*(E=2)+ ("c"="c")*(X="d")*(E=7)) *(D is distance("a",X)*bultin_plus(E,D,MinInput)))) R Multiplicative identity R Multiplicative identity 1 1 * R → R Multiplicative identity 1 * R → R Multiplicative identity

slide-96
SLIDE 96

14 (Distance=min(MinInput, proj(E, proj(D, proj(X, (E is edge("c", X))*(D is distance("a",X)*bultin_plus(E,D,MinInput)))) (Result is edge(Arg1, Arg2)) :- (Arg1="a")*(Arg2="b")*(Result=10) + (Arg1="b")*(Arg2="c")*(Result=2) + (Arg1="c")*(Arg2="d")*(Result=7)

Program

(Distance=min(MinInput, proj(E, proj(D, proj(X, (("c"="a")*(X="b")*(E=10)+ ("c"="b")*(X="c")*(E=2)+ ("c"="c")*(X="d")*(E=7)) *(D is distance("a",X)*bultin_plus(E,D,MinInput)))) R Multiplicative identity R Multiplicative identity 1 1 * R → R Multiplicative identity 1 * R → R Multiplicative identity (Distance=min(MinInput, proj(E, proj(D, proj(X, ((X="d")*(E=7)) *(D is distance("a",X)*bultin_plus(E,D,MinInput))))

slide-97
SLIDE 97

14 (Distance=min(MinInput, proj(E, proj(D, proj(X, (E is edge("c", X))*(D is distance("a",X)*bultin_plus(E,D,MinInput)))) (Result is edge(Arg1, Arg2)) :- (Arg1="a")*(Arg2="b")*(Result=10) + (Arg1="b")*(Arg2="c")*(Result=2) + (Arg1="c")*(Arg2="d")*(Result=7)

Program

(Distance=min(MinInput, proj(E, proj(D, proj(X, (("c"="a")*(X="b")*(E=10)+ ("c"="b")*(X="c")*(E=2)+ ("c"="c")*(X="d")*(E=7)) *(D is distance("a",X)*bultin_plus(E,D,MinInput)))) R Multiplicative identity R Multiplicative identity 1 1 * R → R Multiplicative identity 1 * R → R Multiplicative identity (Distance=min(MinInput, proj(E, proj(D, proj(X, ((X="d")*(E=7)) *(D is distance("a",X)*bultin_plus(E,D,MinInput)))) (Distance=min(MinInput, proj(D, (D is distance("a","d")*bultin_plus(7,D,MinInput))))

Propagate values

slide-98
SLIDE 98

Rewrites for Aggregators

15

slide-99
SLIDE 99

Rewrites for Aggregators

15 (Result=min(MinInput, (MinInput=789))) → (Result=789)

A final value has been determined. Assign it to the Result Variable

slide-100
SLIDE 100

Rewrites for Aggregators

15 (Result=min(MinInput, (MinInput=789))) → (Result=789) (Result=min(MinInput, R+S)) → builtin_min(MR, MS, Result)* (MR=min(MinInput, R))*(MS=min(MinInput, S))

Two disjunctive R-exprs can be split and processed individually

slide-101
SLIDE 101

Rewrites for Aggregators

15 (Result=min(MinInput, (MinInput=789))) → (Result=789) (Result=min(MinInput, R+S)) → builtin_min(MR, MS, Result)* (MR=min(MinInput, R))*(MS=min(MinInput, S)) (Result=min(MinInput, 0)) → (Result=identity) ≡ (Result=∞)

slide-102
SLIDE 102

Rewrites for Aggregators

15 (Result=min(MinInput, (MinInput=789))) → (Result=789) (Result=min(MinInput, R+S)) → builtin_min(MR, MS, Result)* (MR=min(MinInput, R))*(MS=min(MinInput, S)) (Result=min(MinInput, 0)) → (Result=identity) ≡ (Result=∞) not_identity(identity) → 0 not_identity(V) → 1 if ground(V) && V != identity (Result=min(MinInput, 0))*not_identity(Result) → 0

More “traditional” for aggregation to map empty to empty

slide-103
SLIDE 103

Ongoing and Future Work

16

slide-104
SLIDE 104

Ongoing and Future Work

  • Memoization and Mixed-chaining of computation
  • R-exprs serve as a basis for representing incomplete computations and can be

run in a myriad of different execution orders

  • Extended version of this paper to (hopefully) appear soon

16

slide-105
SLIDE 105

Ongoing and Future Work

  • Memoization and Mixed-chaining of computation
  • R-exprs serve as a basis for representing incomplete computations and can be

run in a myriad of different execution orders

  • Extended version of this paper to (hopefully) appear soon
  • Exploring and learning different execution orders
  • R-exprs capture what needs to be computed while leaving the order and how
  • pen to the runtime to decide
  • Much like a database optimizer, but for full, long running programs

16

slide-106
SLIDE 106

Ongoing and Future Work

  • Memoization and Mixed-chaining of computation
  • R-exprs serve as a basis for representing incomplete computations and can be

run in a myriad of different execution orders

  • Extended version of this paper to (hopefully) appear soon
  • Exploring and learning different execution orders
  • R-exprs capture what needs to be computed while leaving the order and how
  • pen to the runtime to decide
  • Much like a database optimizer, but for full, long running programs
  • Compilation and optimization of R-exprs
  • github.com/matthewfl/dyna-R arxiv.org/abs/2010.10503

16

slide-107
SLIDE 107

Thank you

Questions?

github.com/matthewfl/dyna-R arxiv.org/abs/2010.10503 mfl@cs.jhu.edu

17