Ideas for Connecting Inductive Program Synthesis and - - PowerPoint PPT Presentation

ideas for connecting inductive program synthesis and
SMART_READER_LITE
LIVE PREVIEW

Ideas for Connecting Inductive Program Synthesis and - - PowerPoint PPT Presentation

Ideas for Connecting Inductive Program Synthesis and Bidirectionalization Janis Voigtl ander University of Bonn PEPM12 A small test Which function is this? f 1 [ a ] = a f 1 [ a , b ] = b f 1 [ a , b , c ] = c f 1 [ a , b , c , d


slide-1
SLIDE 1

Ideas for Connecting Inductive Program Synthesis and Bidirectionalization

Janis Voigtl¨ ander

University of Bonn

PEPM’12

slide-2
SLIDE 2

A small “test”

Which function is this? f1 [a] = a f1 [a, b] = b f1 [a, b, c ] = c f1 [a, b, c, d ] = d

1

slide-3
SLIDE 3

A small “test”

Which function is this? f1 [a] = a f1 [a, b] = b f1 [a, b, c ] = c f1 [a, b, c, d ] = d And this one? f2 [ ] = [ ] f2 [a] = [a] f2 [a, b] = [b, a] f2 [a, b, c ] = [c, b, a]

1

slide-4
SLIDE 4

View-Update [Banc. & Sp., ACM TODS’81]

source view s v s′ v′ get

2

slide-5
SLIDE 5

View-Update [Banc. & Sp., ACM TODS’81]

source view s v s′ v′ get update

2

slide-6
SLIDE 6

View-Update [Banc. & Sp., ACM TODS’81]

source view s v s′ v′ get put update

2

slide-7
SLIDE 7

View-Update [Banc. & Sp., ACM TODS’81]

source view s v s′ v′ get put update

2

slide-8
SLIDE 8

View-Update [Banc. & Sp., ACM TODS’81]

source view s v s v get = Acceptability / GetPut

2

slide-9
SLIDE 9

View-Update [Banc. & Sp., ACM TODS’81]

source view s v s v get put = = Acceptability / GetPut

2

slide-10
SLIDE 10

View-Update [Banc. & Sp., ACM TODS’81]

source view s v s′ v′ get put update Consistency / PutGet

2

slide-11
SLIDE 11

View-Update [Banc. & Sp., ACM TODS’81]

source view s v s′ v′ get put update get Consistency / PutGet

2

slide-12
SLIDE 12

View-Update [Banc. & Sp., ACM TODS’81]

source view s v s′ v′ get put update

2

slide-13
SLIDE 13

View-Update [Banc. & Sp., ACM TODS’81]

source view s v s′ v′ get put update Lenses, DSLs [Foster et al., ACM TOPLAS’07, . . . ]

2

slide-14
SLIDE 14

View-Update [Banc. & Sp., ACM TODS’81]

source view s v s′ v′ get put update Bidirectionalization [Matsuda et al., ICFP’07], [V., POPL’09], . . .

2

slide-15
SLIDE 15

Bidirectionalization (BX)

Examples: “abc” “bc” “ade” “de” tail

3

slide-16
SLIDE 16

Bidirectionalization (BX)

Examples: “abc” “bc” “ade” “de” tail update

3

slide-17
SLIDE 17

Bidirectionalization (BX)

Examples: “abc” “bc” “ade” “de” tail put update

3

slide-18
SLIDE 18

Bidirectionalization (BX)

Examples: ‘a’ ‘b’ ‘a’ ‘c’ “abac” ‘a’ ‘b’ ‘x’ ‘c’ “abxc” flatten

3

slide-19
SLIDE 19

Bidirectionalization (BX)

Examples: ‘a’ ‘b’ ‘a’ ‘c’ “abac” ‘a’ ‘b’ ‘x’ ‘c’ “abxc” flatten update

3

slide-20
SLIDE 20

Bidirectionalization (BX)

Examples: ‘a’ ‘b’ ‘a’ ‘c’ “abac” ‘a’ ‘b’ ‘x’ ‘c’ “abxc” flatten put update

3

slide-21
SLIDE 21

Nondeterminism / Choices to make

Let get = sieve with: s "" "a" "ab" "abc" "abcd" "abcde" sieve s "" "" "b" "b" "bd" "bd"

4

slide-22
SLIDE 22

Nondeterminism / Choices to make

Let get = sieve with: s "" "a" "ab" "abc" "abcd" "abcde" sieve s "" "" "b" "b" "bd" "bd" Then, for example: put "abcd" "xy" = "axcy"

4

slide-23
SLIDE 23

Nondeterminism / Choices to make

Let get = sieve with: s "" "a" "ab" "abc" "abcd" "abcde" sieve s "" "" "b" "b" "bd" "bd" Then, for example: put "abcd" "xy" = "axcy" put "abcde" "xy" = "axcye"

4

slide-24
SLIDE 24

Nondeterminism / Choices to make

Let get = sieve with: s "" "a" "ab" "abc" "abcd" "abcde" sieve s "" "" "b" "b" "bd" "bd" Then, for example: put "abcd" "xy" = "axcy" put "abcde" "xy" = "axcye" put "abcde" "xyz" =

4

slide-25
SLIDE 25

Nondeterminism / Choices to make

Let get = sieve with: s "" "a" "ab" "abc" "abcd" "abcde" sieve s "" "" "b" "b" "bd" "bd" Then, for example: put "abcd" "xy" = "axcy" put "abcde" "xy" = "axcye" put "abcde" "xyz" = "axcyez"

4

slide-26
SLIDE 26

Nondeterminism / Choices to make

Let get = sieve with: s "" "a" "ab" "abc" "abcd" "abcde" sieve s "" "" "b" "b" "bd" "bd" Then, for example: put "abcd" "xy" = "axcy" put "abcde" "xy" = "axcye" put "abcde" "xyz" = "axcyez"

  • r "axcyez " ?

4

slide-27
SLIDE 27

Nondeterminism / Choices to make

Let get = sieve with: s "" "a" "ab" "abc" "abcd" "abcde" sieve s "" "" "b" "b" "bd" "bd" Then, for example: put "abcd" "xy" = "axcy" put "abcde" "xy" = "axcye" put "abcde" "xyz" = "axcyez"

  • r "axcyez " ?

put "abcd" "xyz" = "axcy z"

4

slide-28
SLIDE 28

Nondeterminism / Choices to make

Let get = sieve with: s "" "a" "ab" "abc" "abcd" "abcde" sieve s "" "" "b" "b" "bd" "bd" Then, for example: put "abcd" "xy" = "axcy" put "abcde" "xy" = "axcye" put "abcde" "xyz" = "axcyez"

  • r "axcyez " ?

put "abcd" "xyz" = "axcy z" put "abcd" "x" =

4

slide-29
SLIDE 29

Nondeterminism / Choices to make

Let get = sieve with: s "" "a" "ab" "abc" "abcd" "abcde" sieve s "" "" "b" "b" "bd" "bd" Then, for example: put "abcd" "xy" = "axcy" put "abcde" "xy" = "axcye" put "abcde" "xyz" = "axcyez"

  • r "axcyez " ?

put "abcd" "xyz" = "axcy z" put "abcd" "x" = "axc"

4

slide-30
SLIDE 30

Nondeterminism / Choices to make

Let get = sieve with: s "" "a" "ab" "abc" "abcd" "abcde" sieve s "" "" "b" "b" "bd" "bd" Then, for example: put "abcd" "xy" = "axcy" put "abcde" "xy" = "axcye" put "abcde" "xyz" = "axcyez"

  • r "axcyez " ?

put "abcd" "xyz" = "axcy z" put "abcd" "x" = "axc"

  • r "ax" ?

4

slide-31
SLIDE 31

Nondeterminism / Choices to make

Let get = sieve with: s "" "a" "ab" "abc" "abcd" "abcde" sieve s "" "" "b" "b" "bd" "bd" Then, for example: put "abcd" "xy" = "axcy" put "abcde" "xy" = "axcye" put "abcde" "xyz" = "axcyez"

  • r "axcyez " ?

put "abcd" "xyz" = "axcy z" put "abcd" "x" = "axc"

  • r "ax" ? ,
  • r "cx" ?

4

slide-32
SLIDE 32

Nondeterminism / Choices to make

Let get = head with: head (x : xs) = x

5

slide-33
SLIDE 33

Nondeterminism / Choices to make

Let get = head with: head (x : xs) = x Maybe: put (x : xs) y = [y ]

5

slide-34
SLIDE 34

Nondeterminism / Choices to make

Let get = head with: head (x : xs) = x Maybe: put (x : xs) y = [y ] But that violates put xs (get xs) = xs !

5

slide-35
SLIDE 35

Nondeterminism / Choices to make

Let get = head with: head (x : xs) = x Maybe: put (x : xs) y = [y ] But that violates put xs (get xs) = xs ! Better: put (x : xs) y | y == x = (x : xs) | otherwise = [y ]

5

slide-36
SLIDE 36

Nondeterminism / Choices to make

Let get = head with: head (x : xs) = x Maybe: put (x : xs) y = [y ] But that violates put xs (get xs) = xs ! Better: put (x : xs) y | y == x = (x : xs) | otherwise = [y ] But “really intended”: put (x : xs) y = (y : xs)

5

slide-37
SLIDE 37

A slightly more complex case, with recursion

Let get = init with: init [x ] = [ ] init (x : xs) = (x : (init xs))

6

slide-38
SLIDE 38

A slightly more complex case, with recursion

Let get = init with: init [x ] = [ ] init (x : xs) = (x : (init xs)) Possible, and correct: put xs ys | length ys == (length xs) − 1 = ys + + [last xs ] | otherwise = ys + + " "

6

slide-39
SLIDE 39

A slightly more complex case, with recursion

Let get = init with: init [x ] = [ ] init (x : xs) = (x : (init xs)) Possible, and correct: put xs ys | length ys == (length xs) − 1 = ys + + [last xs ] | otherwise = ys + + " " But intended: put xs ys = ys + + [last xs ]

6

slide-40
SLIDE 40

A slightly more complex case, with recursion

Let get = init with: init [x ] = [ ] init (x : xs) = (x : (init xs)) Possible, and correct: put xs ys | length ys == (length xs) − 1 = ys + + [last xs ] | otherwise = ys + + " " But intended: put xs ys = ys + + [last xs ] Problem: How to guide/control the possible choices?

6

slide-41
SLIDE 41

Entry: Inductive Program Synthesis (IP)

Recall, I/O pairs for a function: f1 [a] = a f1 [a, b] = b f1 [a, b, c ] = c f1 [a, b, c, d ] = d

7

slide-42
SLIDE 42

Entry: Inductive Program Synthesis (IP)

Recall, I/O pairs for a function: f1 [a] = a f1 [a, b] = b f1 [a, b, c ] = c f1 [a, b, c, d ] = d From this, an IP system automatically generates the program: f1 [x ] = x f1 (x : xs) = f1 xs

7

slide-43
SLIDE 43

Entry: Inductive Program Synthesis (IP)

Recall, I/O pairs for a function: f1 [a] = a f1 [a, b] = b f1 [a, b, c ] = c f1 [a, b, c, d ] = d From this, an IP system automatically generates the program: f1 [x ] = x f1 (x : xs) = f1 xs Or: f2 [ ] = [ ] f2 [a] = [a] f2 [a, b] = [b, a] f2 [a, b, c ] = [c, b, a]

7

slide-44
SLIDE 44

Entry: Inductive Program Synthesis (IP)

Or: f2 [ ] = [ ] f2 [a] = [a] f2 [a, b] = [b, a] f2 [a, b, c ] = [c, b, a] Again automatically generated: f2 [ ] = [ ] f2 (x : xs) = ((f3 (x : xs)) : (f2 (f4 (x : xs)))) f3 [x ] = x f3 (x : xs) = f3 xs f4 [x ] = [ ] f4 (x : xs) = (x : (f4 xs))

7

slide-45
SLIDE 45

Entry: Inductive Program Synthesis (IP)

Or: f2 [ ] = [ ] f2 [a] = [a] f2 [a, b] = [b, a] f2 [a, b, c ] = [c, b, a] Or, through provision of snoc as “background knowledge”: f2 [ ] = [ ] f2 (x : xs) = snoc (f2 xs) x

7

slide-46
SLIDE 46

The master plan: BX + IP

Problem: Of the view-update laws put xs (get xs) = xs get (put xs ys) = ys

  • nly the first one directly delivers I/O pairs for put.

8

slide-47
SLIDE 47

The master plan: BX + IP

Problem: Of the view-update laws put xs (get xs) = xs get (put xs ys) = ys

  • nly the first one directly delivers I/O pairs for put.

Like, for get = init: put [a] [ ] = [a] put [a, b] [a] = [a, b] put [a, b, c ] [a, b] = [a, b, c ] put [a, b, c, d ] [a, b, c ] = [a, b, c, d ]

8

slide-48
SLIDE 48

The master plan: BX + IP

Problem: Of the view-update laws put xs (get xs) = xs get (put xs ys) = ys

  • nly the first one directly delivers I/O pairs for put.

Like, for get = init: put [a] [ ] = [a] put [a, b] [a] = [a, b] put [a, b, c ] [a, b] = [a, b, c ] put [a, b, c, d ] [a, b, c ] = [a, b, c, d ] But then one would synthesize: put xs ys = xs

8

slide-49
SLIDE 49

The master plan: BX + IP

Problem: Of the view-update laws put xs (get xs) = xs get (put xs ys) = ys

  • nly the first one directly delivers I/O pairs for put.

Like, for get = init: put [a] [ ] = [a] put [a, b] [a] = [a, b] put [a, b, c ] [a, b] = [a, b, c ] put [a, b, c, d ] [a, b, c ] = [a, b, c, d ] But then one would synthesize: put xs ys = xs

  • 1. possible solution: Enforce use of both arguments?

8

slide-50
SLIDE 50

The master plan: BX + IP

First, on a simpler example, get = head: put [a] a = [a] put [a, b] a = [a, b] put [a, b, c ] a = [a, b, c ] put [a, b, c, d ] a = [a, b, c, d ]

9

slide-51
SLIDE 51

The master plan: BX + IP

First, on a simpler example, get = head: put [a] a = [a] put [a, b] a = [a, b] put [a, b, c ] a = [a, b, c ] put [a, b, c, d ] a = [a, b, c, d ] To avoid put xs y = xs, insist on use of y, i.e., something like: put xs y = (y : )

9

slide-52
SLIDE 52

The master plan: BX + IP

First, on a simpler example, get = head: put [a] a = [a] put [a, b] a = [a, b] put [a, b, c ] a = [a, b, c ] put [a, b, c, d ] a = [a, b, c, d ] To avoid put xs y = xs, insist on use of y, i.e., something like: put xs y = (y : ) Starting from this hypothesis, practically only one reasonable path

  • f synthesis, with result something like:

put xs y = (y : (tail xs))

9

slide-53
SLIDE 53

The master plan: BX + IP

On the more complex example, get = init: init [x ] = [ ] init (x : xs) = (x : (init xs)) different “degrees” of use of ys in put xs ys are possible.

10

slide-54
SLIDE 54

The master plan: BX + IP

On the more complex example, get = init: init [x ] = [ ] init (x : xs) = (x : (init xs)) different “degrees” of use of ys in put xs ys are possible. For example: put xs ys = (take (length ys) xs) + + [last xs ]

10

slide-55
SLIDE 55

The master plan: BX + IP

On the more complex example, get = init: init [x ] = [ ] init (x : xs) = (x : (init xs)) different “degrees” of use of ys in put xs ys are possible. For example: put xs ys = (take (length ys) xs) + + [last xs ] Or: put xs ys = ys + + [last xs ]

10

slide-56
SLIDE 56

The master plan: BX + IP

On the more complex example, get = init: init [x ] = [ ] init (x : xs) = (x : (init xs)) different “degrees” of use of ys in put xs ys are possible. For example: put xs ys = (take (length ys) xs) + + [last xs ] Or: put xs ys = ys + + [last xs ] Caution: Not every put generated (like) above automatically sa- tisfies get (put xs ys) = ys.

10

slide-57
SLIDE 57

The master plan: BX + IP

On the more complex example, get = init: init [x ] = [ ] init (x : xs) = (x : (init xs)) different “degrees” of use of ys in put xs ys are possible. For example: put xs ys = (take (length ys) xs) + + [last xs ] Or: put xs ys = ys + + [last xs ] Caution: Not every put generated (like) above automatically sa- tisfies get (put xs ys) = ys. (But it’s okay, trust IP.)

10

slide-58
SLIDE 58

The master plan: BX + IP

  • 2. possible solution: To after all generate I/O pairs for put from

get (put xs y) = y as well, “inversion” of get.

11

slide-59
SLIDE 59

The master plan: BX + IP

  • 2. possible solution: To after all generate I/O pairs for put from

get (put xs y) = y as well, “inversion” of get. Then: put xs y = get−1 y as provider of further I/O pairs beside put xs (get xs) = xs.

11

slide-60
SLIDE 60

The master plan: BX + IP

  • 2. possible solution: To after all generate I/O pairs for put from

get (put xs y) = y as well, “inversion” of get. Then: put xs y = get−1 y as provider of further I/O pairs beside put xs (get xs) = xs. Like, for get = head, head−1 y = [y ]

11

slide-61
SLIDE 61

The master plan: BX + IP

  • 2. possible solution: To after all generate I/O pairs for put from

get (put xs y) = y as well, “inversion” of get. Then: put xs y = get−1 y as provider of further I/O pairs beside put xs (get xs) = xs. Like, for get = head, head−1 y = [y ]

  • r, better,

head−1 y = (y : )

11

slide-62
SLIDE 62

The master plan: BX + IP

  • 2. possible solution: To after all generate I/O pairs for put from

get (put xs y) = y as well, “inversion” of get. Then: put xs y = get−1 y as provider of further I/O pairs beside put xs (get xs) = xs. Like, for get = head, head−1 y = [y ]

  • r, better,

head−1 y = (y : ) In this case, agrees with the other suggestion . . .

11

slide-63
SLIDE 63

The master plan: BX + IP

On the more complex example, get = init: init [x ] = [ ] init (x : xs) = (x : (init xs))

12

slide-64
SLIDE 64

The master plan: BX + IP

On the more complex example, get = init: init [x ] = [ ] init (x : xs) = (x : (init xs)) Use of init−1 ys = snoc ys

12

slide-65
SLIDE 65

The master plan: BX + IP

On the more complex example, get = init: init [x ] = [ ] init (x : xs) = (x : (init xs)) Use of init−1 ys = snoc ys to provide, beside: put [a] [ ] = [a] put [a, b] [a] = [a, b] · · · also: put [a] [b] = [b, ] put [a, b] [ ] = [ ] put [a, b] [c ] = [c, ] · · ·

12

slide-66
SLIDE 66

Conclusion / Outlook

◮ Bidirectional Transformations:

◮ “hot topic” in various areas, including PL approaches ◮ typical weakness: nondeterminism, and limited (or no)

impact of programmer intentions

13

slide-67
SLIDE 67

Conclusion / Outlook

◮ Bidirectional Transformations:

◮ “hot topic” in various areas, including PL approaches ◮ typical weakness: nondeterminism, and limited (or no)

impact of programmer intentions

◮ Inductive Program Synthesis:

◮ application of machine learning ◮ detects/exploits regularities ◮ hypothesis: captures programmer intentions 13

slide-68
SLIDE 68

Conclusion / Outlook

◮ Bidirectional Transformations:

◮ “hot topic” in various areas, including PL approaches ◮ typical weakness: nondeterminism, and limited (or no)

impact of programmer intentions

◮ Inductive Program Synthesis:

◮ application of machine learning ◮ detects/exploits regularities ◮ hypothesis: captures programmer intentions

◮ Connection:

◮ inductive program synthesis as a “helper” ◮ either naively as a black box, or deeper integration ◮ further ideas: I/O pairs per parametricity of get;

user impact through ad-hoc I/O pairs or provision of background knowledge; . . .

13

slide-69
SLIDE 69

References I

  • F. Bancilhon and N. Spyratos.

Update semantics of relational views. ACM Transactions on Database Systems, 6(3):557–575, 1981. J.N. Foster, M.B. Greenwald, J.T. Moore, B.C. Pierce, and A. Schmitt. Combinators for bidirectional tree transformations: A linguistic approach to the view-update problem. ACM Transactions on Programming Languages and Systems, 29(3):17, 2007.

  • S. Katayama.

Systematic search for lambda expressions. In Trends in Functional Programming 2005, Revised Selected Papers, pages 111–126. Intellect, 2007.

14

slide-70
SLIDE 70

References II

  • E. Kitzelmann and U. Schmid.

Inductive synthesis of functional programs: An explanation based generalization approach. Journal of Machine Learning Research, 7:429–454, 2006.

  • K. Matsuda, Z. Hu, K. Nakano, M. Hamana, and M. Takeichi.

Bidirectionalization transformation based on automatic derivation of view complement functions. In International Conference on Functional Programming, Proceedings, pages 47–58. ACM Press, 2007.

  • J. Voigtl¨

ander. Bidirectionalization for free! In Principles of Programming Languages, Proceedings, pages 165–176. ACM Press, 2009.

15