examples and sets
DESCRIPTION
Examples and Sets. Synthesize each of These. choose (( x,y ) => 10 x + 14 y == a ) . choose (( x,y ) => 10 x + 14 y == a&& x < y ) . choose (( x,y ) => 10 x + 14 y == a && 0 < x && x < y ) . Constructive (Extended) Euclid’s Algorithm: gcd (10,14). - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Examples and Sets](https://reader035.vdocument.in/reader035/viewer/2022062520/56816103550346895dd047d3/html5/thumbnails/1.jpg)
Examples and Sets
![Page 2: Examples and Sets](https://reader035.vdocument.in/reader035/viewer/2022062520/56816103550346895dd047d3/html5/thumbnails/2.jpg)
Synthesize each of These
choose((x,y) => 10 x + 14 y == a )
choose((x,y) => 10 x + 14 y == a && x < y)
choose((x,y) => 10 x + 14 y == a && 0 < x && x < y)
![Page 3: Examples and Sets](https://reader035.vdocument.in/reader035/viewer/2022062520/56816103550346895dd047d3/html5/thumbnails/3.jpg)
Constructive (Extended) Euclid’s Algorithm: gcd(10,14)
10 1410 46 42 42 22 0
10 x + 14 y == 10 x + 14 y == a
![Page 4: Examples and Sets](https://reader035.vdocument.in/reader035/viewer/2022062520/56816103550346895dd047d3/html5/thumbnails/4.jpg)
Result of Synthesis for one Equation
choose((x,y) => 10 x + 14 y == a )
assert ( ) val x = val y =
check the solution:Change in requirements! Customer also wants: x < y
does our solution work for e.g. a=2
![Page 5: Examples and Sets](https://reader035.vdocument.in/reader035/viewer/2022062520/56816103550346895dd047d3/html5/thumbnails/5.jpg)
Idea: Eliminate Variables
x = 3/2 a + c1 zy = -a + c2 z
choose((x,y) => 10 x + 14 y == a && x < y)
Cannot easily eliminate one of the x,y.
Eliminate both x,y, get one free - z
Find general form, characterize all solutions,parametric solution
c1 = ?c2 = ?
![Page 6: Examples and Sets](https://reader035.vdocument.in/reader035/viewer/2022062520/56816103550346895dd047d3/html5/thumbnails/6.jpg)
Idea: Eliminate Variables
x = 3/2 a + c1 zy = -a + c2 z
choose((x,y) => 10 x + 14 y == a && x < y)
c1 = ?c2 = ?
10 x0 + 14 y0 + (10 c1 + 14 c2) == a10 c1 + 14 c2 == 0
![Page 7: Examples and Sets](https://reader035.vdocument.in/reader035/viewer/2022062520/56816103550346895dd047d3/html5/thumbnails/7.jpg)
x = 3/2 a + 5 zy = -a - 7 z
choose((x,y) => 10 x + 14 y == a && x < y)
![Page 8: Examples and Sets](https://reader035.vdocument.in/reader035/viewer/2022062520/56816103550346895dd047d3/html5/thumbnails/8.jpg)
Synthesis for setsdef splitBalanced[T](s: Set[T]) : (Set[T], Set[T]) = choose((a: Set[T], b: Set[T]) (⇒ a union b == s && a intersect b == empty && a.size – b.size ≤ 1 && b.size – a.size ≤ 1 ))
def splitBalanced[T](s: Set[T]) : (Set[T], Set[T]) = val k = ((s.size + 1)/2).floor val t1 = k val t2 = s.size – k val s1 = take(t1, s) val s2 = take(t2, s minus s1) (s1, s2) a
b
s
![Page 9: Examples and Sets](https://reader035.vdocument.in/reader035/viewer/2022062520/56816103550346895dd047d3/html5/thumbnails/9.jpg)
From Data Structures to Numbers• Observation:– Reasoning about collections reduces to reasoning
about linear integer arithmetic!
9
a.size == b.size && a union b == bigSet && a intersect b == empty
a b
bigSet
![Page 10: Examples and Sets](https://reader035.vdocument.in/reader035/viewer/2022062520/56816103550346895dd047d3/html5/thumbnails/10.jpg)
From Data Structures to Numbers• Observation:– Reasoning about collections reduces to reasoning
about linear integer arithmetic!
10
a.size == b.size && a union b == bigSet && a intersect b == empty
a b
bigSet
![Page 11: Examples and Sets](https://reader035.vdocument.in/reader035/viewer/2022062520/56816103550346895dd047d3/html5/thumbnails/11.jpg)
From Data Structures to Numbers• Observation:– Reasoning about collections reduces to reasoning
about linear integer arithmetic!
11
a.size == b.size && a union b == bigSet && a intersect b == empty
a b
bigSet
![Page 12: Examples and Sets](https://reader035.vdocument.in/reader035/viewer/2022062520/56816103550346895dd047d3/html5/thumbnails/12.jpg)
From Data Structures to Numbers• Observation:– Reasoning about collections reduces to reasoning
about linear integer arithmetic!
12
a.size == b.size && a union b == bigSet && a intersect b == empty
a b
bigSet
New specification:
kA = kB
![Page 13: Examples and Sets](https://reader035.vdocument.in/reader035/viewer/2022062520/56816103550346895dd047d3/html5/thumbnails/13.jpg)
From Data Structures to Numbers• Observation:– Reasoning about collections reduces to reasoning
about linear integer arithmetic!
13
a.size == b.size && a union b == bigSet && a intersect b == empty
a b
bigSet
New specification:
kA = kB && kA +kB = |bigSet|
![Page 14: Examples and Sets](https://reader035.vdocument.in/reader035/viewer/2022062520/56816103550346895dd047d3/html5/thumbnails/14.jpg)
![Page 15: Examples and Sets](https://reader035.vdocument.in/reader035/viewer/2022062520/56816103550346895dd047d3/html5/thumbnails/15.jpg)