Program synthesis
In computer science, program synthesis is the task to construct a program that provably satisfies a given high-level formal specification. In contrast to program verification, the program is to be constructed rather than given; however, both fields make use of formal proof techniques, and both comprise approaches of different degrees of automatization. In contrast to automatic programming techniques, specifications in program synthesis are usually non-algorithmic statements in an appropriate logical calculus.[1]
Origin
During the Summer Institute of Symbolic Logic at Cornell University in 1957, Alonzo Church defined the problem to synthesize a circuit from mathematical requirements.[2] Even though the work only refers to circuits and not programs, the work is considered to be one of the earliest descriptions of program synthesis and some researchers refer to program synthesis as "Church's Problem". In the 1960s, a similar idea for an "automatic programmer" was explored by researchers in artificial intelligence.[citation needed]
Since then, various research communities considered the problem of program synthesis. Notable works include the 1969 automata-theoretic approach by Büchi and Landweber,[3] and the works by Manna and Waldinger (c. 1980). The development of modern high-level programming languages can also be understood as a form of program synthesis.
21st century developments
The early 21st century has seen a surge of practical interest in the idea of program synthesis in the formal verification community and related fields. Armando Solar-Lezama showed that it is possible to encode program synthesis problems in Boolean logic and use algorithms for the Boolean satisfiability problem to automatically find programs.[4] In 2013, a unified framework for program synthesis problems was proposed by researchers at UPenn, UC Berkeley, and MIT.[5] Since 2014 there has been a yearly program synthesis competition comparing the different algorithms for program synthesis in a competitive event, the Syntax-Guided Synthesis Competition or SyGuS-Comp.[6] Still, the available algorithms are only able to synthesize small programs.
The framework of Manna and Waldinger
Nr | Assertions | Goals | Program | Origin |
---|---|---|---|---|
51 | ||||
52 | ||||
53 | s | |||
54 | t | |||
55 | Resolve(51,52) | |||
56 | s | Resolve(52,53) | ||
57 | s | Resolve(53,52) | ||
58 | p ? s : t | Resolve(53,54) |
The framework of Manna and Waldinger, published in 1980,[7][8] starts from a user-given first-order specification formula. For that formula, a proof is constructed, thereby also synthesizing a functional program from unifying substitutions.
The framework is presented in a table layout, the columns containing:
- A line number ("Nr") for reference purposes
- Formulas that already have been established, including axioms and preconditions, ("Assertions")
- Formulas still to be proven, including postconditions, ("Goals"),[note 1]
- Terms denoting a valid output value ("Program")[note 2]
- A justification for the current line ("Origin")
Initially, background knowledge, pre-conditions, and post-conditions are entered into the table. After that, appropriate proof rules are applied manually. The framework has been designed to enhance human readability of intermediate formulas: contrary to classical resolution, it does not require clausal normal form, but allows one to reason with formulas of arbitrary structure and containing any junctors ("non-clausal resolution"). The proof is complete when has been derived in the Goals column, or, equivalently, in the Assertions column. Programs obtained by this approach are guaranteed to satisfy the specification formula started from; in this sense they are correct by construction.[9] Only a minimalist, yet Turing-complete, functional programming language, consisting of conditional, recursion, and arithmetic and other operators[note 3] is supported. Case studies performed within this framework synthesized algorithms to compute e.g. division, remainder,[10] square root,[11] term unification,[12] answers to relational database queries[13] and several sorting algorithms.[14][15]
Proof rules
Proof rules include:
- Non-clausal resolution (see table).
- For example, line 55 is obtained by resolving Assertion formulas from 51 and from 52 which both share some common subformula . The resolvent is formed as the disjunction of , with replaced by , and , with replaced by . This resolvent logically follows from the conjunction of and . More generally, and need to have only two unifiable subformulas and , respectively; their resolvent is then formed from and as before, where is the most general unifier of and . This rule generalizes resolution of clauses.[16]
- Program terms of parent formulas are combined as shown in line 58 to form the output of the resolvent. In the general case, is applied to the latter also. Since the subformula appears in the output, care must be taken to resolve only on subformulas corresponding to computable properties.
- Logical transformations.
- For example, can be transformed to ) in Assertions as well as in Goals, since both are equivalent.
- Splitting of conjunctive assertions and of disjunctive goals.
- An example is shown in lines 11 to 13 of the toy example below.
- This rule allows for synthesis of recursive functions. For a given pre- and postcondition "Given such that , find such that ", and an appropriate user-given well-ordering of the domain of , it is always sound to add an Assertion "".[17] Resolving with this assertion can introduce a recursive call to in the Program term.
- An example is given in Manna, Waldinger (1980), p.108-111, where an algorithm to compute quotient and remainder of two given integers is synthesized, using the well-order defined by (p.110).
Murray has shown these rules to be complete for first-order logic.[18] In 1986, Manna and Waldinger added generalized E-resolution and paramodulation rules to handle also equality;[19] later, these rules turned out to be incomplete (but nevertheless sound).[20]
See also
- Inductive programming
- Metaprogramming
- Program derivation
- Natural language programming
- Reactive synthesis
Notes
- ^ The distinction "Assertions" / "Goals" is for convenience only; following the paradigm of proof by contradiction, a Goal is equivalent to an assertion .
- ^ When and is the Goal formula and the Program term in a line, respectively, then in all cases where holds, is a valid output of the program to be synthesized. This invariant is maintained by all proof rules. An Assertion formula usually is not associated with a Program term.
- ^ Only the conditional operator (?:) is supported from the beginning. However, arbitrary new operators and relations can be added by providing their properties as axioms. In the toy example below, only the properties of and that are actually needed in the proof have been axiomatized, in line 1 to 3.
References
- ^ Basin, D.; Deville, Y.; Flener, P.; Hamfelt, A.; Fischer Nilsson, J. (2004). "Synthesis of programs in computational logic". In M. Bruynooghe and K.-K. Lau (ed.). Program Development in Computational Logic. LNCS. Vol. 3049. Springer. pp. 30–65. CiteSeerX 10.1.1.62.4976.
- ^ Alonzo Church (1957). "Applications of recursive arithmetic to the problem of circuit synthesis". Summaries of the Summer Institute of Symbolic Logic. 1: 3–50.
- ^ Richard Büchi, Lawrence Landweber (Apr 1969). "Solving Sequential Conditions by Finite-State Strategies". Transactions of the American Mathematical Society. 138: 295–311. doi:10.2307/1994916. JSTOR 1994916.
- ^ Solar-Lezama, Armando (2008). Program synthesis by sketching (PDF) (Ph.D.). University of California, Berkeley.
- ^ Alur, Rajeev; al., et (2013). "Syntax-guided Synthesis". Proceedings of Formal Methods in Computer-Aided Design. IEEE. p. 8.
- ^ SyGuS-Comp (Syntax-Guided Synthesis Competition)
- ^ Zohar Manna, Richard Waldinger (Jan 1980). "A Deductive Approach to Program Synthesis". ACM Transactions on Programming Languages and Systems. 2: 90–121. doi:10.1145/357084.357090. S2CID 14770735.
- ^ Zohar Manna and Richard Waldinger (Dec 1978). A Deductive Approach to Program Synthesis (PDF) (Technical Note). SRI International.
- ^ See Manna, Waldinger (1980), p.100 for correctness of the resolution rules.
- ^ Manna, Waldinger (1980), p.108-111
- ^ Zohar Manna and Richard Waldinger (Aug 1987). "The Origin of a Binary-Search Paradigm". Science of Computer Programming. 9 (1): 37–83. doi:10.1016/0167-6423(87)90025-6.
- ^ Daniele Nardi (1989). "Formal Synthesis of a Unification Algorithm by the Deductive-Tableau Method". Journal of Logic Programming. 7: 1–43. doi:10.1016/0743-1066(89)90008-3.
- ^ Daniele Nardi and Riccardo Rosati (1992). "Deductive Synthesis of Programs for Query Answering". In Kung-Kiu Lau and Tim Clement (ed.). International Workshop on Logic Program Synthesis and Transformation (LOPSTR). Workshops in Computing. Springer. pp. 15–29. doi:10.1007/978-1-4471-3560-9_2.
- ^ Jonathan Traugott (1986). "Deductive Synthesis of Sorting Programs". Proceedings of the International Conference on Automated Deduction. LNCS. Vol. 230. Springer. pp. 641–660.
- ^ Jonathan Traugott (Jun 1989). "Deductive Synthesis of Sorting Programs". Journal of Symbolic Computation. 7 (6): 533–572. doi:10.1016/S0747-7171(89)80040-9.
- ^ Manna, Waldinger (1980), p.99
- ^ Manna, Waldinger (1980), p.104
- ^ Manna, Waldinger (1980), p.103, referring to: Neil V. Murray (Feb 1979). A Proof Procedure for Quantifier-Free Non-Clausal First Order Logic (Technical report). Syracuse Univ. 2-79.
- ^ Zohar Manna, Richard Waldinger (Jan 1986). "Special Relations in Automated Deduction". Journal of the ACM. 33: 1–59. doi:10.1145/4904.4905. S2CID 15140138.
- ^ Zohar Manna, Richard Waldinger (1992). "The Special-Relations Rules are Incomplete". Proc. CADE 11. LNCS. Vol. 607. Springer. pp. 492–506.
- Zohar Manna, Richard Waldinger (1975). "Knowledge and Reasoning in Program Synthesis". Artificial Intelligence. 6 (2): 175–208. doi:10.1016/0004-3702(75)90008-9.