program synthesis

Uses your system voice; voice and rate in settings.

Q4117718Snapshot

≈ 6 min read

Names in other languages

  • Françaissynthèse de programmes
  • Englishprogram synthesis
  • עבריתסינתזה של תוכניות
  • ไทยProgram synthesis
  • العربيةتكوين البرنامج
  • daprogramsyntese
  • 日本語プログラム合成
  • 中文程序合成

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

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 automation. In contrast to automatic programming techniques, specifications in program synthesis are usually non-algorithmic statements in an appropriate logical calculus. The primary application of program synthesis is to relieve the programmer of the burden of writing correct, efficient code that satisfies a specification. However, program synthesis also has applications to superoptimization and inference of loop invariants.

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 automation. In contrast to automatic programming techniques, specifications in program synthesis are usually non-algorithmic statements in an appropriate logical calculus. The primary application of program synthesis is to relieve the programmer of the burden of writing correct, efficient code that satisfies a specification. However, program synthesis also has applications to superoptimization and inference of loop invariants. ::= x | y | 0 | 1 | + | ite( , , ) ::= where "ite" stands for "if-then-else". The expression ite(x = (f x y) x)) (constraint (>= (f x y) y)) (constraint (or (= (f x y) x) (= (f x y) y))) (check-synth) A compliant solver might return the following output: ((define-fun f ((x Int) (y Int)) Int (ite ( E from 51 and F from 52 which both share some common subformula p . The resolvent is formed as the disjunction of E , with p replaced by \it true , and F , with p replaced by \it false . This resolvent logically follows from the conjunction of E and F . More generally, E and F need to have only two unifiable subformulas p_1 and p_2 , respectively; their resolvent is then formed from E \theta and F \theta as before, where \theta is the most general unifier of p_1 and p_2 . This rule generalizes resolution of clauses. Program terms of parent formulas are combined as shown in line 58 to form the output of the resolvent. In the general case, \theta is applied to the latter also. Since the subformula p appears in the output, care must be taken to resolve only on subformulas corresponding to computable properties. Logical transformations. For example, E \land (F \lor G) can be transformed to (E \land F) \lor (E \land G) ) 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. Structural induction. This rule allows for synthesis of recursive functions. For a given pre- and postcondition "Given x such that \textit{pre}(x) , find f(x) = y such that \textit{post}(x,y) ", and an appropriate user-given well-ordering \prec of the domain of x , it is always sound to add an Assertion " x' \prec x \land \textit{pre}(x') \implies \textit{post}(x',f(x')) ". Resolving with this assertion can introduce a recursive call to f 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 (n',d') \prec (n,d) defined by 0 \leq n' (p.110). Murray has shown these rules to be complete for first-order logic. In 1986, Manna and Waldinger added generalized E-resolution and paramodulation rules to handle also equality; later, these rules turned out to be incomplete (but nevertheless sound).

Example

As a toy example, a functional program to compute the maximum M of two numbers x and y can be derived as follows. Starting from the requirement description "The maximum is larger than or equal to any given number, and is one of the given numbers", the first-order formula \forall X \forall Y \exists M: X \leq M \land Y \leq M \land (X=M \lor Y=M) is obtained as its formal translation. This formula is to be proved. By reverse Skolemization, the specification in line 10 is obtained, an upper- and lower-case letter denoting a variable and a Skolem constant, respectively. After applying a transformation rule for the distributive law in line 11, the proof goal is a disjunction, and hence can be split into two cases, viz. lines 12 and 13. Turning to the first case, resolving line 12 with the axiom in line 1 leads to instantiation of the program variable M in line 14. Intuitively, the last conjunct of line 12 prescribes the value that M must take in this case. Formally, the non-clausal resolution rule shown in line 57 above is applied to lines 12 and 1, with being the common instance of and , obtained by syntactically unifying the latter formulas, being , obtained from instantiated line 1 (appropriately padded to make the context around visible), and being , obtained from instantiated line 12, yielding \lnot ( ) , which simplifies to x \leq x \land y \leq x . In a similar way, line 14 yields line 15 and then line 16 by resolution. Also, the second case, x \leq M \land y \leq M \land y = M in line 13, is handled similarly, yielding eventually line 18. In a last step, both cases (i.e. lines 16 and 18) are joined, using the resolution rule from line 58; to make that rule applicable, the preparatory step 15→16 was needed. Intuitively, line 18 could be read as "in case x \leq y , the output y is valid (with respect to the original specification), while line 15 says "in case y \leq x , the output x is valid; the step 15→16 established that both cases 16 and 18 are complementary. Since both line 16 and 18 comes with a program term, a conditional expression results in the program column. Since the goal formula \textit{true} has been derived, the proof is done, and the program column of the " \textit{true} " line contains the program.

Notes

Text derived from https://en.wikipedia.org/w/index.php?oldid=1371077386 under CC BY-SA 4.0; modifications have been made.

Sources cited in this revision

No external citation was extracted for this revision. That is a statement about the source, not a claim that none exists.