1 / 20

Software Synthesis

Software Synthesis. Ruzica Piskac Max Planck Institute for Software Systems, Germany. What is a Program?. Program = a sequence of commands describing what needs to be done. val bigSet = .... val ( setA , setB ) = choose ((a: Set, b: Set) ) =>

hans
Download Presentation

Software Synthesis

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Software Synthesis RuzicaPiskac Max Planck Institute for Software Systems, Germany

  2. What is a Program? • Program = a sequence of commands describing what needs to be done valbigSet = .... val (setA, setB) = choose((a: Set, b: Set) ) => ( a.size == b.size && a union b == bigSet && a intersect b == empty)) Code val n = bigSet.size/2 valsetA = take(n, bigSet) valsetB = bigSet −− setA

  3. What is a Program? • Program = a sequence of commands describing what needs to be done val bigSet = .... val (setA, setB) = choose((a: Set, b: Set) ) => ( a.size == b.size && a union b == bigSet && a intersect b == empty)) Code assert (bigSet.sizeis an even number) val n = bigSet.size/2 valsetA = take(n, bigSet) valsetB = bigSet −− setA

  4. Sorting algorithm • Why should we sort data? • Practical exercise: • Form a line, where you are sorted by your first name, from Aaron to Zoe

  5. Arrays • Data structure: • A[0] = 23, A[1]=4, A[2]=6, A[3]=15, A[4]=5, A[5]=7

  6. Specification • Array a2 is a sorted version of array a1 • Define the counting function and

  7. Automated Reasoning • decision procedure answers whether the input formula is satisfiable or not • formula is satisfiable for x=0, y=1 • formula is unsatisfiable satisfiable(model) theorem prover based on DECISION PROCEDURES formula in some logic unsatisfiable (proof)

  8. Synthesis for Linear Integer Arithmetic choose((h: Int, m: Int, s: Int) ⇒ ( h * 3600 + m * 60 + s == totalSeconds && h ≥ 0 && m ≥ 0 && m < 60 && s ≥ 0 && s < 60 )) Returned code: assert (totalSeconds ≥ 0) val h = totalSecondsdiv 3600 valtemp = totalSeconds + (-3600) * h valm = min(temp div60, 59) vals = totalSeconds + (-3600) * h + (-60) * m

  9. Linear Integer Arithmetic - Equalities h * 3600 + m * 60 + s == totalSeconds Code: <further code will come here> valh = lambda valm = mu valvals = totalSeconds + (-3600) * lambda + (-60) * mu

  10. Linear Integer Arithmetic - Equalities h * 3600 + m * 60 + s == totalSeconds Resulting formula (new specifications): 0 ≤ λ, 0 ≤ μ, μ ≤ 59, 0 ≤ totalSeconds – 3600λ - 60μ, totalSeconds – 3600λ - 60μ ≤ 59 10

  11. Linear Integer Arithmetic - Inequalities 0 ≤ λ, 0 ≤ μ, μ ≤ 59, 0 ≤ totalSeconds – 3600λ - 60μ, totalSeconds – 3600λ - 60μ ≤ 59 expressing constraints as bounds on μ 0 ≤ λ, 0 ≤ μ, μ ≤ 59, μ ≤ ⌊(totalSeconds – 3600λ)/60⌋ , ⌈(totalSeconds – 3600λ – 59)/60⌉ ≤ μ Code: valmu = min(59, (totalSeconds -3600* lambda) div 60)

  12. Linear Integer Arithmetic - Inequalities 0 ≤ λ, 0 ≤ μ, μ ≤ 59, μ ≤ ⌊(totalSeconds – 3600λ)/60⌋ , ⌈(totalSeconds – 3600λ – 59)/60⌉ ≤ μ combine each lower and upper bound 0 ≤ λ, 0 ≤ 59, 0 ≤ ⌊(totalSeconds – 3600λ)/60⌋ , ⌈(totalSeconds – 3600λ – 59)/60⌉ ≤ ⌊(totalSeconds – 3600λ)/60⌋ , ⌈(totalSeconds – 3600λ – 59)/60⌉ ≤ 59 basic simplifications Code: vallambda = totalSecondsdiv 3600 Preconditions: 0 ≤ totalSeconds 0 ≤ λ, 60λ ≤ ⌊totalSeconds/60⌋, ⌈(totalSeconds –59)/60⌉ – 59 ≤ 60λ

  13. Synthesis for Sets • Observation: • Reasoning about collections reduces to reasoning about linear integer arithmetic! a.size == b.size && a union b == bigSet && a intersect b == empty a b bigSet

  14. Synthesis for Sets • Observation: • Reasoning about collections reduces to reasoning about linear integer arithmetic! a.size == b.size && a union b == bigSet && a intersect b == empty a b bigSet

  15. Synthesis for Sets • Observation: • Reasoning about collections reduces to reasoning about linear integer arithmetic! a.size == b.size && a union b == bigSet && a intersect b == empty a b bigSet

  16. Synthesis for Sets • Observation: • Reasoning about collections reduces to reasoning about linear integer arithmetic! a.size == b.size&& a union b == bigSet && a intersect b == empty New specification: kA = kB a b bigSet

  17. Synthesis for Sets • Observation: • Reasoning about collections reduces to reasoning about linear integer arithmetic! a.size == b.size && a union b == bigSet && a intersect b == empty New specification: kA = kB && kA +kB = |bigSet| a b bigSet

  18. Synthesis: Applications • Automatic code completion • Flash Fill feature in the new Microsoft Excell (video!) • Available at: http://research.microsoft.com/en-us/um/people/sumitg/flashfillextensions.wmv

  19. InSynth • InSynth – a tool for synthesis of code fragments (snippets) • interactive • getting results in a short amount of time • multiple solutions – a user needs to select • component based • assemble program from given components (local values, API) • partial specification • hard constraints – type constraints • soft constraints - use of components “most likely” to be useful

More Related