文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > A Denotational Approach to Measuring Complexity in Functional Programs
侵权投诉

A Denotational Approach to Measuring Complexity in Functional Programs

A Denotational Approach to Measuring Complexity in Functional Programs

2

CHAPTER 1. INTRODUCTION

higher-order functional languages. A third appealing property of functional languages (although not unique to them) is the widespread use of type constructors. Type constructors allow us to de ne data types without necessarily knowing much about the actual implementation; for example, we know that a list has a head, containing an element of some data type, and a tail, which is another list, and we can abstract away from implementation details. This facilitates analysis in two ways: by suppressing implementation details that do not a ect the value of data, the analysis becomes much simpler; and by restricting the operations on data types we can guarantee that no element of the data type has an invalid form (such as a circular list). The drawback is that because implementation details are hidden, it may be harder to determine the amount of space they require or the time taken by operations on data. Lastly, many functional languages allow lazy evaluation, either directly, as an integral part of the language, or indirectly, via higher-order types. When we speak of lazy evaluation, we usually mean at least one of two di erent optimizations. First, any evaluation is postponed until needed, avoiding possibly costly work if the result is never used. We also can manipulate data structures that are theoretically in nite as long as we only need to examine a nite amount of the structure. Second, evaluation can be memoized; that is, the result of an evaluation can be saved so that it can be looked up if needed again, avoiding re-evaluation. Programmers and researchers thus often nd functional languages very attractive. The applicative structure, lack of side e ects, and use of exible type constructors make it easier to design programs at a high level of abstraction, thus making it easier to prove program correctness. Furthermore, if we know that evaluation of one part of an expression has no side e ects, it is easy to analyze the expression compositionally. It is also possible to substitute part of an expression with another of equal value and know that the overall result is unchanged; this property is known as referential transparency . Such properties make the extensional analysis (i.e., analysis of inputoutput properties) of functional programs reasonably simple. Additionally, the use of higher-order and lazy data types increases the expressive power and elegance of programs; a program written in a functional language is frequently shorter than the equivalent program written in an imperative language. These advantages do come with a cost: As programs resemble function declarations more than machine instructions, it may be more di cult to det

ermine the appropriate instructions needed for the computer to run them. Analyzing internal properties such as space and time complexity becomes more di cult when much of the work done by the computer is hidden from the programmer. Because the compiler or interpreter handles all space allocation invisibly, we may not know exactly how much space is allocated for a given data structure or how much time is taken managing the space. Furthermore, for certain types it may be di cult to de ne what we mean by time complexity. For example, consider the function twice=

f: x:f (f (x))

The time it takes to compute twice f x is dependent on the size of x, the complexity of f, and the size of the output of f on x. A standard de nition for the complexity of an algorithm is a function from the size of the input to the time it takes to compute the output; however such a de nition does not work for programs such as twice, which needs not only the complexity of f but the size of f (x). A similar situation holds for lazy data structures; for example, we can easily show that a program that calculates the length of a list will take time proportional to the length of the list. Lazy lists, however, may not be completely evaluated, thus the time needed to nd their lengths includes the time taken to nish evaluating the structure of the list, adding a potentially

上一页第16页

你可能喜欢

热门文档

相关文档

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email