ebook img

Programming with Sets: An Introduction to SETL PDF

507 Pages·1986·11.037 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Programming with Sets: An Introduction to SETL

Texts and Monographs in Computer Science Editor David Gries Advisory Board F.L. Bauer J.J. Horning R. Reddy D.C. Tsichritzis W.M. Waite Texts and Monographs in Computer Science Suad Alagl(; Relational Database Technology Suad Alagu; and Michael A Arblb The Design of Well-Structured and Correct Programs S Thomas Alexander Adaptive Signal Processing: Theory and Applications Michael A Arblb, A J Kfoury, and Robert N Moll A Basis for Theoretical Computer Science Michael A Arblb and Ernest G Manes Algebraic Approaches to Program Semantics F L Bauer and H Wossner Algorithmic Language and Program Development Kaare Chnstlan The Guide to Modula-2 Edsger W DIJkstra Selected Writings on Computing: A Personal Perspective NI SSlm Francez Fairness Peter W Frey, Ed Chess Skill in Man and Machine, 2nd Edition R T Gregory and E V Kmhnamurthy Methods and Applications of Error-Free Computation DaVid Gnes, Ed Programming Methodology: A Collection of Articles by Members of IFIP WG2,3 DaVid Gnes The Science of Programming A J Kfoury, Robert N Moll, dnd Mlch"el A Arblb A Programming Approach to Computability E V Knshnamurthy Error-Free Polynomial Matrix Computations Franco P Preparata and Michael Ian Shamus Computational Geometry: An Introduction Bnan Randell, Ed The Origins of Digital Computers: Selected Papers Arto Salomaa and Matti SOittola Automata-TheQl"etic Aspects of Formal Power Series Jeffrey R Sampson Adaptive Information Processing: An Introductory Survey J T Schwartz, R B Dewar, E DublOsky, dnd E Schonberg: Programming with Sets: An Introduction to SETL Wilham M Watte and Gerhard Goos Compiler Construction Nlklaus Wirth Programming in Modula-2 Programming with Sets An Introduction to SETL J. T. Schwartz R.B.K. Dewar E. Dubinsky E. Schonberg With 31 Illustrations Springer-Verlag New York Berlin Heidelberg London Paris Tokyo J.T. Schwartz E. Dubinsky R.B.K. Dewar Department of Mathematics E. Schonberg and Computer Science Computer Science Department Clarkson University Courant Institute of Potsdam, NY 13676 Mathematical SCIences New York University New York, NY 10012 U.S.A. Series Editor David Gries Department of Computer Science Cornell University Ithaca, NY 14853 U.S.A. Library of Congress Cataloging in Publication Data Programmmg with sets. (Texts and monographs in computer science) Includes index. I. SETL (Computer program language) I. Schwartz, Jacob T. II. Series. QA 76.73.S4P76 1986 005.13'3 86-20386 © 1986 by Springer-Verlag New York Inc. Softcover reprint of the hardcover I st edition 1986 All rights reserved. No part of this book may be translated or reproduced in any form without written permiSSIOn from Springer-Verlag, 175 Fifth Avenue, New York, New York 10010, U.S.A. Typeset by Asco Trade Typesetting Ltd., Hong Kong. 9 8 7 6 5 4 3 2 I ISBN-13: 978-1-4613-9577-5 e-ISBN-13: 978-1-4613-9575-1 DOl: 10.1007/978-1-4613-9575-1 Preface The programming language SETL is a relatively new member of the so-called "very-high-level" class of languages, some of whose other well-known mem bers are LISP, APL, SNOBOL, and PROLOG. These languages all aim to reduce the cost of programming, recognized today as a main obstacle to future progress in the computer field, by allowing direct manipulation of large composite objects, considerably more complex than the integers, strings, etc., available in such well-known mainstream languages as PASCAL, PL/I, ALGOL, and Ada. For this purpose, LISP introduces structured lists as data objects, APL introduces vectors and matrices, and SETL introduces the objects characteristic for it, namely general finite sets and maps. The direct availability of these abstract, composite objects, and of powerful mathematical operations upon them, improves programmer speed and pro ductivity significantly, and also enhances program clarity and readability. The classroom consequence is that students, freed of some of the burden of petty programming detail, can advance their knowledge of significant algorithms and of broader strategic issues in program development more rapidly than with more conventional programming languages. The price that very-high-levellanguages pay for their expressive power is a certain loss of efficiency. SETL should therefore be regarded, not as a tool for production-efficiency programming, but as a vehicle for rapid experimen tation with algorithms and program design, and as an ideal vehicle for writing "one-shot" or infrequently used programs whose efficiency is of little con sequence. It is also an effective tool for proto typing large systems for purposes of design validation and early customer exposure, systems which if important enough can then be translated into more efficient versions written in pro gramming languages of lower level. Experience with SETL will show that it vi Preface is efficient enough for a surprising variety of purposes; nevertheless, it is still expensive to run and will remain so until the newest generation of high performance microcomputers becomes generally available. In spite of this, SETL is a good vehicle for discussing program-efficiency issues, since it allows a stepwise approach to these issues, algorithm design being chosen first and data structures which realize them being chosen second. It will also be seen that the data structure representation sublanguage of SETL, described in Chapter 10, is a powerful conceptual tool aiding such "programming by stepwise refinement." Fairly polished versions ofSETL are currently available on the DEC VAX, IBM/370, SUN workstation and APOLLO. The systems running on all these machines are close to identical, all being produced from a common system source by transporting an underlying systems-implementation language from machine to machine. This book is intended for people who want to write programs in SETL. It does not assume knowledge of any other programming language and is therefore suitable for use in an introductory course. We attempt to explain most of the mathematical concepts which play a role in SETL programs, almost all of which are in fact quite elementary. However, we do assume that the reader has a working knowledge of such basic concepts as set, sequence, etc. The knowledge assumed is roughly equivalent to that which would be acquired in a good high school "new mathematics" course, or in the first month of a freshman-level course in discrete mathematics. We present considerably more material than can be covered in a one semester introductory course. Chapter 1 provides an introduction to com puter programming and a brief overview of the SETL language. (It can safely be ignored by readers who have some previous exposure to programming.) Chapters 2 and 3 introduce the major data objects of SETL, of which sets, maps, and tuples are most characteristic, and describe many of the language's operations. By the end of Chapter 3, the student is in a position to write various interesting one-liners. Chapter 4 then presents various basic control structure notions, qualifying the student to write interesting short programs. Chapter 5 introduces the most important control structures, namely procedures. Chapter 6 gives advice on program development, testing, and debugging, completing what can be considered the elementary part of the book. Chapter 7 describes the backtracking dictions of SETL. The first seven chapters can be covered in a one-semester introductory course and can be skimmed rapidly by any reader reasonably familiar with at least one modern programming language, such as PL/1, ALGOL 68, PASCAL, or Ada. The remaining chapters present more advanced material, which could be covered in a second programming course. Chapter 8 introduces the directory, program, module, and library mechanisms used to structure large programs. Chapter 9 describes the I/O features of SETL systematically. Chapter 10 presents SETL's data representation sublanguage and reviews various stra- Preface VII tegic considerations which playa role in data representation choice. Chapter 11 shows the language in action by presenting several more substantial applications of it. SETL was developed at the Computer Science Department of New York University, by a group of which three of the present authors were members. The language has now been used by students in courses at NYU, Clarkson University, Dickinson College and University of California, Berkeley ranging from the introductory undergraduate to graduate courses in algorithm design. The style and order of presentation adopted in this book reflects some of the pedagogical experience gained in this way, especially at the undergraduate level. Thanks are due to the many persons who helped to define and develop the SETL system. David Shields has been a mainstay throughout, inventing and implementing many system improvements, and developing documentation from which several of the sections of the book are drawn. Much of the first version of the system was written by Arthur Grand and brought to solidity by Stefan Freudenberger. Thanks are also extended to Edith Schonberg, Micha Sharir, Robert Paige, Kurt Maly, Phillip Owens, Aaron Stein, Earl Draughon, Bernard Lang, Leonard Vanek, Steve Tihor, Hank Warren, and Gerry Fisher, all of whom contributed to the development of the SETL system. Thanks are also due to the members of the NYUADA group, the largest and most persistent users of the SETL system in their experiments in Software Proto typing. Valuable design suggestions were contributed by our colleague Professor Malcolm Harrison and gleaned from his elegant BALM language. Essential thanks are due to the very helpful and hard-working group of summer interns who helped put this manuscript together and remove many of its errors during the summer of 1981: Leonid Fridman, Nathaniel Glasser, Barbara Okun, and Yi Tso. Many thanks to David Berkowitz who was responsible for coordinating the editing and debugging process in its final stages. We also wish to extend thanks to Professor Andrei Ershov and his group at Novosibirsk, who have aided the development and definition of the language from the very first days, Professor Anthony McCann of Leeds University, and Drs. Su Bogong and Zhou Zhiying of Tsinghua University, whose more recent involvement has been most valuable. Thanks are due to the research administrators who fostered the develop ment of SETL through its early, relatively isolated years. Among these we should particularly like to thank Milton Rose, who launched our development effort during his years at NSF, also Kent Curtis and Tom Keenan of NSF, who fostered it during the period in which the NYU group was struggling toward a reliable and acceptably efficient implementation. Recent support from the Office of Naval Research is making possible an improved implementation of SETL and renewed research in language design; for his support and en couragement we want to thank here Robert Grafton. The able secretarial work of Allison Sundheim, Marina Lowry, and Yanire viii Preface Zayas is gratefully acknowledged: their care, patience, and unflappable good humor in the face of an ever-changing manuscript has been invaluable. The detailed editorial advice of Springer-Verlag added a layer of much-needed polish to this text. To all of them our heart-felt thanks, and of course a full exoneration from whatever errors remain lurking in the text that follows. Contents CHAPTER 1 Programming Concepts 1.1 An Informal Overview of SETL 1.2 Advice to the Would-Be Programmer 6 1.3 Programming Steps: How to Run Your Program and Read Its Results 10 1.4 How to Type a Program: Character Sets 14 1.4.1 Comments 16 1.5 Appendix: More on How to Read Your Output Listing 17 1.5.1 Missing quotation marks 20 1.5.2 Other features of the compilation history 20 1.5.3 Review of principal actions which occur when a job is run 23 CHAPTER 2 Simple Data Types, Expressions, and Operations 25 2.1 The Main Classes of Data Objects 25 2.2 Simple Types and Their Constants 26 2.2.1 Integer constants 26 2.2.2 Floating-point constants 27 2.2.3 String constants 28 2.2.4 Boolean constants 29 2.2.5 Atoms 29 2.2.6 Om: the underfined value 29 2.3 Variable Identifiers 29 2.4 Expressions and Statements 31 2.5 Operations with Simple Data Types 34 2.5.1 Integer operators 34 x Contents 2.5.1.1 Binary operations on integers 34 2.5.1.2 Predicates on integers 34 2.5.1.3 Unary integer operators 35 2.5.2 Floating-point operators 38 2.5.2.1 Binary floating-point operators 38 2.5.2.2 Predicates on floating-point values 38 2.5.2.3 Unary floating-point operators 38 2.5.3 String operators 40 2.5.4 Boolean operators 43 2.5.4.1 Boolean equivalences 44 2.5.5 Operations with atoms 45 CHAPTER 3 Compound Data Types and Operators 48 3.1 Sets and Set Denotations 48 3.1.1 Some useful sets of integers 50 3.2 Tuples 50 3.2.1 Some useful tuples of integers 52 3.3 Maps 53 3.4 The Size of Composite Objects: The # Operator 54 3.5 Set Operations and Set Formers 57 3.5.1 Binary set operators 57 3.5.2 Unary set operators 59 3.5.3 Set former expressions 60 3.5.4 Existential and universal quantifiers 63 3.5.4.1 A remark on bound variables in compound set formers and q uan tifiers 65 3.5.5 Some illustrative one-statement programs 65 3.5.5.1 More about prime numbers 66 3.5.5.2 Integer right triangles 67 3.6 Tuple Operations and Tuple Formers 67 3.6.1 Binary tuple operators 68 3.6.2 Unary tuple operators 69 3.6.3 Other tuple operators. Indexing and slicing 69 3.7 Tuple Formers; Simple Tuple and String Iterators 72 3.8 Map Operations 75 3.8.1 The image-set operator f{x} 75 3.8.2 The single-valued image operator f(x) 76 3.8.3 Some remarks on multivalued maps 81 3.8.4 Two useful map operations 82 3.8.5 Multiparameter maps 82 3.9 Compound Operators 83 3.10 Types and Type-Testing Operators 85 3.11 The? Operator 85 3.12 General Form of the SETL Assignment: The Operators from, frome, and fromb 90 3.12.1 Assigning forms of infix operators 93 3.12.2 Assignment expressions 94

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.