Download presentation
Presentation is loading. Please wait.
1
Lecture 8 Functional synthesis
Xiaokang Qiu
2
Moving beyond Inductive synthesis
We want to synthesize functions that satisfy richer correctness criteria Key questions Specification formalisms How do we describe the intended behavior? How do we ensure correctness No longer trivial as in the inductive case Synthesis approaches Deductive vs. inductive
3
The general synthesis problem
∃ 𝑃 ∀ 𝑖𝑛 𝑖𝑛, 𝑃⊨𝑆𝑝𝑒𝑐 ∃ 𝑐 ∀ 𝑖𝑛 𝑖𝑛, 𝑆𝑘(𝑐)⊨𝑆𝑝𝑒𝑐
4
Defining correctness 𝑛≥0∧ 𝑛 ≤ 𝑙𝑒𝑛(𝑖𝑛) out=Sort(n, in)
Precondition: 𝑛≥0∧ 𝑛 ≤ 𝑙𝑒𝑛(𝑖𝑛) out=Sort(n, in) Postcondition: ∀𝑖. 0≤𝑖<𝑛−1⇒𝑜𝑢𝑡 𝑖 ≤𝑜𝑢𝑡 𝑖+1 𝑙𝑒𝑛 𝑜𝑢𝑡 =𝑛 ∀𝑖. 0≤𝑖<𝑛−1⇒∃𝑗 𝑖𝑛 𝑗 =𝑜𝑢𝑡[𝑖] ∀𝑖. 0≤𝑖<𝑛−1⇒∃𝑗 𝑖𝑛 𝑖 =𝑜𝑢𝑡[𝑗] ∃𝑃:𝑖𝑛𝑡→𝑖𝑛𝑡. ∀𝑖. 𝑖<𝑛⇒ 𝑜𝑢𝑡 𝑖 =𝑖𝑛 𝑃(𝑖) ∧∃𝑗. 𝑃 𝑗 =𝑖
5
Multimodal Synthesis Trick: Synthesizer Synthesizer
combine many simple specs in different formalisms to fully constrain the behavior Concrete scenarios Abstract scenarios Correct Code Partial specs Synthesizer Synthesizer Safety properties Structural Info
6
Ensuring correctness ∀ 𝑖𝑛 𝑖𝑛, 𝑃⊨𝑆𝑝𝑒𝑐 This is a hard problem in general
Two points of view: Not my problem That’s what program verification is for Synthesis should be guided by verification Synthesize code that is easier to prove correct Ensure correctness by construction ∀ 𝑖𝑛 𝑖𝑛, 𝑃⊨𝑆𝑝𝑒𝑐
7
CEGIS Counterexample guided inductive synthesis Ideas
Rely on an oracle to tell you if your program is correct If it is not, rely on oracle to generate counterexample inputs Reduce to an inductive synthesis problem
8
CEGIS 𝒊𝒏 Synthesize Check {𝒊 𝒏 𝒊 } ∃𝑷 𝒔.𝒕. 𝑪𝒐𝒓𝒓𝒆𝒄𝒕(𝑷, 𝒊 𝒏 𝒊 )
Insert your favorite checker here ∃𝑷 𝒔.𝒕. 𝑪𝒐𝒓𝒓𝒆𝒄𝒕(𝑷, 𝒊 𝒏 𝒊 ) ∃𝒊𝒏 𝒔.𝒕. ¬𝑪𝒐𝒓𝒓𝒆𝒄𝒕(𝑷, 𝒊 𝒏 𝒊 ) 𝒊𝒏 {𝒊 𝒏 𝒊 }
9
CEGIS in Sketch ∃ 𝑐 ∀ 𝑖𝑛 𝑖𝑛, 𝑆𝑘(𝑐)⊨𝑆𝑝𝑒𝑐 ∃ 𝑃 ∀ 𝑖𝑛 𝑖𝑛, 𝑃⊨𝑆𝑝𝑒𝑐
∃ 𝑐 ∀ 𝑖𝑛 𝑖𝑛, 𝑆𝑘(𝑐)⊨𝑆𝑝𝑒𝑐 ∃ 𝑃 ∀ 𝑖𝑛 𝑖𝑛, 𝑃⊨𝑆𝑝𝑒𝑐 ∃ 𝑐 ∀ 𝑖𝑛 𝑄 𝑖𝑛, 𝑐
10
CEGIS in Sketch 𝒄 𝒊𝒏 𝑸(𝒄, 𝒊𝒏) Synthesize Check {𝒊 𝒏 𝒊 } 𝑸 (𝒄, 𝒊 𝒏 𝟎 )
+ b a c d A 𝑸(𝒄, 𝒊𝒏) Synthesize Check 𝒄 𝒊𝒏 𝑸 (𝒄, 𝒊 𝒏 𝟎 ) ¬𝑸 (𝒄, 𝒊 𝒏 𝟒 ) ¬𝑸 (𝒄, 𝒊 𝒏 𝟑 ) ¬𝑸 (𝒄, 𝒊 𝒏 𝟏 ) ¬𝑸 (𝒄, 𝒊 𝒏 𝟐 ) 𝑸 (𝒄, 𝒊 𝒏 𝟐 ) 𝑸 (𝒄, 𝒊 𝒏 𝟑 ) {𝒊 𝒏 𝒊 }
11
Example N = 18 P = 5 You want to partition N elements over P procs
How many elements should a processor get? Obvious answer is N/P Obvious answer is wrong! N = 18 P = 5
12
Synthesizing a partition function
What do we know? The interface to the function we want Not all processors will get the same # of elements The kind of expressions we expect void partition(int p, int P, int N, ref int ibeg, ref int iend){ if(p< expr({p, P, N, N/P, N%P},{PLUS,TIMES}) ){ iend = expr({p, P, N, N/P, N%P},{PLUS,TIMES}); ibeg = expr({p, P, N, N/P, N%P},{PLUS,TIMES}); }else{ } p P N N/P N%P * +
13
Synthesizing a partition function
How does the system know what a partition is? harness void testPartition(int p, int N, int P){ if(p>=P || P < 1){ return; } int ibeg, iend; partition(p, P, N, ibeg, iend); assert iend - ibeg < (N/P) + 2; if(p+1 < P){ int ibeg2, iend2; partition(p+1, P, N, ibeg2, iend2); assert iend == ibeg2; } if(p==0){ assert ibeg == 0; } if(p==P-1){ assert iend == N; } Partitions should be balanced Adjacent partitions should match First and last partition should go all the way to the ends
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.