COP 4020 Lecture -*- Outline -*- * Relational Programming (Ch 9) Based on Peter van Roy and Seif Haridi's book, "Concepts, Techniques, and Models of Computer Programming" (MIT Press, 2004), where all references that are not otherwise attributed are found. ** self-test ------------------------------------------ SELF-TEST FOR CHAPTER 9 Motivation [Concepts] [EvaluateModels] [MapToLanguages] Why is programming so hard? What approaches might solve this problem? What is rapid prototyping? How does it help? What are the costs we care about in rapid prototyping? Goals [Concepts] [EvaluateModels] What are the goals of declarative programming? Ideas [Concepts] What are the key ideas of logic programming? Application [EvaluateModels] When is logic programming useful? Model [Concepts] [UseModels] What features are added to the declarative model in the relational model? What does choice do? How does it execute? What does fail do? How does it execute? What does Solve do? How does it execute? In what order are choices used? Does a fail statement have to occur nested within the execution of a choice statement? What happens when there are no more choices and a fail occurs? Is there a difference between unification failure and fail? What happens to variable bindings after a failure? Semantics [Concepts] [UseModels] Given fun {Vowel} choice a [] e [] i [] o [] u end end Draw a search tree for the query: {Solve proc {$ V} V={Vowel} V=i end} Encapsulated Search [Concepts] [UseModels] [MapToLanguages] In what sense does Solve give encapsulated search? How does encapsulating search help reasoning? Relational programming [UseModels] Write the procedure {Reverse L1 L2}, such that L2 is the reverse of L1 Write addition, multiplication on natural numbers. Generate and Test [UseModels] [MapToLanguages] What features of the relational model are used in generate and test? Solve a problem, such as the VCR problem in the notes, using generate and test. When is it appropriate to use generate and test? How would you program sorting, using generate and test? How efficient would that be? Constructive logic [Concepts] What is a constructive proof? Does constructive logic allow "proof by contradiction"? Correspondence between Oz and logical formulas [Concepts] [UseModels] What does sequencing mean, in the logical translation of Oz? What does a choice statement mean, in logic? How do you state an existential property in Oz? How do you state a universal property (rule) in Oz? What's the logical semantics of: case Ls of nil then skip [] _|nil then skip [] X|Y|Zs then (X =< Y)=true {Ordered Y|Zs} end What's the logical semantics of: choice Ls=nil [] Ls=_|nil [] local X Y Zs in X|Y|Zs=Ls (X =< Y)=true {Ordered Y|Zs} end end What's the operational difference between the above two statements? What does a choice mean in a rule? Logical semantics [Concepts] [UseModels] How do you write a query for a fact? What is the closed world assumption? Can the closed world assumption ever be wrong? How do you write a query to join two pieces of information? What syntax is used to represent conjunction in queries? Modeling in Oz [UseModels] Write Oz rules that encode your class schedule. Write a query to ask if you are in class Monday at 11:45. Write a query to find all the classes you are taking. Comparison to other models [EvaluateModels] [MapToLanguages] Can we do logic programming in the declarative model? What happens if we add concurrency to the relational model? Can we use logic programming ideas in the stateful models? Parsing [UseModels] [EvaluateModels] [MapToLanguages] For what kinds of grammars are logic programming techniques best suited? How are a grammar's nonterminals coded? How are alternatives in grammars coded? How do you create parse trees? Databases [UseModels] [EvaluateModels] What are the advantages of using logic programs for queries? How would you find prerequisite classes for a course in a database? How would you ask: What classes have the most prerequisites? How would you ask: What are all the classes you take before cop4020? Applicability [EvaluateModels] [MapToLanguages] When is the relational model most useful? What are some typical problems the relational model is good for? What kind of modularity properties does the relational model have? Is the relational model declarative? Referentially transparent? Can we mix the relational model with state? ------------------------------------------