Narrowing: the scope of this project Steven Libby.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Functional Programming Lecture 10 - type checking.
Logic Gates.
Type Inference David Walker COS 320. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
Type Checking, Inference, & Elaboration CS153: Compilers Greg Morrisett.
Control-Flow Graphs & Dataflow Analysis CS153: Compilers Greg Morrisett.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Factors and Prime Factorization. Definitions Factors ~ Whole numbers that are multiplied to find a product Factors ~ Whole numbers that are multiplied.
Outline 1. General Design and Problem Solving Strategies 2. More about Dynamic Programming – Example: Edit Distance 3. Backtracking (if there is time)
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
MINI ERLANG ID1218 Lecture Christian Schulte Software and Computer Systems School of Information and Communication Technology.
1 Constraint Programming Maurizio Gabbrielli Universita’ di Bologna Slides by: K. Marriott.
0 PROGRAMMING IN HASKELL Chapter 4 - Defining Functions.
CS 536 Spring Global Optimizations Lecture 23.
The Theory of NP-Completeness
1 Chapter 1: Constraints What are they, what do they do and what can I use them for.
Search in the semantic domain. Some definitions atomic formula: smallest formula possible (no sub- formulas) literal: atomic formula or negation of an.
Last time Proof-system search ( ` ) Interpretation search ( ² ) Quantifiers Equality Decision procedures Induction Cross-cutting aspectsMain search strategy.
מבוא מורחב 1 Lecture #8. מבוא מורחב 2 Shall we have some real fun.. Lets write a procedure scramble.. (scramble (list )) ==> ( ) (scramble.
CS 206 Introduction to Computer Science II 10 / 16 / 2009 Instructor: Michael Eckmann.
Ormap, andmap, and filter CS 5010 Program Design Paradigms “Bootcamp” Lesson 5.3 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Recursion. Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list.
CS 206 Introduction to Computer Science II 02 / 25 / 2009 Instructor: Michael Eckmann.
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
CS 211 RECURSION TREES. Trees versus Linked Lists A tree is like a linked list, except instead of a single next node, it can have multiple next nodes.
Intermediate Statistical Analysis Professor K. Leppel.
Sequence Control Chapter 6. 2 l Control structures: the basic framework within which operations and data are combined into programs. Sequence control.
Tuples and Lists Lecture 3, Programmeringsteknik del A.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
1 Programming Languages (CS 550) Simple Query Language* Jeremy R. Johnson *Material for this lecture comes from SICP chapter 4.
9-1 Solving 3 by 3 Systems Day 1. Umm… did she say 3 by 3?? Just like the 2 by 2 systems, we will solve the 3 by 3 systems. How many methods did we choose.
Fall Week 3 CSCI-141 Scott C. Johnson.  Say we want to draw the following figure ◦ How would we go about doing this?
CS 403: Programming Languages Lecture 19 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
INTRODUCTION TO BINARY TREES P SORTING  Review of Linear Search: –again, begin with first element and search through list until finding element,
CS321 Functional Programming 2 © JAS Type Checking Polymorphism in Haskell is implicit. ie the system can derive the types of all objects. This.
What does a computer program look like: a general overview.
Equations Reducible to Quadratic
Goal-based Problem Solving Goal formation Based upon the current situation and performance measures. Result is moving into a desirable state (goal state).
1 CS 457/557: Functional Languages Lists and Algebraic Datatypes Mark P Jones Portland State University.
PPL CPS. Moed A 2007 Solution (define scale-tree (λ (tree factor) (map (λ (sub-tree) (if (list? sub-tree) (scale-tree sub-tree factor) (* sub-tree.
Types and Programming Languages Lecture 14 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Solving Equations Using Logs. True or False? 1.Log 4 = log Log 15 = log 3 x log 5 3.Log 4 = log 8 – log 2 4.Log 64 = 2 log 8 5.Log 64 = 8 log 2.
Defining Classes Modules and ADTs CSCE 314 Spring 2016.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Conditional Expressions
ML: a quasi-functional language with strong typing
EQUATION IN TWO VARIABLES:
6.001 SICP Variations on a Scheme
Logic Programming (cont’d): Lists
From Templates to Folds
COP4020 Programming Languages
Nondeterministic Evaluation
PROGRAMMING IN HASKELL
Introduction to Code Generation
Advanced Functional Programming
Lecture #8 מבוא מורחב.
PROGRAMMING IN HASKELL
Types and Classes in Haskell
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
Lazy Programming Lazy evaluation:
topics mutable data structures
List and list operations (continue).
CSC 143 Java Trees.
6.001 SICP Interpretation Parts of an interpreter
Lecture # , , , , מבוא מורחב.
ormap, andmap, and filter
If-Statements and If/Else Statements
PROGRAMMING IN HASKELL
Parsing CSCI 432 Computer Science Theory
Presentation transcript:

Narrowing: the scope of this project Steven Libby

What is Narrowing? Narrowing is a method for finding solutions in Term Rewriting Systems It combines unification and evaluation If t narrows to r with rule l →r  u=mgu(t,l)  t → r u Each step has a unification and an evaluation

What is Term Rewriting? This is a better question l→r is a rewrite rule T is a term t| p is the subterm at position p of t Then t→ p,l→r t' replaces t| p with r to get t'

Umm... How about a picture

t = f x : map f xs p = 1. 1 l→r = f→id t' = f x : map id x t → 1. 1,f→id t'

Cool, how do we do it? The general problem is hard (undecidable) Limit ourselves to orthogonal systems We still need a narrowing strategy

Needed Narrowing Normal form: no more rewrite rules apply A step is “needed” if every derivation of a normal form includes that step Computing only needed steps would be optimal It turns out there is a strategy that does this

Detour through the forrest To compute the narrowing strategy we need a Definitional Tree Definitional Tree = Branch pattern [subtree] | Rule pattern l → r | Error pattern A definitional tree lets us pattern match to find the rule we're looking for

Example Definitional tree for  0 <= X → true  S(X) <= 0 → false  S(X) <= S(Y) → X <= Y

Example (Cont)

How do we make them > pdt :: Term Name -> Pos -> [Rule Name] -> PDT Name > pdt pat p [] = Error pat p > pdt pat p rs > | not (null rules) = renameRule (head rules) > | null cons = pdt pat [head p + 1] (vRules ++ tooShort) > | otherwise = Branch pat p $ branches ++ varBranch > where branches = map branch cons > branch cs = pdt (sub cs) (p++[0]) cs > rules = [Rule pat (init p) l r | (l:=>r) <- rs, pat ~= l] > vRules = filter unifies rs > tooShort = filter ends rs > cons = groupBy (leftEq p) (filter differs rs) > con l = Con (name l) (take (arity l) (newVars v p)) > sub ((l:=>_):_) = pat >>= ((v |-> con (l!>p))!) > (Var v) = pat!>p > exists l = arity (l!>(init p)) > last p > ends (l:=>r) = not (exists l) > unifies (l:=>r) = exists l && (l!>p) ~= (pat!>p) > differs (l:=>r) = exists l && not ((l!>p) ~= (pat!>p)) > varBranch = if not (null vRules) then [pdt pat [head p + 1] vRules] else []

Eww, can we Narrow things Now? Narrowing is actually a lot easier Walk the tree until we hit a rule or an error  At each branch we walk down one that unifies with t  If none of the branches unify we unify the pattern with t and try again If we hit a rule, then we replace t| p with r If we hit an error, then that's a failure

Narrowing Algorithm > narrow :: (Show v, Ord v) => Term v -> PDT v -> [PDT v] -> Step v > narrow t (Rule pat p l r) _ = [(p, l :=> r, u) | (Just u) <- [unify pat t]] > narrow t (Error pat p) _ = [(p, E, u) | (Just u) <- [unify pat t]] > narrow t (Branch pat p ts) dt > | not (null us) = [(p',r,s) | (ti,u) <- us, (p',r,s) <- narrow t ti dt] > | otherwise = [(p',r,s |=> tau) | (p',r,s) <- narrow t t' dt] > where us = [(ti,u) | ti <- ts, (Just u) <- [unify (pattern ti) t ]] > (Just tau) = unify pat t > t' = getTree ((t !> p) >>= (tau!)) dt

Conclusion Narrowing is a useful strategy It can be used to solve many/all of the problem we've looked at Implementing narrowing is doable  Make the definitional tree  Walk the tree and unify