1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Applicative Computational Systems Project Leade doc

347 206 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Combinatory Logic in Programming
Tác giả V. E. Wolfengagen
Người hướng dẫn Dr. L. Yu. Ismailova
Trường học Moscow Engineering Physics Institute
Chuyên ngành Computer Science
Thể loại Thesis
Năm xuất bản 2003
Thành phố Moscow
Định dạng
Số trang 347
Dung lượng 1,43 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

The several areas of the-oretical computer science are covered, including the following: typefree and typed λ-calculus and combinatory logic with applications,evaluation of expressions,

Trang 1

V E WolfengagenCombinatory

Logic

in Programming

Trang 2

Series: Computer Science and Information

Trang 3

Institute for Contemporary Education

“JurInfoR-MSU”

Department of Advanced Computer Studies

and Information Technologies

Trang 4

ob-ISBN 5-89158-101-9

The book is intended for computer science students, programmersand professionals who have already got acquainted with the basiccourses and background on discrete mathematics It may be used

as a textbook for graduate course on theoretical computer science.The book introduces a reader to the conceptual framework for think-ing about computations with the objects The several areas of the-oretical computer science are covered, including the following: typefree and typed λ-calculus and combinatory logic with applications,evaluation of expressions, computations in a category The topics,covered in the book accumulated much experience in teaching thesesubjects in graduate computer science courses

A rich set of examples and exercises, including solutions, has beenprepared to stimulate the self studying and to make easier the job ofinstructor

c Center “JurInfoR”

Institute for Contemporary Education “JurInfoR-MSU”

Fax: +7 (095) 956-25-12 E-mail: vew@jmsuice.msk.ru

Trang 5

1.1 The spectrum of ideas 29

1.2 Layout of a chapter 30

1.3 State-of-the-art in an area 32

1.4 Typical task 35

1.5 Variants of task 37

1.6 A recommended order of solving the tasks 44

2 Derivation of Object 45 2.1 Principle of combinatory completeness 46

2.1.1 Combinatory characteristic 46

2.1.2 Systems of concepts 47

V

Trang 6

2.1.3 Combinatory completeness 47

2.1.4 Elementary combinatory logic 49

2.2 Deriving main combinators: tasks 51

2.3 Historical remark 62

3 Fixed Point 65 3.1 Theoretical background 65

3.1.1 Abstraction 66

3.1.2 Multiabstraction 66

3.1.3 Local recursion 67

3.2 Main tasks 68

Exercises 73

4 Extensionality 75 4.1 Theoretical background 75

4.2 Tasks 77

Exercises 79

5 Numerals 81 5.1 Numbers and numerals 81

5.2 Combinatory arithmetic 82

5.3 Tasks 87

Exercises 91

6 Typed combinators 93 6.1 Notion of a type 93

6.1.1 Combinatory terms 96

6.1.2 λ-terms 97

6.2 Tasks 97

7 Basis I, K, S 113 7.1 Theoretical background 113

7.2 Tasks 114

Exercises 115

Trang 7

C ONTENTS VII

8.1 Theoretical background 117

8.2 A property of being basic 118

8.3 Elementary examples 120

Exercises 121

9 Applications of fixed point combinator Y 123 9.1 Fixed point theorem 123

9.2 Elements of recursive computations 124

9.3 Using the combinator Y 125

9.4 Evaluation of a function 127

Exercises 131

10 Function list1 133 10.1 Theoretical background 133

10.2 Tasks 134

10.3 Functor-as-object 137

Exercises 138

11 Isomorphism of c.c.c and ACS 139 11.1 Theoretical background 139

11.2 Tasks 141

12 Currying 143 12.1 Theoretical background 143

12.1.1 Operators and functions 143

12.1.2 Comprehension 144

12.1.3 Connection between operators and functions 144 12.2 Tasks 145

Exercises 147

13 Karoubi’s shell 149 13.1 Theoretical background 149

13.2 Tasks 150

Trang 8

Exercises 154

14 Products and projections 157 14.1 Theoretical background 157

14.2 Task 157

14.3 Product and cartesian closed category 161

15 Embedding Lisp into ACS 163 15.1 Theoretical background 163

15.2 A main task 164

15.3 Concluding remarks 170

16 Supercombinators 171 16.1 Theoretical background 171

16.1.1 Notion of supercombinator 172

16.1.2 Process of compiling 174

16.1.3 Transformation to supercombinators 175

16.1.4 Eliminating redundant parameters 177

16.1.5 Ordering of the parameters 178

16.1.6 The lambda-lifting with a recursion 182

16.1.7 Execution of the lambda-lifting algorithm 185

16.1.8 Other ways of lambda-lifting 188

16.1.9 Full lazyness 190

16.1.10Maximal free expressions 192

16.1.11Lambda-lifting with MFE 194

16.1.12Fully lazy lambda-lifting with letrec 196

16.1.13Compound example 197

16.2 Task 200

16.3 Answers to exercises 202

17 Lazy implementation 211 17.1 Tasks 211

Exercises 214

Trang 9

C ONTENTS IX

18.1 Task 215

Exercises 219

Test 219

19 Immediate computations 221 19.1 Task 221

Exercises 223

Test 224

20 de Bruijn’s encoding 225 20.1 Tasks 225

Exercises 230

21 Abstract machine: CAM 233 21.1 Theoretical background 233

21.1.1 CAM structure 233

21.1.2 Instructions 235

21.2 Tasks 239

Exercises 240

22 Optimizing CAM-computations 243 22.1 Task 243

Exercises 252

Test 253

23 Variable objects 255 23.1 Models 255

23.1.1 Applicative structure 256

23.1.2 Typed models 259

23.1.3 Partial objects 267

23.1.4 Data object models 270

23.2 The main task 274

23.2.1 Elementary types 275

Trang 10

23.2.2 Typed variable objects 276

23.2.3 Computational models 278

23.2.4 Indexed objects 280

23.3 Interpretation of evaluating environment 288

Trang 11

P REFACE OF THE EDITORS OF THE SERIES 1

Preface of the editors of the series

Computer science and information technologies have become nipresent and continue to promise changes that more and more in-volve, practically speaking, all the spheres of our life First of all, thenew technologies make it easier to get access to diverse informationand produce masses of information in electronic form, changing bythis both the character of work and its results Indeed, many products,being of great demand, are produced in the form of a sequence of bits,with an exceptionally high tempo of their changes

om-Changes involve both separate professions, and the whole ches of industry and knowledge In real state of things, the develop-ment of information technologies has led to the appearance of virtualreality Contemporary society is just beginning to get adapted to vir-tual reality, the capabilities of which are being appropriated quicklyenough

bran-While at its early stages of development programming was a kind

of art with a programmer creating a program in order to solve a inite task and providing it with more or less detailed documentation

def-By now, a powerful industry of programming has been created, plete with accompanying software engineering At present, in theresearch in the field of programming or in the sphere of computer sci-ences, as a rule, support is given to works in which a slight improve-ment is introduced in the solution of the already well-known problem

com-At the same time no attention is paid to really important and basic search, being the way to search for new computation concepts, whileinsufficient attention is given to accumulation of knowledge in thefield of programming

re-This series of volumes is meant as a continuing row of cations in the field of computer science, information technologiesand programming, promoting the accumulation of knowledge in theabove-mentioned fields It is assumed that these publications may

publi-be used for presentation of separate courses and can also promote

Trang 12

scientific research As a rule, the volumes of the series are meant tosatisfy the needs of readers of various levels, starting with studentsthat have the aim of getting initial familiarization with the subjectitself, up to specialists in different branches of computer sciences.Thus, the publications of the planned series are meant to reflectthe current status of the given field and also to provide the basis forsystematic study of different sections of computer sciences, informa-tion technologies and programming.

The Editors of The Series

Trang 13

S PECIAL P REFACE 3

Special Preface

One of the virtues of combinatory logic is that it provides a smartuniverse of discourse to computer scientists, programmers, appliedtheoreticians, practitioners In practice, however, a sophisticated ap-plied theoretician and an applied programmer must have a thoroughgrasp of what the system of objects does in response to an evaluationrequest To make the most transparent use of the evaluation sys-tem, one must have insight of such things as what kind of thing is

an object or data structure, how to optimize the execution plan of aprogram for given set of objects, to understand the impact of avoidingthe bound variables on a program code, the importance of sub- andsuper-partitioning of an object set, etc When used or studied, allthese trends are interrelated and involve some self contained localuniverses of mathematical ideas

This book covers the commonly used computational ideas related

to combinatory logic

Nevertheless, the lifting from undergraduate to graduate ing of applicative computations topics initiates unusual didactic chal-lenges which can be explained by the visible distance between therigorous mathematical apparatus and applied research papers.This volume addresses this problem by providing a graduate text-book which covers the principle topics for classroom teaching Inthis book the gradual progression of topics is supported by examplesand exercises By solving them, the students are introduced to theresearch issues at the forefront of computer science The book iswritten by the author who is a specialist in the covered areas, andwho has accumulated a rich experience in teaching graduate courses

teach-in those areas

To use this book a minimal knowledge of theoretical computerscience is needed to reach the following aims:

• to provide an introduction to the principle areas of current research

in computer science in order to give students the needed

Trang 14

knowl-edge and intuition for more advanced study and research;

• to provide both the practitioners and researchers with a conceptualbackground of computational ideas that are expected to be used inapplied computer science in the coming years

To achieve the second aim the author has used the general notations

of mappings between the classes of objects, in order to bring in moreindependency from a particular formal system Most of attention ispaid to the main computational ideas and their implementation within

a formal framework

Nobody argues that λ-calculus is a theory of functions This ory gives a philosophy and reasons to view the idealized entities asfunctions It is more important that λ-calculus is related to othertheories and the kind of these relations gives important insight intohow to build different models of computation

the-The spectrum of other theories usually starts with set theory the-The

question is how set theory provides a theory of functions E.g., melo’s theory has a limited view of sets observing separate set A as

Zer-extremely small with respect to the size of V , the universe of all sets.

Any particular map f : A → B from one set A into other set B gives

no information concerning maps from V to V , thus the classes ofoperations on all sets are hardly ever known within set theory Usual

assumption takes set A as an element of V , A ∈ V in spite of class

B which is subcollection of V , B ⊆ V The connections betweenλ-calculus and class theory have been established and studied Thisdoes not mean that λ-calculus depends on the set theory

If we want a theory of functions be not derived from the set theory

we need a pure theory of functions within which functions are

ob-served as particular entities A category theory gives a universe of

discourse for selected functions, or better: functional entities Themiddle way between pure category theory and a set theory is given by

cartesian closed categories.

Trang 15

T HE SPECTRUM OF PROBLEMS 5

The spectrum of problems

“It has long been my personal view that the separation of practical and theoretical work is artificial and injurious Much of the practical work done in computing, both in software and in hardware design, is unsound and clumsy because the people who do it have not any clear understanding of the fundamental design principles of their work Most of the abstract mathematical and theoretical work is sterile be- cause it has no point of contact with real computing One of the central aims of the Programming Research Group [in Oxford University] as a teaching and research group has been to set up an atmosphere in which this separation cannot happen.”

Christopher Strachey

http://vmoc.museophile.com/pioneers/strachey.html

From the moment of their emergence, combinatory logic and calculus are referred to as “non-classical” by logicians The point isthat combinatory logic appeared in the 20-ies, while lambda-calcu-lus, in the 40-ies, as a branch of mathematics with sufficiently clear-cut purpose of rendering foundation to mathematics It means that,having constructed the required “applied” mathematical theory, i.e.object theory, reflecting processes and phenomena in real environ-ment, it is possible to make use of a “pure” metatheory as a shell forfinding out the capabilities and properties of the object theory

lambda-Combinatory logic and lambda-calculus are such formal systems

in which the central elaborated essence is the concept of an object.Within the framework of the first of them, i.e the combinatory logic,the mechanism of binding variables is absent in its explicit form, whilebeing present in the second one The presence of this explicit mecha-nism of binding assumes both the presence of bound variables (how-ever, in this case, free variables are also assumed), as well as mech-anisms of replacement of formal parameters, i.e bound variables, byactual parameters, that is substitution

The initial purpose of combinatory logic was namely the analysis

of this substitution process In the capacity of its essences, it was

Trang 16

planned to use objects as combinations of constants

Lambda-calculus was assigned the role of means for specifying the notions of

an algorithm and computability As a consequence, combinatory

logic provides a tool for analysis of the process of substitution After

a short period of time, it turned out that both the systems could be

treated as programming languages.

Both the systems, in which objects are computed, are calculi or

languages of higher order, i.e., there are means for describing

map-pings or operators, which are defined on a set of mapmap-pings or ators, while also generating mappings and operators as a result of

oper-it The most important thing is that it is precisely mapping that is

considered to be an object This constitutes its basic difference from

the whole variety of other systems, for which the notion of set and its

elements is usually taken as their primary basics

Currently, both these languages have become the basis for thewhole domain of research in the field of computer science and arealso widely used in the theory of programming The development

of computational power of computers has led to the automation of

a considerable part of theoretical – both logical and mathematical, –knowledge, while combinatory logic together with lambda-calculusare recognized as a basis for considerations in terms of objects.Without the mastering of their methods, it is impossible to fullydevelop the basic technique of computations with objects, since theset-theoretic style, still widely used in the object-oriented languages

of programming and development, makes it difficult to avoid gettingburied in masses of secondary details and, as a result, losing sight ofthe really important issues of the interaction of objects

Trang 17

P REFACE TO THE FIRST EDITION OF THE VOLUME 7

Preface to the first edition of the volume

Whom is the volume addressed to?

This volume has been written to assist those readers who study puter science or are engaged in this sphere of activity, who want tosystemize their knowledge and have another look at the spectrum ofideas they have to deal with in their everyday work The volume ismeant to help in reading and studying the original research publica-tions in the field of system and theoretical programming, as well as,

com-if need be, to effect accurate mathematical analysis of newly createdprogramming mechanisms and data models The detailed explana-tions and a great number of analyzed examples and problems willassist the reader in getting the message without any considerableeffort of making a good choice of the required literature and startingown research work in this interesting and promising field That ispromoted by a considerable amount of independence in the study ofseparate sections, which is reasonable in view of the specific character

of the mathematical discipline itself, i.e combinatory logic A moreexperienced reader in the field of mathematics may be interested in theapplied aspects of the theory

Why should objects be calculated?

Work with computers provided with a shell, which can take over uponitself the control of software objects, lays the basis for the utmoststate-of-the-art technique of programming Presently, hundreds ofapplied programs, such as Windows, AutoCAD, Designer and manyothers deal with objects On the other hand, the instrumental systems

of programming, such as Small Talk, C++, Actor and some othersrequire a programmer to exercise systematic speculations in terms

of objects and relationship between them, which, in their turn, can

be treated as objects Programming in terms of objects requires thedevelopment and maintenance of their own mathematical culture that

Trang 18

provides the whole spectrum of stimulating ideas In the process ofsolving a specific task, a programmer becomes a researcher, who isrequired to create his own language with its own capabilities Suchcapabilities are not always intuitively self-evident and may requirepurely mathematical evaluation of their expressive abilities Apartfrom that, very often it is not only necessary to create a certain pro-gram code but also to fulfill its optimization without losing the prop-erties of its equivalence to the initial code For doing careful andprofessional work, it is required to have its own “mathematical shell”,supporting all significant and interesting mathematical applications.

The principal thing is the adequate way of thinking

It is a well-known fact that in the practice of programming, differentapproaches, developing in different directions, have taken shape Themost evident differences manifest themselves in the difference in com-prehension and writing of programs The major part of programmers

is engaged in procedure-oriented programming Apart from that, there exist rule-oriented programming, logical programming, par-

allel programming, visual programming, and programming in terms

of dataflows If need be, this list can be continued, but, evidently, it will

be incomplete without also including object-oriented programming,

displaying a vividly expressed tendency for growth

Approaches and styles of programming. Approaches and styles

of programming are numerous, which reflects the tendency of grading and propagating of still newer computer architectures Theemerging new architectures are oriented at new approaches to pro-gramming that are still taking shape in research laboratories

up-The abundance and great variety of approaches to programming

in computer science are reflected in the development and tion of different approaches to mathematics And indeed, surpris-ingly many mathematical theories have been built, each of them being

Trang 19

propaga-P REFACE TO THE FIRST EDITION OF THE VOLUME 9

an absolutely unique language of communication for a comparativelynarrow circle of specialists who understand each other perfectly well

At the same time, any attempt of an “uninitiated” person to stand practical usefulness and significance of the new mathematicallanguage meets with obstacles It turns out that, first of all, it isnecessary to change one’s own way of thinking so as to be able tohave a different look at certain difficulties Thus, the spread of object-oriented programming also requires the use of different ways of rea-soning, which more often than not radically differ from the stereotypes

under-of reasoning adopted in procedure-oriented programming

Speculations in terms of objects. Similarly, only just few andcomparatively young mathematical theories are oriented at specula-

tion in terms of objects rather than in terms of operators, as goes

from the experience in studying mathematical analysis at the majority

of universities, including those technically or computer oriented fortunately, a programmer has no opportunity to attend a universitycourse that might lay down the basis of mathematical thinking interms of objects At best, only some information about purely mathe-

Un-matical results is given, which are obtained in the framework of

com-binatory logic, lambda-calculus or category theory and which are

far from being easy to apply to practical programming, if you are notversed in theory

It is possible to assert that combinatory logic has had a able influence on the contemporary status of programming Coming

consider-into life as a science about the nature of substitutions in matical theories, it has then given birth to functional programming, programming in terms of supercombinators, as well as some other

mathe-highly productive approaches to programming In particular, onlyafter one really understands the very spirit of combinatory logic, it

is possible to fully comprehend and put into practice the system of

programming, having no predetermined set of instructions.

Trang 20

Computation theory. The programming paradigms of the 90-iesemerged, to a great extent, from the mathematical way of consider-ations, adopted in the computation theory In particular, one of itsinitial premises was the concept of ‘information flow’ along a certain

‘possible’ channel, which gave rise to the appearance of a very fruitfulconcept of a program, controlled by a data flow Another example has

to do with the idea of using a certain part of combinatory logic bybuilding special instructions-objects within it Those objects form a

system of commands of a categorical abstract machine, which can

successfully serve as a foundation of quite practical (albeit, oriented) systems of programming More than that, the rules of com-

object-binatory logic make it possible to optimize the compiled program

code by reducing it to a certain normal form For a specialist in

combinatory logic, it was something taken for granted from the verybeginning, since that was one of the aims for developing combinatorylogic as a mathematical discipline

The contemporary research in the field of computer science hasshown that combinatory logic and its various categorial dialects be-come an indispensable mathematical language of the programmer,used for exchanging ideas between colleagues The point is that one

of the subject matters of its research is the study of objects and opment of different calculuses of objects, satisfying a set of aspects ofeach applied task In other words, the solution of any particular taskrequires the creation of a specific exact language As is well known

devel-by programmers, that is the language of the software interface Interms of a computer science specialist, it is a specialized dialect ofcombinatory logic

Objects and a systemic approach

If a programmer chooses an object-oriented approach to the ment, it would most probably be a mistake to adjust the task undersolution to a certain already known mathematical model Probably,

Trang 21

develop-P REFACE TO THE FIRST EDITION OF THE VOLUME 11

it would be much better to look for some nonstandard solution thatadequately matches the specific features related to the very nature of

the applied domain In computer science, the metatheory is

cho-sen for this purpose, within the framework of which the research isdone and which is “adjusted” to the specific character of the applieddomain One of the means for such an adjustment is to embed theapplied theory (a “smaller” theory) into pure metatheory (a “bigger”theory) Besides, from the mathematical viewpoint, within the frame-work of combinatory logic, it is convenient to build up sub-theories,i.e special mathematical modules which in their finished form presetthe computation mechanisms having a value of their own Such rea-soning can easily find response with a programmer who has to dealwith a big software project, when the advantages of considerations

in terms of objects and their properties become especially evident.Combinatory logic makes it possible, by using mathematically ideal-ized objects, to preliminarily “play out” all the most complicated anddelicate issues of interactions of mechanisms within a big softwareproject

The City of Moscow

Trang 22

Preface to the second edition

Applicative Computing Systems. The systems of calculuses ofobjects, based on combinatory logic and lambda-calculus, are tradi-tionally treated as applicative computing systems, or ACS The onlything that is being essentially developed within such systems is the

notion of an object In combinatory logic the only meta-operator

is application, or, within a different system of terms, the using the

action of one object to another Lambda-calculus has two

meta-operators, i.e application and functional abstraction that makes it

possible to bind one variable within one object

Objects arising in such systems behave as functional entities, playing the following features:

dis-• a number of argument places, or the arity of an object, is not fixed

in advance but manifests itself gradually in interaction with otherobjects;

• in designing a composite object, one of the initial objects, i.e afunction, is applied to another object, i.e an argument, while inother contexts they may exchange their roles, meaning that func-tions and arguments are equally treated as objects;

• self-applicability of functions is allowed, i.e an object can be plied to itself

ap-Computing systems with this most general and least restrictive ities turn out to be the center of attention of the contemporary com-puter science community It is precisely these systems that cur-rently ensure the required meta-theoretical means, making it possible

qual-to study the properties of target applied theories, provide the basisfor building semantic means of programming languages and ensuremeans for building data/metadata models within the informationalsystems

Trang 23

P REFACE TO THE SECOND EDITION 13

The second half of the 70-ies – the beginning of the 80-ies nessed an explosion in the development of applicative computing sys-tems, which has led to the progress in a whole range of trends ofresearch and brought about an abundance of scientific publications.They were written in a special language, their reading and under-standing, to say nothing about mastering the very essence of the mat-ter, required a considerable theoretical background There were a fewreasons for that

wit-In the first place, back in 1980 the theory of applicative tations was still being actively developed, while one of the purposes

compu-of the authors compu-of the publications was to arouse interest and involvemathematically talented students into the research in that field

In the second place, in the course of time, the role and place,assigned to the applicative systems in the curriculum, have changedwith time If earlier, in order to master the most important ideas, itwas necessary to get closely familiar with a whole set of mathematicaldisciplines, now the study of basic elements of applicative computa-tions is included into a standard curriculum, being compulsory forthe students in the first and second years It means that, in writing

a volume, preference should be given to the intensional method ofpresentation of the material, which involves only basic means in order

to make the subject matter easily understood

In the third place, in the meantime, the courses in computerscience have changed from purely mathematical and conceptual into

a fairly prescriptional ones, giving something similar to a “quickoverview” of a mass of ready-made solutions, methods, technologiesand recommendations for use

In the fourth place, the attitude towards computer science has come, to a great extent, purely practical and even that of a consumer

be-In the majority of cases, it is expected that the mastering of this orthat branch of computer science should immediately bring about acertain return Students even display quite evident unwillingness to

do exercises or solve tasks of creative or theoretical character, being

Trang 24

of a fundamental importance In order to preserve the required level ofeducation in applicative computations, the present volume containsexamples and exercises of different character in the field of program-ming and their solutions are given by using basic means, withoutassuming any preliminary mathematical background.

The required level of background. In this volume the main set

of problems is presented using basic means and, as is expected, willcause no difficulties for students familiar with logic and the principles

of proof methods It is assumed that the reader is also familiar withthe basics of programming, having a certain knowledge of data struc-tures At the same time, the presentation of the material as a wholeand partly inside separate sections is built following the ever growingdegree of complexity, meaning to please those advanced readers whoavoid books intended for “easy reading” The mastering of a number

of sections will help the readers to achieve the level of the up-to-dateresearch and stimulate their own scientific studies

Examples and exercises. The volume contains series of examplesand exercises, the major part of which is provided with directions andsolutions As a rule, the solution itself includes a sufficient store oftheoretical knowledge that will help not only understand the solution,but also look for other options It stands to reason that such a bookcannot be completely free from mistakes In case you detect anymistakes or in case you have any suggestions as to how they should

be corrected, please, do not hesitate to inform the author about it Ifyou have new tasks and exercises, the author will be especially glad

to learn about it However, if you decide to send them over, please,provide them with solutions before submitting them to the followinge-mail address: vew@jmsuice.msk.ru

Source material and laboratory exercises. This volume is based

on a course of lectures, delivered by the author at the Moscow

Trang 25

En-P REFACE TO THE SECOND EDITION 15

gineering and Physical Institute (MEPhI) The courses of lectures,delivered at the MEPhI on the basis of the present volume, are pro-vided with Laboratory Exercises The Laboratory Exercises prod-uct is compatible with the IBM PC and is distributed on machine-readable media

Acknowledgements. The author highly appreciates the tion made by Dr R.V Khrapko, and N.P Masliy, A.S Afanasyev,T.V Syrova, who displayed a high level of interest in and profoundprofessional understanding of the problems involved and their greaterudition In developing software, they strived to use applicative orpurely object technologies and solutions, as well as the technique ofdynamic formation of objects

contribu-The conditions and possibilities for application of the object proach to software development were provided by V.V Ivanchenko,who did his best to organize the scientific research process

ap-I.V Papaskiry’s assistance and well-meaning attention made itpossible to establish a permanently acting workshop, as well as aunique atmosphere of scientific debates during which the main range

of ideas presented in the volume were discussed

Prof L.T Kuzin paid considerable attention to the methods andmeans for work with abstract objects, promoting research in that di-rection, its development, application and extension to the solution ofvarious tasks in the field of cybernetic simulation A whole number ofresults obtained was discussed at scientific workshops of the “AppliedProblems of Cybernetics” Section, chaired by him, while their appli-cation was presented within the framework of a cycle of disciplines,headed by him, for the students of the Cybernetics faculty of MEPhI

as part of training engineers-mathematicians, specializing in appliedmathematics

Sincere gratitude is due to K.A Sagoyan for the preparation andcheck-up of solutions of all the examples, given in Section 6, thatwere also used in the Preprint publications His thoroughness, hard

Trang 26

work and resourcefulness evoke genuine admiration Various ants of their solutions were tested by him in the course of conduction

vari-of laboratory exercises with the students at the MEPhI CyberneticsDepartment

Enormous patience and readiness to show a whole range of plications for object calculus were shown by I.V Chepurnova, whotook upon herself the responsibility for the publication of the Preprintversion of this volume It would be impossible to overestimate herwork of many years in organizing and conducting workshops for theMEPhI full-time students and for the post-graduate students of theMEPhI enhancement courses Her special courses were based on thesections contained in the present volume, which were updated andextended at her suggestions

ap-I.A Goryunova took upon herself a difficult assignment in picking

up tasks for Section 16 Enthusiasm, displayed by her, and found understanding of the mechanism of dynamic formation of ob-jects made it possible to select exercises, provided with solutions.A.G Panteleev offered a number of valuable comments on Sec-tion15

pro-Wu-Hoang Ham indicated other possible variants of solutions forsome examples

Profs B.V Biryukov and A.S Kuzichev, who chaired the tific workshop in the history and methodology of natural sciences atthe Moscow State University (MSU), provided valuable recommen-dations in selecting bibliography Prof V.A Smirnov indicated addi-tional possible areas of applications of intensional methods in combi-nation with object calculuses

scien-Prof S.Kh Aytyan provided remarks for parts of the volume terial in the course of its writing Some aspects of object applicationswere discussed with Prof G.G Belonogov, Prof G.Ya Voloshin,Prof S.N Seletkov, and Prof E.N Syromolotov

ma-Prof P.-L Curien of Universit ´e Paris VII, LITP, one of the thors of the categorical abstract machine concept, was very kind to

Trang 27

au-P REFACE TO THE SECOND EDITION 17

provide me with a number of his publications, which made it possible

to speed up the work on the first publication of the volume

Dr V.Ya Yatsuk, shared his procedures and experience he gainedwhile presenting object calculi in the courses, delivered by him.I.V Mazhirin indicated some possibilities in developing versions ofabstract machines Dr G.S Lebedev, initiated the teaching of de-ductive extensions of object calculi

E.M Galstyan rendered technical support in the preparation ofthe preliminary version of the volume text

The preparation of the present volume for publication was ched in time and became feasible thanks to collaboration with thefollowing numerous interested specialists, who took part in the work

stret-of scientific workshops held on the problems stret-of computer scienceand information technologies at the Moscow Engineering and Phys-ical Institute, as well as organized practical lessons for students ofdifferent years of education, and supervised their course and diplomaprojects: Yu.G Gorbanev, V.I Vasiliyev, O.V Voskresenskaya,M.Yu Chuprikov, O.V Barinov, I.A Alexandrova, G.K Sokolov,S.V Kosikov, I.A Volkov, S.K Saribekyan, K.A Sagoyan,A.I Mih-kaylov, T.V Volshanik, Z.I Shargatova, I.A Goryunova, A.V Gav-rilov, L.V Goltseva, E.V Burlyaeva, V.A Donchenko, I.V Chepur-nova, A.V Myasnikov, K.E Aksyenov, S.I Dneprovsky, S.V Bryz-galov, S.V Zykov, Ye.S Pivovarova, A.Yu Rukodanov, S.A Kasta-nov, L.A Dmitrieva, Yu.Yu Parfenov, R.K Barabash, A.I Odrova,A.L Brin, R.V Snitsar, A.L Zabrodin, A.M Grigoryev, G.G Pogo-daev, B.B Gorelov, M.L Faybisovich, K.V Pankin, N.V Pishchimo-

va, A.I Vaizer

Finally, it has become possible to issue the present volume binatory Logic in Programming” only thanks to the enormous timeand energy, rendered by the employees of the Institute for Contempo-rary Education “JurInfoR-MSU”

“Com-The City of Moscow

Trang 28

Objects and modes of combining the objects represent all that is

es-sential in combinatory logic Combination of objects with some otherobjects is implemented by initial identification of objects-constants,

called combinators There are just a few such initial combinators,

however, by using them one can build such well-known formal tems as the logic of statements, the logic of predicates, arithmeticsystems1and a whole number of others In the past ten years, combi-natory logic has become one of the basic metamathematical tech-niques of computer science, having shown its capabilities in thesphere of programming There has appeared a whole family of func-tional programming languages Miranda, ML, KRC, being suffi-ciently well known to programmers, give us an idea of their possibleapplication However, the object-oriented approach to programmingand designing of applied systems as a whole, which has alreadydisplayed its overall potential, raises fundamental questions, refer-ring to the method of operation itself in terms of objects For this

sys-purpose, a preselected universe of discourse is required, being a sort

of theoretical shell that guarantees mathematical fruitfulness of theperformed investigation This is felt especially acutely in the process

of implementation of large software projects when the choice of asystematic method of representation and operation of objects acquiresdecisive importance

Discussion of the volume structure

The structure of this volume and the layout of separate sections areimplemented in such a way as to enable the reader to fully concentratethe attention on the matter of computations with objects being offundamental importance

1

More rigorously: the systems of numerals

Trang 29

I NTRODUCTION 19

• Synthesis of a new object

One of the most important tasks, solved within the framework ofcombinatory logic, is formulated as a task of synthesis of an objectwith preset properties out of the available objects by using the alreadyknown modes of combining At the initial stage, the availability ofonly three objects-combinators is assumed: I, K, S, as well as that

of their properties, preset by characteristic equations To preservethe intuitive clarity, one can assume that there exists a system ofprogramming with these three instructions and, using exclusivelythese instructions, one will have to build up a system of programming,being rich enough in its expressive capabilities The resultant systemwill contain solely objects-combinators

• Characteristics of a fixed point combinator

The transparency of combinatory logic makes it rather easy to study.After the first steps, it may seem that within it we always have to dealwith simple and finite in their nature objects However, that impres-sion is deceptive, and, by using combinators, it is possible to represent

processes, including loop computations, which are problems with a

recursion stack, being well known in programming

• The use of the extensionality principle

The characteristic feature of combinatory logic is that it is possible to

build and apply functions within it, having a number of arguments

that is not fixed a priori It means that one should be cautious

enough while answering the question about how many argument sitions the applied function-object has in reality Indeed, careful use

po-of sufficiently simple principles po-of extensionality (expansibility) makes

it possible to overcome that indefiniteness

Trang 30

• Numerals and their properties

Note that, from the very beginning, there are no numerals among

primary objects in combinatory logic The point is that the concept of

a numeral can be developed independently, by using known nators In such a case, numerals present themselves in a somewhatunusual aspect, being objects, which display their arity, depending onthe used system of postulates In the same way, arithmetical opera-tions are successfully developed in the form of combinators In otherwords, arithmetical entities are built into combinatory logic Thissituation is well known in object-oriented programming, i.e an ap-plication (arithmetical objects with their rules) is built into a softwareenvironment (combinatory logic)

combi-• Study of properties of combinators with types

The concept of a class is one of the most important in object-orientedspeculations In this case, a class is understood as a sample for cre-ating specimens of concrete objects Moreover, classes themselvescan be treated as objects Similarly, combinators are classified ortypified The high order of functional spaces turns out to be importantfor combinators Nevertheless, the intuitive clarity of the work withcombinators as objects does not get lost

• Expansion of terms in the I, K, S basis

Let us concentrate on the simplest system of programming with onlythree instructions: I, K, S It is possible to synthesize a new object

by a purely mechanical use of the algorithm of expansion in the basis,being quite similar to the process of compilation

• Expansion of terms in the I, B, C, S basis

As it turns out, the I, K, S basis is not the only one, and the set ofcombiners I, B, C, S also displays the property of a basis Compila-

Trang 31

I NTRODUCTION 21

tion (expansion) of an object in that basis also resolves the problem ofsynthesis of an object with preset properties Evidently, it is possible

to use the freedom of selecting a basis, depending on some criteria

• Expression of function definition using the fixed point

opera-tor Y

The case of recursive definitions of objects is considered By using thefixed point theorem, being fundamental for functional programming,recursive definitions can be successfully reduced to the conventionalequational form

• Study of properties of the list1 function

Capabilities for building a function-object in a parameterized form areshown By assigning particular values to arguments – and functionscan also be these particular values, – it is possible to get a wholefamily of definitions for particular functions

• Establishment of isomorphism for the Cartesian closed

cate-gory and applicative computation system

Now, we begin to move into the depths of mathematical abstractionsand start coordinating the operational way of thinking with combi-natory approach Note that within combinatory logic, use is made

of only one operator, i.e the application operator, or the operator

of application of one object to another The system of computations,

arising as a result of it, is called an applicative computation

sys-tem It is linked up with the conventional computation system, being

represented by a special object, i.e the Cartesian closed category.

Trang 32

• Building of representation, currying the n-ary function

Within combinatory logic, n-ary functions-operators, used in tional programming, have images in the form of objects, which inheritall their substantial properties

opera-• Deriving of basic properties of the Karoubi’s Shell

A special category, called the Karoubi’s shell, makes it possible tolaconically express a whole body of knowledge, related to operators,

in terms of combinatory logic In this case, the types are also encoded

by objects As a result, we implement the immersion or embedding ofthe typed application into the type free software environment

• Cartesian product and projections: embedding into ACS

The final completion of the started process of embedding is achieved

by the introduction of ordered populations of objects into tion It has turned out that applicative computations also allow theirrepresentation

considera-• Lisp Representation by means of lambda-calculus or

combi-natory logic

A non-trivial application is built into the applicative computation tem: a considerable and, actually, complete fragment of the well-known Lisp system of programming

sys-• Implementation of computation of expressions values with

the help of supercombinators

It is discussed how the object-oriented systems, built into tory logic, work Thus, it is possible to directly satisfy the need indenotational computation of instructions of programming languages,

Trang 33

combina-I NTRODUCTION 23

when objects are used to express the functional meaning of a gram It is significant that computation begins with a certain a prioriknown set of instructions In the process of the program value com-putation, new instructions dynamically arise, being earlier unknownbut indispensable in the process, which are additionally fixed in thesystem of programming

pro-• Fully lazy implementation of supercombinators

When the dynamic formation of objects is performed ”on-fly”, theefficiency of the resulting code may be lost because of the need torepeatedly calculate the value of one and the same object The ap-plication of the mechanism of lazy evaluations makes it possible toavoid it: once the value of an object has been calculated, this alreadycalculated value will always be used further on

• Optimization of computation process by permutation of

pa-rameters

The use of combinators makes it possible to build up an optimizedprogram code, while, in the course of synthesis of the resulting object,analyzing the order of the possible substitution of formal parameterswith actual ones

• Implementation of direct computations of expressions of

programming languages

The technique of evaluating the expressions is reconsidered in theview of systematic build-up of both syntactic and semantic equa-tions, implementing the selected paradigm of object-oriented com-putations

Trang 34

• Evaluation of the de Bruijn’s code

A technique for re-designation of bound variables (formal eters) is introduced into consideration, which makes it possible toavoid binding collisions in replacing formal parameters by actual

param-ones This technique of re-designation is called de Bruijn’s

encod-ing and allows, in fact, the lambda-calculus apparatus to be used on

the same legal basis as for the combinatory logic apparatus

• Implementation of machine instructions of the categorical

abstract machine (CAM)

A special version of the theory of computation, named categorical

abstract machine, is being built For this purpose, a special fragment

of combinatory logic, i.e categorical combinatory logic, is introducedinto consideration It is represented by a set of combinators, each ofwhich being of a self-sustained significance as an instruction of thesystem of programming Thus, one more useful application, i.e thesystem of programming, based on the Cartesian closed category, isbeing built into combinatory logic It allows the connection betweenthe operative and applicative styles of programming to be reconsid-ered once again but at a new level

• Capabilities of optimization in computation on the CAM

The use of Cartesian closed category opens up additional capabilitiesfor the optimization of the resulting program code In addition to theproperties of combinatory logic per se, used as a shell, it is allowed touse special categorical equations, borrowed from the Cartesian closedcategory, as from an application

• Variable objects

The concluding part of considering the calculi of objects deals withgeneric questions of mathematical representation of objects It is

Trang 35

as well as the semantics of the programming systems and the models

of data objects The data-as-objects display new degrees of freedom

To this preliminary part, Sections5,9,7–8can be added, whichdeal with numerals, recursion, and expansions in basis

Then, one may read Sections 10, 15–18, introducing a body ofconcepts for programming by means of combinators with the dy-namic system of instructions

Other sections can be added to one’s taste In particular, a moredetailed acquaintance with the categorial abstract machine in Sec-tions19–22will require one to refer to the literature cited in the bib-liography Sections11–14are aimed at those readers, who want toindependently begin reading original research papers in the field ofcomputer science Having mastered the basic ideas of the theory

of computation, one can start reading papers, devoted to this topic

On the other hand, Section23may of interest to those readers, whowould like to go deeper into the very essence of creating “built-inapplications”, requiring modification of the software environment In

Trang 36

such a case, the researcher encounters variable notions or, in otherterms, variable concepts.

Trang 37

Chapter 1

Preliminaries

Nowadays the theoretical studies in an area of computer science aregrounded at the stable main mathematical means As it happened,this is just the several interrelated branches, giving rise both to logic

and computer science Among them are λ-calculus, combinators,

type systems, category theory and programming languages.

λ-calculus. In this branch those modes of constructing the purecalculus of functional abstraction and application of functions arestudied, that obtain the application areas in metamathematics, logicand computer science

Combinatory logic. In developing this branch it has been shown,that bound variables can be excluded without lost of expressive power

of the formal system The most important applications of combinatorylogic have been found in constructing the foundations of mathemat-ics, and in constructing methods and and tools for implementing theprogramming languages

Type systems. Currently, λ-calculus gives the main means forstudying the type systems, and its results gave an important insights

27

Trang 38

both for the foundations of mathematics and for the practice of structing and applying of programming languages.

con-Category theory. This branch, from a mathematical point of view,

deals just with two entities – objects and mappings, – but the last,

in turn, can be considered as objects Applying the methods of gory theory seems especially important in case of research, develop-ment and application of the object programming systems

cate-Programming languages. It is rather difficult to consider thesethree main branches: λ-calculus, combinatory logic and type sys-tems, – singularly, separated each from others They are interrelated,and current point of view is in their mutual studies Moreover, namelythese three branches give a sound ground to construe the program-ming languages

Currently, there are more and more reasons to add to this list, on

equal rights, one more branch – category theory, which involves the only notion, namely: representation of an abstract object that covers

the mappings as well

At a first look, a spectrum of ideas, covered in these branches,

is not homogeneous, resulting in growth of seemingly disparate malisms and mathematical means Actually, it happens even more:every current research, as a rule, includes the constructing of its ownmathematical means Rather often, the main mathematical ideas,used by the author, are hidden by the complicated evaluations.Studying of the branches, mentioned above, helps to discover theintrinsic unity of the disparate researches, and their regular appli-cation supplies a researcher or developer by both the conceptuallytransparent and flexible and powerful theoretical means

Trang 39

for-C HAPTER 1 : P RELIMINARIES 29

1.1 The spectrum of ideas

Currently, after more careful consideration, it appears that the fulfilled

in an area of computer science researches use some or other ideas

either of category theory, or of combinatory logic, or of calculi of

λ-conversions, or of all these three disciplines altogether.

Importance of getting acquainted the knowledge of these ches of mathematics is so evident, that, opening practically occa-sional proceedings of any conference in computer science, you canfind not only pure nominal usage of λ-notations, but actual con-structing of own mathematical language, which is based on usingthe applications and abstractions Nevertheless, the attempts of self-studying the foundations of λ-calculus or combinatory logic meet thedifficulties from the very early steps: a known effort is needed “to fit

bran-a wbran-ay of thinking” from operbran-ationbran-al point of view of mbran-athembran-aticbran-al notations to applicative one, when there is no generic separation of

mathematical entities into ‘functions’ and ‘arguments’, but there arethe only ‘objects’ It is interesting to observe, that the same object,

depending on a context, can be used in different roles, sometimes

playing the role of an argument and sometimes – the role of a tion

func-From the syntax point of view, the objects are indicated either bythe notations with parentheses, or by using an agreement of omittingthe non-significant parentheses, when they, by need, can be restoredwithout any ambiguity Another significant feature is to establish a

property of being basic for some pre-specified objects Any time it

is evident, that newly introduced object can be rather suitably

repre-sented by combining of generic objects, which, under such a stance, can be called the combinators It is difficult to overestimate

circum-this ability to disassemble the arbitrary introduced object into basis:

in place of studying of properties of complicated applied theory with

a great amount of distinct objects, it could be possible to study theproperties just of several objects, without any loss of generality of the

Trang 40

obtained result.

For a specialist in computer science this is rather desirable erty It is evident, that the basic combinators can be assumed as a

prop-system of commands of some abstract computing prop-system, and the

rest of the objects can be expressed, i.e “programmed”, by usingnamely this set of commands In spite of seeming evidence, this abil-ity of means of the combinatory logic is not yet properly applied inpractice of computer studies

1.2 Layout of a chapter

A discussion of philosophical, pure mathematical or technical aspects

of applicative computations can lead far distant to the side of tions of mathematics Nevertheless, there is rather acceptable way.For a beginning, it can be reasonable to restrict yourself by solvingsome – however, for a first look, abstract, – problems, and after thatmake a conclusion, if is it needed to move further, in depth of ideas ofapplicative computations

founda-This chapter is to be assumed as some kind of menu, in which themain questions are indicated, and interaction of which, at first, could

be seen immediately, but after that, in detailed study, getting clear itsdeeper essence

The current chapter contains the sets of variants of the tasks,which are recommended to use in self studying

In case of organizing the studying in the classes of λ-calculusand combinatory logic, it can be recommended to select out the spe-cial units of tasks by variants, allowing to make not “so large”, butrather acceptable steps in learning of new mathematical, or, better,computational ideas These variants of the tasks are arranged in theTable1.1 The tasks for self studying are composed by such a way,that covers most of the chapters in this volume

Ngày đăng: 22/03/2014, 16:22