vg-gppe.txt Sun Jan 3 20:59:22 1999 1 Generic Programming, Partial Evaluation, and a New Programming Paradigm Dr. Christopher Landauer Aerospace Integration Science Center The Aerospace Corporation cal@aero.org Dr. Kirstie L. Bellman, Principal Director Aerospace Integration Science Center The Aerospace Corporation bellman@aero.org
vg-gppe.txt Sun Jan 3 20:59:22 1999 2 Outline Introduction - Generic Programming . Goals and Progress, Examples - Partial Evaluation . Basic Approach, Futamura Projections, Performance Problem Posing Programming Paradigm Underlying Technology - Wrapping: Knowledge Based Integration Infrastructure . Coordination Manager, Study Manager, Meta-Recursion . Wrapping Knowledge Base Semantics - Wrex (Wrapping Expression notation) Applications - Coordination Languages - Reuse without Modification Conclusions - Partial Evaluation - Generic Programming
vg-gppe.txt Sun Jan 3 20:59:22 1999 3 Generic Programming Goals and Progress A goal of programming since the beginning - Get the right level of abstraction in algorithms Result would be - All and only the essential parts of the algorithm are displayed - All of the important characteristics of the execution environment can be made explicit and deferred to pre-compile time - Algorithm is then instantiated or adapted to fit the environment Generic Programming is about making programs more flexible - More interesting kinds of Polymorphism - More interesting kinds of parameters (e.g., programs, types, constructors, ...) Gradual improvements over the last 50 years: Machine language -> assemblers -> compilers -> interpreters Still looking for more effective techniques - Partial Evaluation looks like a good one
vg-gppe.txt Sun Jan 3 20:59:22 1999 4 Examples Algorithms are often written descriptively for explanation - We want those descriptions to be the actual generic programs Generic genetic programming algorithm: generate initial population loop until done compute offspring retain only the ones with best fitness Generic simulated annealing algorithm: set initial temperature and position loop until done generate potential new position check movement criterion reduce temperature Generic k-means clustering algorithm: generate initial cluster centers loop until done partition data into nearest-center clusters recompute cluster centers
vg-gppe.txt Sun Jan 3 20:59:22 1999 5 Partial Evaluation: Basic Approach Simple idea - If you know a program and some of the parameters, then you can specialize the program - The resulting specialized program should be (and often is) faster Difficult to make it work - Want completely automatic techniques - Requires compiler optimization methods . Symbolic execution . Partly unrolling iterations and recursions . Program point specialization: Replicate parts of program with different specializations, Definition Creation, Folding, Memoization - Need care in replication to avoid exponential blowup Imagine a program ‘‘mix’’ that can do partial evaluation: for all programs p, and all inputs in1 and in2, [[mix] (p, in1)] in2 = [p] (in1, in2), so mix specializes p to the inputs in1 (such programs do exist for some languages) Partial evaluation provides an adaptation mechanism for generic programs
vg-gppe.txt Sun Jan 3 20:59:22 1999 6 Futamura Projections We can get compilers and compiler generators out of partial evaluators (1970) Definition: An interpreter is a program interp for which: for all inputs in, and all source programs s, [interp] (s, in) = [s] in We claim that a kind of ‘‘compilation target’’ t for source program s can be computed: t = [mix] (interp, s), since for any input in, out = [s] in = [interp] (s, in) = [[mix] (interp, s)] in = [t] in, so mix specializes the interpreter via part of its input (the source program s) Now comp = [mix] (mix, interp) turns out to be a compiler for the language interpreted by interp: for any source program s, the compilation target t has t = [mix] (interp, s) = [[mix] (mix, interp) ] s = [comp] s
vg-gppe.txt Sun Jan 3 20:59:22 1999 7 Futamura Projections (continued) So far, t = [mix] (interp, s) is a compiled form of s, comp = [mix] (mix, interp) is a compiler for the language interp interprets Finally, cogen = [mix] (mix, mix) is a compiler generator for the language interp is written in: for any interpreter interp, source program s, and input in, [s] in = [interp] (s, in) = [[mix] (interp, s)] in = [[[mix] (mix, interp)] s ] in = [[[[mix] (mix, mix)] interp] s] in, = [[[cogen] interp] s] in so [cogen] interp = [comp] is a compiler for the language of s
vg-gppe.txt Sun Jan 3 20:59:22 1999 8 Performance of Partial Evaluation The use of these formal projections looks nice - The performance of the programs is important Two ways to produce output with these notions: out = [interp] (s, in) = [s] in t = [mix] (interp, s) = [comp] s comp = [mix] (mix, interp) = [cogen] interp cogen = [mix] (mix, mix) = [cogen] mix The second way is often something like 10 times faster The first way is usually much easier to write (once the program mix is written) We want to use this fact to write faster programs more easily
vg-gppe.txt Sun Jan 3 20:59:22 1999 9 Problem Posing Programming Paradigm All programming languages have a notion of information service - Information service requests - Information service providers We connect them now by using the same names ‘‘Problem Posing’’ is a new declarative programming style - Unifies all major classes of programming Programs interpreted in this style ‘‘pose problems’’; they do not - ‘‘call functions’’, - ‘‘issue commands’’, - ‘‘assert constraints’’, or - ‘‘send messages’’ (these are information service requests) Program fragments are ‘‘resources’’ that can be ‘‘applied’’ to problems; they are not - ‘‘functions’’, - ‘‘modules’’, - ‘‘clauses’’, or - ‘‘objects’’ that do things (these are information service providers)
vg-gppe.txt Sun Jan 3 20:59:22 1999 10 Problem Posing Programming Paradigm (continued) The Problem Posing interpretation separates the requests from the providers - Easy: compilers and interpreters always know the difference anyway - So do we when we write the programs We call the service requests ‘‘posed problems’’ We call the service providers ‘‘resources’’ We can connect them through knowledge bases (or other means) - ‘‘Knowledge-Based’’ Polymorphism maps problems to resources . From the problem specification in its context . To the computational resources that will organize the solution Any programming language can be interpreted in this new way (well, almost any) Problem Posing changes the semantics of programming languages, not the syntax - It makes a program an organized collection of posed problems . Instead of an organized collection of solutions without problems - That should make programs easier to understand . Because the problems at all levels of detail remain in it
vg-gppe.txt Sun Jan 3 20:59:22 1999 11 Examples C - Functions are resources, so are data structures - Function calls and Data accesses are posed problems - Each function relates a posed problem to an algorithm that poses other problems - Data structures are used by other resources to retain and provide data Lisp - S-expressions are resources (some are applicable, others not) - Applications are posed problems - Each applicable S-expression relates a posed problem to an algorithm that poses other problems - Other S-expressions are used by other resources to retain and provide data Smalltalk - Methods are resources, so are other object components - Messages are posed problems - Each method relates a posed problem, with some constraints on parameters (including which object receives the message), to other posed problems - Other object components are used by other resources to retain and provide data Prolog - Clauses are resources, so are tuples - Terms are posed problems - Each clause relates a posed problem, with some constraints on parameters, to other posed problems - Tuples are used by other resources to retain and provide data
vg-gppe.txt Sun Jan 3 20:59:22 1999 12 Wrapping: Knowledge Based Integration Infrastructure Problem Posing is particularly effective in combination with ‘‘wrappings’’ Computationally reflective knowledge-based integration infrastructure - Explicit, machine-processable information about resource uses AND - Active processes that use the information Wrapping has four main features - Everything is a ‘‘resource’’ that provides an information service . Tools, components, interfaces, even architectures - Every activity is ‘‘problem study’’: . A resource is ‘‘applied’’ to a ‘‘posed problem’’ . Separate problem to be studied from the resources that might study it - Wrappings are meta-knowledge about the uses of resources: . Not just ‘‘how’’, but ‘‘when’’, ‘‘why’’ and ‘‘whether’’ . Wrapping Knowledge Bases (WKBs) contain all the wrappings - Problem Managers (PMs) organize the use of resources . Use implicit invocation, both context and problem dependent . Knowledge-Based Polymorphism . These wrapping processes are also resources; they are also wrapped (Computational Reflection) . Coordination Manager (CM) and Study Manager (SM) are two PMs
Recommend
More recommend