Motivation Outline Framework Translation Data Abstractions Evaluation Discussion Summary Unifying Execution of Imperative and Declarative Code Aleksandar Milicevic Massachusetts Institute of Technology Cambridge, MA RQE Defense, MIT May 03, 2011 Unifying Execution of Imperative and Declarative Code Aleksandar Milicevic 1
Motivation Outline Framework Translation Data Abstractions Evaluation Discussion Summary Solving Sudoku Sudoku puzzle : fill in the empty cells s.t.: 1. cell values are in { 1 , 2 , ··· , 9 } 2. all rows have distinct values 3. all columns have distinct values 4. all sub-grids have distinct values Unifying Execution of Imperative and Declarative Code Aleksandar Milicevic 2
Motivation Outline Framework Translation Data Abstractions Evaluation Discussion Summary Solving Sudoku Sudoku puzzle : fill in the empty cells s.t.: 1. cell values are in { 1 , 2 , ··· , 9 } 2. all rows have distinct values 3. all columns have distinct values 4. all sub-grids have distinct values Approaches : write a custom (heuristic-based) algorithm [ imperative ] write a set of constraints and use a constraint solver [ declarative ] Unifying Execution of Imperative and Declarative Code Aleksandar Milicevic 2
Motivation Outline Framework Translation Data Abstractions Evaluation Discussion Summary Solving Sudoku Sudoku puzzle : fill in the empty cells s.t.: 1. cell values are in { 1 , 2 , ··· , 9 } 2. all rows have distinct values 3. all columns have distinct values 4. all sub-grids have distinct values Approaches : write a custom (heuristic-based) algorithm [ imperative ] write a set of constraints and use a constraint solver [ declarative ] Unifying Execution of Imperative and Declarative Code Aleksandar Milicevic 2
Motivation Outline Framework Translation Data Abstractions Evaluation Discussion Summary Solving Sudoku with Squander Unifying Execution of Imperative and Declarative Code Aleksandar Milicevic 3
Motivation Outline Framework Translation Data Abstractions Evaluation Discussion Summary Solving Sudoku with Squander public class Sudoku { private f i n a l int n = 9; private f i n a l int [ ] [ ] regions = new int [ ] { new int [ ] { 0 , 1 , 2 } , new int [ ] { 3 , 4 , 5 } , new int [ ] { 6 , 7 , 8 } } ; private int [ ] [ ] data = new int [ n ] [ n ] ; public Sudoku ( ) {} Unifying Execution of Imperative and Declarative Code Aleksandar Milicevic 3
Motivation Outline Framework Translation Data Abstractions Evaluation Discussion Summary Solving Sudoku with Squander public class Sudoku { private f i n a l int n = 9; private f i n a l int [ ] [ ] regions = new int [ ] { new int [ ] { 0 , 1 , 2 } , new int [ ] { 3 , 4 , 5 } , new int [ ] { 6 , 7 , 8 } } ; private int [ ] [ ] data = new int [ n ] [ n ] ; public Sudoku ( ) {} public void solve ( ) { Squander . exe ( this ) ; } Unifying Execution of Imperative and Declarative Code Aleksandar Milicevic 3
Motivation Outline Framework Translation Data Abstractions Evaluation Discussion Summary Solving Sudoku with Squander public class Sudoku { private f i n a l int n = 9; private f i n a l int [ ] [ ] regions = new int [ ] { new int [ ] { 0 , 1 , 2 } , new int [ ] { 3 , 4 , 5 } , new int [ ] { 6 , 7 , 8 } } ; private int [ ] [ ] data = new int [ n ] [ n ] ; public Sudoku ( ) {} @Ensures( { ” a l l row in { 0 . . . ( t h i s . n − 1) } | t h i s . data [ row ] [ i n t ] = { 1 . . . t h i s . n } ” , ” a l l col in { 0 . . . ( t h i s . n − 1) } | t h i s . data [ i n t ] [ col ] = { 1 . . . t h i s . n } ” , public void solve ( ) { Squander . exe ( this ) ; } Unifying Execution of Imperative and Declarative Code Aleksandar Milicevic 3
Motivation Outline Framework Translation Data Abstractions Evaluation Discussion Summary Solving Sudoku with Squander public class Sudoku { private f i n a l int n = 9; private f i n a l int [ ] [ ] regions = new int [ ] { new int [ ] { 0 , 1 , 2 } , new int [ ] { 3 , 4 , 5 } , new int [ ] { 6 , 7 , 8 } } ; private int [ ] [ ] data = new int [ n ] [ n ] ; public Sudoku ( ) {} @Ensures( { ” a l l row in { 0 . . . ( t h i s . n − 1) } | t h i s . data [ row ] [ i n t ] = { 1 . . . t h i s . n } ” , ” a l l col in { 0 . . . ( t h i s . n − 1) } | t h i s . data [ i n t ] [ col ] = { 1 . . . t h i s . n } ” , ” a l l r1 , r2 in t h i s . regions . vals | t h i s . data [ r1 . vals ] [ r2 . vals ] = { 1 . . . t h i s . n } ” } ) public void solve ( ) { Squander . exe ( this ) ; } Unifying Execution of Imperative and Declarative Code Aleksandar Milicevic 3
Motivation Outline Framework Translation Data Abstractions Evaluation Discussion Summary Solving Sudoku with Squander public class Sudoku { private f i n a l int n = 9; private f i n a l int [ ] [ ] regions = new int [ ] { new int [ ] { 0 , 1 , 2 } , new int [ ] { 3 , 4 , 5 } , new int [ ] { 6 , 7 , 8 } } ; private int [ ] [ ] data = new int [ n ] [ n ] ; public Sudoku ( ) {} @Ensures( { ” a l l row in { 0 . . . ( t h i s . n − 1) } | t h i s . data [ row ] [ i n t ] = { 1 . . . t h i s . n } ” , ” a l l col in { 0 . . . ( t h i s . n − 1) } | t h i s . data [ i n t ] [ col ] = { 1 . . . t h i s . n } ” , ” a l l r1 , r2 in t h i s . regions . vals | t h i s . data [ r1 . vals ] [ r2 . vals ] = { 1 . . . t h i s . n } ” } ) @Modifies ( ” t h i s . data [ i n t ] . elems | < 2 > = 0 ” ) public void solve ( ) { Squander . exe ( this ) ; } Unifying Execution of Imperative and Declarative Code Aleksandar Milicevic 3
Motivation Outline Framework Translation Data Abstractions Evaluation Discussion Summary Solving Sudoku with Squander public class Sudoku { private f i n a l int n = 9; private f i n a l int [ ] [ ] regions = new int [ ] { new int [ ] { 0 , 1 , 2 } , new int [ ] { 3 , 4 , 5 } , new int [ ] { 6 , 7 , 8 } } ; private int [ ] [ ] data = new int [ n ] [ n ] ; public Sudoku ( ) {} @Ensures( { ” a l l row in { 0 . . . ( t h i s . n − 1) } | t h i s . data [ row ] [ i n t ] = { 1 . . . t h i s . n } ” , ” a l l col in { 0 . . . ( t h i s . n − 1) } | t h i s . data [ i n t ] [ col ] = { 1 . . . t h i s . n } ” , ” a l l r1 , r2 in t h i s . regions . vals | t h i s . data [ r1 . vals ] [ r2 . vals ] = { 1 . . . t h i s . n } ” } ) @Modifies ( ” t h i s . data [ i n t ] . elems | < 2 > = 0 ” ) public void solve ( ) { Squander . exe ( this ) ; } public static void main ( String [ ] args ) { Sudoku s = new Sudoku ( ) ; s . data [ 0 ] [ 3 ] = 1; s . data [ 0 ] [ 7 ] = 9; . . . s . data [ 8 ] [ 1 ] = 9; s . data [ 8 ] [ 5 ] = 1; s . solve ( ) ; System . out . p r i n t l n ( s ) ; } } Unifying Execution of Imperative and Declarative Code Aleksandar Milicevic 3
Motivation Outline Framework Translation Data Abstractions Evaluation Discussion Summary Solving Sudoku with Squander heap @Ensures( { ” a l l row in { 0 . . . ( t h i s . n − 1) } | t h i s . data [ row ] [ i n t ] = { 1 . . . t h i s . n } ” , ” a l l col in { 0 . . . ( t h i s . n − 1) } | t h i s . data [ i n t ] [ col ] = { 1 . . . t h i s . n } ” , ” a l l r1 , r2 in t h i s . regions . vals | t h i s . data [ r1 . vals ] [ r2 . vals ] = { 1 . . . t h i s . n } ” } ) @Modifies ( ” t h i s . data [ i n t ] . elems | < 2 > = 0 ” ) public void solve ( ) { Squander . exe ( this ) ; } public static void main ( String [ ] args ) { Sudoku s = new Sudoku ( ) ; s . data [ 0 ] [ 3 ] = 1; s . data [ 0 ] [ 7 ] = 9; . . . s . data [ 8 ] [ 1 ] = 9; s . data [ 8 ] [ 5 ] = 1; s . solve ( ) ; System . out . p r i n t l n ( s ) ; } Unifying Execution of Imperative and Declarative Code Aleksandar Milicevic 4
Motivation Outline Framework Translation Data Abstractions Evaluation Discussion Summary Solving Sudoku with Squander heap @Ensures( { ” a l l row in { 0 . . . ( t h i s . n − 1) } | t h i s . data [ row ] [ i n t ] = { 1 . . . t h i s . n } ” , ” a l l col in { 0 . . . ( t h i s . n − 1) } | t h i s . data [ i n t ] [ col ] = { 1 . . . t h i s . n } ” , ” a l l r1 , r2 in t h i s . regions . vals | t h i s . data [ r1 . vals ] [ r2 . vals ] = { 1 . . . t h i s . n } ” } ) @Modifies ( ” t h i s . data [ i n t ] . elems | < 2 > = 0 ” ) public void solve ( ) { Squander . exe ( this ) ; } public static void main ( String [ ] args ) { Sudoku s = new Sudoku ( ) ; s . data [ 0 ] [ 3 ] = 1; s . data [ 0 ] [ 7 ] = 9; . . . s . data [ 8 ] [ 1 ] = 9; s . data [ 8 ] [ 5 ] = 1; s . solve ( ) ; System . out . p r i n t l n ( s ) ; } Unifying Execution of Imperative and Declarative Code Aleksandar Milicevic 4
Recommend
More recommend