123
Metacomputation A Gentle Introduction to Advanced Topics Ilya Klyuchnikov Keldysh Institute of Applied Mathematics (Russian Academy of Sciences)

Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

MetacomputationA Gentle Introduction to Advanced Topics

Ilya Klyuchnikov

Keldysh Institute of Applied Mathematics (Russian Academy of Sciences)

Page 2: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

Metacomputation: The Big Picture

Page 3: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

3

Disclaimer Notice

The following presentation simplifies technical stuff A LOT in order to fit 1.5 hours

and give you a taste of the area.

Examples are also small for the same reason.

Please consult references for details.

Page 4: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

4

Valentin Turchin (1931-2010)● The concept of

metasystem transition● The concept of

supercompilation

These two concepts are related (I will try to show this at the end of the talk).

Page 5: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

5

The Plan● Supercompilation in a nutshell● Optimization vs Analysis● Analyzing supercompilation (HOSC)● Two-level supercompilation● Multi-result supercompilation (MRSC)● Finding a minimal proof by multi-result

supercompilation● On metasystem transitions

Page 6: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

6

The Plan● Supercompilation in a nutshell● Optimization vs Analysis● Analyzing supercompilation (HOSC)● Two-level supercompilation● Multi-result supercompilation (MRSC)● Finding a minimal proof by multi-result

supercompilation● On metasystem transitions

Page 7: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

7

Supercompilation in a Nutshel● Driving● Folding● Whistle● Generalization

V. Turchin. The concept of a supercompiler / 1986M. Sørensen, R. Glück, and N. Jones. A Positive Supercompiler /1996M. Sørensen and R. Glück. Introduction to Supercompilation / 1998

Page 8: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

8

Execution

...

Page 9: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

9

Driving

S0

S1

S2 S

3

S4

...

cond' cond''

A. Klimov, R. Glück. Occam's Razor in Metacomputation: the Notion of a Perfect Process Tree / 1993N. Jones. The Essence of Program Transformation by Partial Evaluation and Driving / 1999

Execution

...

Page 10: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

10

Folding

S0

S1

S2 S

3

...

S0'

cond' cond''

Supercompilation is an instance of unfold/fold trans-formation defined in: R. M. Burstall and J. Darlington "A Transformation System for Developing Recursive Programs" / 1977

Page 11: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

11

Whistle

S0

S1

S2 S

3

...

Sn

cond' cond''

Page 12: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

12

Binary Whistle (standard approach)

S0

S1

S2 S

3

...

Sn

cond' cond''

M. Leuschel. On the power of homeomorphic embedding for online termination. 1998

Page 13: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

13

Generalization

S0

S1

S2 S

3

...

Sg'

cond' cond''

Sn

V. Turchin. The algorithm of generalization in the supercompiler / 1988M. Sørensen, R. Glück. An algorithm of generalization in positive supercompilation / 1995

Page 14: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

14

History of Supercompilation● 1970-1990s - Supercompilation for Refal

Language (V. Turchin et al)● 1990s – Supercompilation of First-Order

Functional languages● 2000s – Supercompilation of Higher-Order

Functional languages

There are 2 trends in supercompilation community: program optimization, program analysis.

Page 15: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

15

Existing Supercompilers● SCP4 (1990s)

● SCP for TSG (2000s)

● Jscp (2000s)

● SCP for Timber (2007)

● Supero (2007)

● SPSC (2008)

● HOSC (2008)

● Optimusprime (2009/10)

● CHSC (2010)

● Distiller (2009/10)

● MRSC (2011)

I. Klyuchnikov. The ideas and methods of supercompilation. Practice of functional programming. Vol.7. 2011 [In Russian].

Page 16: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

16

“Analyzing” Supercompilers● SCP4 (1990s)

● SCP for TSG (2000)

● Jscp (2000)

● SCP for Timber (2007)

● Supero (2007)

● SPSC (2008)

● HOSC (2008)

● Optimusprime (2009/10)

● CHSC (2010)

● Distiller (2009/10)

● MRSC (2011)

I. Klyuchnikov. The ideas and methods of supercompilation. Practice of functional programming. Vol.7. 2011 [In Russian].

Page 17: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

17

The Plan● Supercompilation in a nutshell● Optimization vs Analysis● Analyzing supercompilation (HOSC)● Two-level supercompilation● Multi-result supercompilation (MRSC)● Finding a minimal proof by multi-result

supercompilation● On metasystem transitions

Page 18: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

18

Optimization vs Analysis

Page 19: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

19

Optimization vs Analysis

Page 20: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

20

Optimization vs Analysis

Page 21: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

21

Optimization vs Analysis● Reducing execution

time● Reducing code size

● Simplifying the structure

● Revealing hidden properties

Page 22: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

22

Optimization vs Analysis● Reducing execution

time● Reducing code size

● Simplifying the structure

● Revealing hidden properties

The “best” ouput program.

The set of output programs.

Page 23: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

23

The story of development of analyzing supercompilers

From HOSC (2008) to MRSC (2011)

Page 24: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

24

The Plan● Supercompilation in a nutshell● Optimization vs Analysis● Analyzing supercompilation (HOSC)● Two-level supercompilation● Multi-result supercompilation (MRSC)● Finding a minimal proof by multi-result

supercompilation● On metasystem transitions

Page 25: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

25

From HOSC to MRSC

HOSC (Higher-Order Supercompiler) –an analyzing supercompiler for core Haskell:http://code.google.com/p/hosc/

MRSC (Multi-Result Supercompiler) – a framework for rapid development of different supercompilers:https://github.com/ilya-klyuchnikov/mrsc

Page 26: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

26

The HOSC Supercompiler (2008)

HOSC is intended for program analysis rather than for program optimization:

● Code duplication is allowed

● “Controversial” (from optimization point) transformation is allowed

The trick: we treat call-by-need programs ascall-by-name ones.

The consequence: tendency “to normalize” programs.

I. Klyuchnikov and S. Romanenko. Proving the equivalence of higher-order terms by means of supercompilation. PSI-2009.

Page 27: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

27

Example #1. Church numbers0 = \s z -> z

1 = \s z -> s z

2 = \s z -> s (s z)

3 = \s z -> s (s (s z))

...

n = \s z -> sn z

fm+n z -> sm (sn z)

fm*n z -> ((sn)m) z

Page 28: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

28

Example #1. Church numbersdata Nat = Z | S Nat;

foldn = \h z s -> case x of { Z -> z; S n1 -> s (foldn s z n1); };

add = \x y -> foldn S y x;

mult = \x y -> foldn (add y) Z x;

church = \n -> foldn (\m f x -> f (m f x)) (\f x -> x) n;

unchurch = \n -> n S Z;

churchMult = \m n f -> m (n f);

mult x y ? unchurch (churchMult (church x) (church y))

Page 29: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

29

Example #1. Church numbersdata Nat = Z | S Nat;

foldn = \h z s -> case x of { Z -> z; S n1 -> s (foldn s z n1);};

add = \x y -> foldn S y x;

mult = \x y -> foldn (add y) Z x;

church = \n -> foldn (\m f x -> f (m f x)) (\f x -> x) n;

unchurch = \n -> n S Z;

churchMult = \m n f -> m (n f);

mult x y ≅ unchurch (churchMult (church x) (church y))

letrec f = \m n -> case m of {

Z -> Z;

S m1 -> letrec g = \z -> case z of { S v -> S (g v); Z -> f m1 n; } in g n;

} in f x y

Page 30: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

30

Example #1. Church numbersdata Nat = Z | S Nat;

foldn = \h z s -> case x of { Z -> z; S n1 -> s (foldn s z n1);};

add = \x y -> foldn S y x;

mult = \x y -> foldn (add y) Z x;

church = \n -> foldn (\m f x -> f (m f x)) (\f x -> x) n;

unchurch = \n -> n S Z;

churchMult = \m n f -> m (n f);

mult x y ≅ unchurch (churchMult (church x) (church y))

letrec f = \m n -> case m of {

Z -> Z;

S m1 -> letrec g = \z -> case z of { S v -> S (g v); Z -> f m1 n; } in g n;

} in f x y

Page 31: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

31

Inferring the equivalence of programs

P1

P2

Page 32: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

32

Inferring the equivalence of programs

P1

SC

P1'

P2

SC

P2'

Page 33: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

33

Inferring the equivalence of programs

P1

SC

P1'

P2

SC

P2'

Page 34: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

34

Inferring the equivalence of programs

P1

SC

P1'

P2

SC

P2'

Page 35: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

35

Example #2. Abstract machines

O. Danvy and K. Millikin. On the equivalence between small-stepand big-step abstract machines: a simple application of lightweight fusion / 2008

Page 36: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

36

Example #2. Abstract machines

am1 am

2

O. Danvy and K. Millikin. On the equivalence between small-stepand big-step abstract machines: a simple application of lightweight fusion / 2008

Page 37: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

37

Example #2. Abstract machines

Danvy, Millikin (by hand):

am1 am

2

O. Danvy and K. Millikin. On the equivalence between small-stepand big-step abstract machines: a simple application of lightweight fusion / 2008

Page 38: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

38

Example #2. Abstract machines

Danvy, Millikin (by hand):

am1 am' am'' am

2

O. Danvy and K. Millikin. On the equivalence between small-stepand big-step abstract machines: a simple application of lightweight fusion / 2008

Page 39: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

39

Example #2. Abstract machines

Danvy, Millikin (by hand):

HOSC (automatically):

am1 am' am'' am

2

am1

am2

O. Danvy and K. Millikin. On the equivalence between small-stepand big-step abstract machines: a simple application of lightweight fusion / 2008

Page 40: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

40

Example #2. Abstract machines

Danvy, Millikin (by hand):

HOSC (automatically):

am1 am' am'' am

2

am1

am2

am*

O. Danvy and K. Millikin. On the equivalence between small-stepand big-step abstract machines: a simple application of lightweight fusion / 2008

Page 41: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

41

Example #2. Abstract machines

Danvy, Millikin (by hand):

HOSC (automatically):

am1 am' am'' am

2

am1

am2

am*31 loc 13 loc

51 loc

O. Danvy and K. Millikin. On the equivalence between small-stepand big-step abstract machines: a simple application of lightweight fusion / 2008

Page 42: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

42

Example #2. Abstract machines

Danvy, Millikin (by hand):

HOSC (automatically):

am1 am' am'' am

2

am1

am2

am*31 loc 13 loc

51 loc

Examples online: http://hosc.appspot.com

O. Danvy and K. Millikin. On the equivalence between small-stepand big-step abstract machines: a simple application of lightweight fusion / 2008

Page 43: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

43

Can we reuse this normalization property?

Page 44: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

44

Can we reuse this normalization property?

Self-application???

Page 45: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

45

Approaches to self-application● Futamura projections

● sc(int, prog) = prog'● sc(sc, int) = compiler● sc(sc, sc) = compiler generator

Page 46: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

46

Approaches to self-application● Futamura projections

● sc(int, prog) = prog'● sc(sc, int) = compiler● sc(sc, sc) = compiler generator

The most popular (old) idea

Page 47: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

47

Approaches to self-application● Futamura projections

● sc(int, prog) = prog'● sc(sc, int) = compiler● sc(sc, sc) = compiler generator

● Distillation● Two-level supercompilation● ...

The most popular (old) idea

Page 48: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

48

Approaches to self-application● Futamura projections

● sc(int, prog) = prog'● sc(sc, int) = compiler● sc(sc, sc) = compiler generator

● Distillation● Two-level supercompilation● ...

The most popular (old) idea

Rather new approaches

Page 49: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

49

Approaches to self-application● Futamura projections

● sc(int, prog) = prog'● sc(sc, int) = compiler● sc(sc, sc) = compiler generator

● Distillation● Two-level supercompilation● ...

The most popular (old) idea

Rather new approaches

Page 50: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

50

The Plan● Supercompilation in a nutshell● Optimization vs Analysis● Analyzing supercompilation (HOSC)● Two-level supercompilation● Multi-result supercompilation (MRSC)● Finding a minimal proof by multi-result

supercompilation● On metasystem transitions

Page 51: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

51

Two-Level SupercompilationThe problem:

● When whistle blows, we perform generalization.

● Generalization is evil, since it result in loss of information.

The idea:

● Escape from whistle

I. Klyuchnikov and S. Romanenko. Towards higher-level supercompilation. META-2010

Page 52: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

52

Escape from Whistle

S0

S1

S2 S

3

...

Sn

cond' cond''

Page 53: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

53

Escape from Whistle

S0

S1

S2 S

3

...

Sn

cond' cond''

S'n

=

Page 54: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

54

Escape from Whistle

S0

S1

S2 S

3

...

Sn

cond' cond''

S'n

=SC

Page 55: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

55

Two-Level Supercompilation

Sc Sc

X

A ?? BY/NSc

X'

| |

Page 56: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

56

Two-Level Supercompilation

Sc Sc

X

A ?? BY/NSc

X'

| |

There is a shortcut!

Page 57: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

57

Shortcut Two-Level supercompilation

S0

S1

S2 S

3

...

Sn

cond' cond''

Page 58: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

58

Shortcut Two-Level supercompilation

S0

S1

S2 S

3

...

Sn

cond' cond''

S0'

S0'

SC

SC

I. Klyuchnikov. Towards effective two-level supercompilation. KIAM Preprint #81. 2010

Page 59: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

59

Example #3. Even or odddata Bool = True | False;

data Nat = Z | S Nat;

even = \x -> case x of { Z -> True; S x1 -> odd x1; };

odd = \x -> case x of { Z -> False; S x1 -> even x1; };

or = \x y -> case x of { True -> True; False -> y; };

or (even m) (odd m)

The output:

letrec f = \w ->

case w of { Z -> True; S x -> case x of { Z -> True; S z -> f z; };}

in f m

Page 60: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

60

Example #3. Even or oddor (even m) (odd m)

case (even m) of {True -> True; False -> odd m;}

case (even n) of {True -> True; False -> odd (S (S n));}

...

Page 61: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

61

Example #3. Even or oddor (even m) (odd m)

case (even m) of {True -> True; False -> odd m;}

case (even n) of {True -> True; False -> odd (S (S n));}

...

letrec f=\v-> case v of { Z -> True; S p -> case p of { Z -> letrec g = \w-> case w of { Z -> False; S t -> case t of { Z -> True; S z -> g z;};} in g m; S x -> f x;};}in f m

letrec f=\v-> case v of { Z -> True; S p -> case p of { Z -> letrec g = \w-> case w of { Z -> False; S t -> case t of { Z -> True; S z -> g z;};} in g n; S x -> f x;};}in f n

SC

SC

Page 62: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

62

Example #3. Even or oddor (even m) (odd m)

case (even m) of {True -> True; False -> odd m;}

case (even n) of {True -> True; False -> odd (S (S n));}

...

letrec f=\v-> case v of { Z -> True; S p -> case p of { Z -> letrec g = \w-> case w of { Z -> False; S t -> case t of { Z -> True; S z -> g z;};} in g m; S x -> f x;};}in f m

letrec f=\v-> case v of { Z -> True; S p -> case p of { Z -> letrec g = \w-> case w of { Z -> False; S t -> case t of { Z -> True; S z -> g z;};} in g n; S x -> f x;};}in f n

SC

SC

Page 63: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

63

Making supercompilers from supercompilers (by multiplication)

Sc Sc

X

A ?? BY/NSc

X'

Sc L2| |

Page 64: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

64

Making supercompilers from supercompilers (by multiplication)

Sc1

Sc1

X

A ?? BY/NSc

2

X'

Sc2

Sc1

L2

| |

Page 65: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

65

Is It Worth to Do?

We make a two-level supercompiler from two different supercompilers.

Page 66: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

66

Is It Worth to Do?

We make a two-level supercompiler from two different supercompilers.

Does this approach make difference?

Page 67: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

67

Is It Worth to Do?

We make a two-level supercompiler from two different supercompilers.

Does this approach make difference?(We could use more powerful low-level supercompilers).

The stuff for experiments:𝑆�−−−, 𝑆�+−−, 𝑆�−+−, ... - 8 supercompilers

I. Klyuchnikov. Supercompiler HOSC 1.5: homeomorphic embedding and generalization in a higher-order setting

+/- is a feature

Page 68: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

68

The task: grammar transformation

doubleA = 𝜖 | a doubleA a doubleA = 𝜖 | a a doubleA

It Is Worth to Do!

I. Klyuchnikov. Towards effective two-level supercompilation. KIAM Preprint #81. 2010

Page 69: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

69

The task: grammar transformation

doubleA = 𝜖 | a doubleA a doubleA = 𝜖 | a a doubleA

L2(𝑆�−−−,𝑆�−−−), L2(𝑆�+−−,𝑆�+−−), L2(𝑆�−+−,𝑆�−+−),

L2(𝑆�−−+,𝑆�−−+), ... FAILURE

It Is Worth to Do!

I. Klyuchnikov. Towards effective two-level supercompilation. KIAM Preprint #81. 2010

Page 70: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

70

The task: grammar transformation

doubleA = 𝜖 | a doubleA a doubleA = 𝜖 | a a doubleA

L2(𝑆�−−−,𝑆�−−−), L2(𝑆�+−−,𝑆�+−−), L2(𝑆�−+−,𝑆�−+−),

L2(𝑆�−−+,𝑆�−−+), ... FAILURE

L2(𝑆�++−, 𝑆�+−−), ... SUCCESS

It Is Worth to Do!

I. Klyuchnikov. Towards effective two-level supercompilation. KIAM Preprint #81. 2010

Page 71: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

71

The task: grammar transformation

doubleA = 𝜖 | a doubleA a doubleA = 𝜖 | a a doubleA

L2(𝑆�−−−,𝑆�−−−), L2(𝑆�+−−,𝑆�+−−), L2(𝑆�−+−,𝑆�−+−),

L2(𝑆�−−+,𝑆�−−+), ... FAILURE

L2(𝑆�++−, 𝑆�+−−), ... SUCCESS

Interesting Pattern:L2(Sc

2, Sc

1) – Sc

2 should be a bit smarter than Sc

1 (A managing person should

be a bit clever than a person being managed)

It Is Worth to Do!

I. Klyuchnikov. Towards effective two-level supercompilation. KIAM Preprint #81. 2010

Page 72: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

72

V. Turchin. The phenomenon of Science

Page 73: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

73

Step #1: 2 Instances of a Supercompiler

Sc Sc

X

A ?? B

Y/N

Page 74: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

74

Step #2: 3 Instances of a Supercompiler

Sc Sc

X

A ?? BY/NSc

X'

| |

Page 75: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

75

Step #3: Combining 2 Supercompilers

Sc1

Sc1

X

A ?? BY/NSc

2

X'

| |

Page 76: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

76

Step #4: Combining Many Supercompilers

Sca

Sca

X

A ?? BY/NSc

2

X'

Scb Sc

cSc

b Scc

| |

Page 77: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

77

Step #5?

Sca

Sca

X

A ?? BY/NSc

2

X'

Scb Sc

cSc

b Scc

Sc1 Sc

3

| || | | |

Page 78: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

78

WE ARE LOOSING CONTROL

STOP

Page 79: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

79

The Plan● Supercompilation in a nutshell● Optimization vs Analysis● Analyzing supercompilation (HOSC)● Two-level supercompilation● Multi-result supercompilation (MRSC)● Finding a minimal proof by multi-result

supercompilation● On metasystem transitions

Page 80: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

80

There Is One More Elementary Operation Here:

Sca

Sca

X

A ?? BY/NSc

2

X'

Scb Sc

cSc

b Scc

Sc1 Sc

3

| | | || |

Page 81: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

81

There Is One More Elementary Operation Here:Multiplication of Supercompilers

Sca

Sca

X

A ?? BY/NSc

2

X'

Scb Sc

cSc

b Scc

Sc1 Sc

3

| | | || |

Page 82: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

82

Let's Treat Many Supercompilers asOne Multi-Result Supercompiler

Sc2

P1'

Sc2

P2'

Sc3

P3'

P

Page 83: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

83

Let's Treat Many Supercompilers as One Multi-Result Supercompiler

P1' P

2' P

3'

P

MSc

Page 84: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

84

Checking for the equivalence

Pa1

' Pa2

' Pa3

'

Pa

MSc

Pb1

' Pb2

' Pb3

'

Pb

MSc

Page 85: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

85

Checking for the equivalence

Pa1

' Pa2

' Pa3

'

Pa

MSc

Pb1

' Pb2

' Pb3

'

Pb

MSc

Page 86: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

86

Checking for the equivalence

Pa1

' Pa2

' Pa3

'

Pa

MSc

Pb1

' Pb2

' Pb3

'

Pb

MSc

Page 87: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

87

Checking for the equivalence

Pa1

' Pa2

' Pa3

'

Pa

MSc

Pb1

' Pb2

' Pb3

'

Pb

MSc

Pa2

'

Page 88: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

88

Checking for the equivalence

Pa1

' Pa2

' Pa3

'

Pa

MSc

Pb1

' Pb2

' Pb3

'

Pb

MSc

Pa2

'

Page 89: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

89

Supercompiler Combinatorstype SC prog = prog → prog

type MSC prog = prog → [prog]

MERGE :: [SC prog] → MSC prog

L2 :: SC prog → MSC prog → SC prog

Page 90: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

90

Supercompiler Combinatorstype SC prog = prog → prog

type MSC prog = prog → [prog]

MERGE :: [SC prog] → MSC prog

MERGE :: [MSC prog] → MSC prog

L2 :: SC prog → MSC prog → SC prog

L2 :: MSC prog → MSC prog → MSC prog

Page 91: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

91

Supercompiler Combinatorstype SC prog = prog → prog

type MSC prog = prog → [prog]

MERGE :: [SC prog] → MSC prog

MERGE :: [MSC prog] → MSC prog

L2 :: SC prog → MSC prog → SC prog

L2 :: MSC prog → MSC prog → MSC prog

BOOTSTRAP :: SC prog → MSC prog

Page 92: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

92

The Recipe● Driving● Folding● Whistle● Generalization

Page 93: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

93

The Recipe● Driving● Folding● Whistle● Generalization

● Driving● Folding● Whistle● Multi-

Generalization

Page 94: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

94

Standard Generalization (Sequence of Trees)

...

...

Page 95: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

95

Multi-Generalization (Tree of Trees)

...

...

gen1 gen2

Page 96: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

96

Multi-Generalization

Theorem

If whistle blows at any infinite branch and multi-generalization produces the finite number of variants, then the set of residual programs is finite.

I.Klyuchnikov and S. Romanenko. Multi-result supercompilation as branching growth of the penultimate level in metasystem transitions. PSI-2011.I. Klyuchnikov. MRSC: a framework for multi-result supercompilation. Preprint, Keldysh Institute of Applied Mathematics, 2011. To appear.

Page 97: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

97

MRSC (2011)● MRSC is the framework for constructing (multi-

result and two-level) supercompilers by combining strategies for whistle, multi-generalization and escape from whistles.

● https://github.com/ilya-klyuchnikov/mrsc● The preliminary results are exciting:

● Automatically finding minimal proofs of the correctness of coherence protocols.

● Automatic proof of commutativity of addition/multiplication by supercompilation.

● Automatic proof of correctness of sorting algorithms by supercompilation.

Page 98: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

98

The Taste of MRSCclass MultiSC(val ordering: PartialOrdering[SLLExpr])

extends GenericMultiMachine[Expr, DriveInfo[SLLExpr], Extra]

with SLLSyntax

with SLLSemantics

with SimpleDriving[SLLExpr]

with Folding[SLLExpr]

with PartialOrderingTermination[SLLExpr]

with InAdvanceAllGens[SLLExpr]

Page 99: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

99

The Plan● Supercompilation in a nutshell● Optimization vs Analysis● Analyzing supercompilation (HOSC)● Two-level supercompilation● Multi-result supercompilation (MRSC)● Finding a minimal proof by multi-result

supercompilation● On metasystem transitions

Page 100: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

100

Multi-result supercompilation is natural for program analysis

Example #4. Finding Minimal Proof

Page 101: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

101

Verification of Protocols

The model of cache-coherence protocols can be seen as a set of transition rules between states represented as a n-tuple of natural numbers.

The problemGiven a safe initial state, prove that unsafe state is unreachable.

The problem is well-studied and there is a lot of specialized methods to prove the correctness of protocols automatically.

Page 102: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

102

Verification by Supercompilation● A. Lisitsa and A. Nemytykh. Verification as a parameterized testing

(experiments with the SCP4 supercompiler) / 2007

● The proof is by program transformation:

– ∀events: safe (go init events) == true

General-pur-pose SC

Page 103: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

103

Verification by Supercompilation● A. Lisitsa and A. Nemytykh. Verification as a parameterized testing

(experiments with the SCP4 supercompiler) / 2007

● The proof is by program transformation:

– ∀events: safe (go init events) == true

● A series of works by A. Klimov (2010/2011)● Solving Coverability Problem for Monotonic Counter Systems by

Supercompilation

● Yet another algorithm for solving cover-ability problem for Monotonic Counter Systems

General-pur-pose SC

Minimalistic domain-specific SC

Page 104: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

104

Verification by Supercompilation● A. Lisitsa and A. Nemytykh. Verification as a parameterized testing

(experiments with the SCP4 supercompiler) / 2007

● The proof is by program transformation:

– ∀events: safe (go init events) == true

● A series of works by A. Klimov (2010/2011)● Solving Coverability Problem for Monotonic Counter Systems by

Supercompilation

● Yet another algorithm for solving cover-ability problem for Monotonic Counter Systems

● I. Klyuchnikov (2011)● Finding a minimal proof by

multi-result supercompilation

General-pur-pose SC

Minimalistic domain-specific SC

DSL-based factory-made multi-result SC

Page 105: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

105

Example #4. MOESI Protocolcase object MOESI extends Protocol { val start: OmegaConf = List(Omega, 0, 0, 0, 0)

val rules: List[TransitionRule] = List( { case List(i, m, s, e, o) if i>=1 => List(i-1, 0, s+e+1, 0, o+m) }, { case List(i, m, s, e, o) if e>=1 => List(i, m+1, s, e-1, o) }, { case List(i, m, s, e, o) if s+o>=1 => List(i+m+s+e+o-1, 0, 0, 1, 0) }, { case List(i, m, s, e, o) if i>=1 => List(i+m+s+e+o-1, 0, 0, 1, 0) })

def unsafe(c: OmegaConf) = c match { case List(i, m, s, e, o) if m>=1 && (e + s + o) >= 1 => true case List(i, m, s, e, o) if m>=2 => true case List(i, m, s, e, o) if e>=2 => true case _ => false }

}

Just mini-DSL in Scala

Page 106: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

106

Supercompiler in 3 slidessealed trait Component { def +(comp: Component): Component def -(comp: Component): Component def >=(i: Int): Boolean}

case class Value(i: Int) extends Component { override def +(comp: Component) = comp match { case Omega => Omega case Value(j) => Value(i + j) } override def -(comp: Component) = comp match { case Omega => Omega case Value(j) => Value(i – j) } override def >=(j: Int) = i >= j}

case object Omega extends Component { def +(comp: Component) = Omega def -(comp: Component) = Omega def >=(comp: Int) = true}

Page 107: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

107

Supercompiler in 3 slidestrait CountersPreSyntax extends PreSyntax[OmegaConf] { val instance = OmegaConfInstanceOrdering def rebuildings(c: OmegaConf) = gens(c) – c def gens(c: OmegaConf): List[OmegaConf] = c match { case Nil => List(Nil) case e :: c1 => for (cg <- genComp(e); gs <- gens(c1)) yield cg :: gs } def genComp(c: Component): List[Component] = c match { case Omega => List(Omega) case value => List(Omega, value) }}

trait CountersSemantics extends RewriteSemantics[OmegaConf] { val protocol: Protocol def drive(c: OmegaConf) = protocol.rules.map { _.lift(c) }}

object OmegaConfInstanceOrdering extends SimplePartialOrdering[OmegaConf] { def lteq(c1: OmegaConf, c2: OmegaConf) = (c1, c2).zipped.forall(lteq) def lteq(x: Component, y: Component) = (x, y) match { case (Omega, _) => true case (_, _) => x == y }}

Page 108: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

108

Supercompiler in 3 slidestrait LWhistle { val l: Int def unsafe(counter: OmegaConf) = counter exists { case Value(i) => i >= l case Omega => false }}

case class CounterMultiSc(val protocol: Protocol, val l: Int) extends CountersPreSyntax with LWhistle with CountersSemantics with RuleDriving[OmegaConf] with SimpleInstanceFoldingToAny[OmegaConf, Int] with SimpleUnaryWhistle[OmegaConf, Int] with ProtocolSafetyAware with SimpleGensWithUnaryWhistle[OmegaConf, Int]

Page 109: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

109

Proofs by supercompilation

A. Lisitsa and A. Nemytykh. Verification as a parameterized testing (experiments with the SCP4 supercompiler) / 2007

Page 110: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

110

Proofs by supercompilation

I. Klyuchnikov. MRSC: a framework for multi-result supercompilation / 2011

A. Lisitsa and A. Nemytykh. Verification as a parameterized testing (experiments with the SCP4 supercompiler) / 2007

Page 111: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

111

Proofs by supercompilation

22 steps 8 steps

I. Klyuchnikov. MRSC: a framework for multi-result supercompilation / 2011

A. Lisitsa and A. Nemytykh. Verification as a parameterized testing (experiments with the SCP4 supercompiler) / 2007

Page 112: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

112

Optimization and Analysis

...

Page 113: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

113

Optimization and Analysis

Sc1

Sc1

X

A ?? BY/NSc

2

X'

Sc2

Sc1

L2

| |

Page 114: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

114

Optimization and Analysis

Sc1

Sc1

X

A ?? BY/NSc

2

X'

Sc2

Sc1

L2

| |

optimizing

analyzing

Page 115: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

115

Optimization and Analysis

Sc1

Sc1

X

A ?? BY/NSc

2

X'

Sc2

Sc1

L2

| |

optimizing

optimizing

analyzing

Page 116: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

116

The Plan● Supercompilation in a nutshell● Optimization vs Analysis● Analyzing supercompilation (HOSC)● Two-level supercompilation● Multi-result supercompilation (MRSC)● Finding a minimal proof by multi-result

supercompilation● On metasystem transitions

Page 117: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

117

Metasystem Transition

Page 118: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

118

The “Formula” of Metasystem Transition

Control +

Branching Growth ⇒

Metasystem Transition

Page 119: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

119

Supercompilation

Sc

Sc1

Sc2

Scn

...

X

Sc3

Supercompilation is treated as an elementary operation.

Page 120: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

120

The “Formula” of Metasystem Transition

Control +

Branching Growth ⇒

Metasystem Transition

Two-Level Supercompilation +

Multi-Result Supercompilation ⇒

Metasystem Transition

Page 121: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

121

The “Formula” of Metasystem Transition

Control +

Branching Growth ⇒

Metasystem Transition

Two-Level Supercompilation +

Multi-Result Supercompilation ⇒

Metasystem Transition

The projection of the formula onto supercompilation

I.Klyuchnikov and S. Romanenko. Multi-result supercompilation as branching growth of the penultimate level in metasystem transitions. PSI-2011.

Page 122: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

122

Conslusion

Supercompilation is a unified method for:● Program optimization by transformation● Program analysis by transformation

Supercompilation is based on the idea of metasystem transitions.

Control + Branching Growth ⇒ Metasystem Transition

Page 123: Metacomputation A Gentle Introduction to Advanced Topicsilya/slides/gentle2.pdf · A Gentle Introduction to Advanced Topics ... Optimization vs Analysis ... Introduction to Supercompilation

123

Thanks you for your patience!

QUESTIONS?