Parallel Functional Programming with APL

Total Page:16

File Type:pdf, Size:1020Kb

Parallel Functional Programming with APL Parallel Functional Programming, APL Lecture 1 Parallel Functional Programming with APL Martin Elsman Department of Computer Science University of Copenhagen DIKU December 19, 2016 Martin Elsman (DIKU) Parallel Functional Programming, APL Lecture 1 December 19, 2016 1 / 18 Outline 1 Outline Course Outline 2 Introduction to APL What is APL APL Implementations and Material APL Scalar Operations APL (1-Dimensional) Vector Computations Declaring APL Functions (dfns) APL Multi-Dimensional Arrays Iterations Declaring APL Operators Function Trains Examples Reading Martin Elsman (DIKU) Parallel Functional Programming, APL Lecture 1 December 19, 2016 2 / 18 Outline Course Outline Teachers Martin Elsman (ME), Ken Friis Larsen (KFL), Andrzej Filinski (AF), and Troels Henriksen (TH) Location Lectures in Small Aud, Universitetsparken 1 (UP1); Labs in Old Library, UP1 Course Description See http://kurser.ku.dk/course/ndak14009u/2016-2017 Course Outline Week 47 48 49 50 51 1–3 Mon 13–15 Intro, Futhark Parallel SNESL APL (ME) Project Futhark (ME) Haskell (AF) (ME) (KFL) Mon 15–17 Lab Lab Lab Lab Project Wed 13–15 Futhark Parallel SNESL Invited APL Project (ME) Haskell (AF) Lecture (ME) / (KFL) (John Projects Reppy) Martin Elsman (DIKU) Parallel Functional Programming, APL Lecture 1 December 19, 2016 3 / 18 Introduction to APL What is APL APL—An Ancient Array Programming Language—But Still Used! Pioneered by Ken E. Iverson in the 1960’s. E. Dijkstra: “APL is a mistake, carried through to perfection.” There are quite a few APL programmers around (e.g., HIPERFIT partners). Very concise notation for expressing array operations. Has a large set of functional, essentially parallel, multi- dimensional, second-order array combinators. E.g., reduce, scan, reduce, map, zipWith (implicit vectorisation) Martin Elsman (DIKU) Parallel Functional Programming, APL Lecture 1 December 19, 2016 4 / 18 Introduction to APL APL Implementations and Material Implementations of APL Dyalog APL: http://dyalog.com/ TryAPL: http://www.tryapl.org/ Gnu-APL: https://www.gnu.org/software/apl/ NGN APL: https://ngn.github.io/apl/web/ (zero-indexed) TAIL-APL: https://github.com/melsman/apltail Material Bernard Legrand. Mastering Dyalog APL. Online. http://dyalog.com/uploads/ documents/MasteringDyalogAPL.pdf. Martin Elsman (DIKU) Parallel Functional Programming, APL Lecture 1 December 19, 2016 5 / 18 Introduction to APL APL Scalar Operations APL Scalar Operations 3+4 " Scalar op 7 2#3+4 " Right-parsed 14 %2#3+4 " Reciprocal Essentially only one 0.07142857143 numeric type (B ! Z ! R a _%2#3+4 " Assignment ! C). a + 1 " Var use 1.07142857143 Many built-in functions are 1.05a " Max (dyadic) overloaded (e.g., %, ). 1.07142857143 The character type is a " Floor (monadic) 1 another basic type. 0J1*2 " Complex squared APL is in principle a 1 dynamically typed language. 2 a " Comparison 0 ’a’ + 1 " Character DOMAIN ERROR Martin Elsman (DIKU) Parallel Functional Programming, APL Lecture 1 December 19, 2016 6 / 18 Introduction to APL APL (1-Dimensional) Vector Computations APL (1-Dimensional) Vector Computations v _ 5 4 2 1 " Vector declaration v#2 " Scalar expansion 10 8 4 2 +/v#2 " Reduction (/ is an ‘‘operator’’) 24 %v " Vectorised monadic op 0.2 0.25 0.5 1 4 " Index (one-indexed) 1 2 3 4 v+| 4 " Point-wise + of reversed iota 9 7 4 2 1|v+| 4 " Rotate 1 7 4 2 9 (1|v+| 4)[2 1] " Index 4 7 £|1|v+| 4 " Grade-up (sort indexes) 3 2 1 4 u[£|(u_1|v+| 4)] " Sort 2 4 7 9 Martin Elsman (DIKU) Parallel Functional Programming, APL Lecture 1 December 19, 2016 7 / 18 Introduction to APL APL (1-Dimensional) Vector Computations More APL (1-Dimensional) Vector Computations v _ 3 " Vector declaration 5^v " Take 5 elements 1 2 3 0 0 5^v " Undertake (from the right) 0 0 1 2 3 5 8 " Drop 6 7 8 y_(5# 2),5 8 " Concatenation 5 10 6 7 8 /y " Find maximum (/ is an ‘‘operator’’) 10 (y>6)/y " Compress 10 7 8 +\y " Inclusive prefix scan (\ operator) 5 15 21 28 36 Martin Elsman (DIKU) Parallel Functional Programming, APL Lecture 1 December 19, 2016 8 / 18 Introduction to APL Declaring APL Functions (dfns) Declaring APL Functions f _ {¥+2} 8 3 4 " Monadic function 10 5 6 g _ {((¤*2)+¥*2)*0.5} " Dyadic function 3 g 4 5 Example—Signal Processing diff _ {1¥-1|¥} signal _ {505050#(diff 0,¥)%0.01+¥} +/ signal 9 8 6 8 7 4 4 3 2 2 1 2 4 5 6 27.870466 Example—Integration f _ { 2%¥+2 } " Function λx.2/(x+2) X _ 1000000 " Points dom _ 10#( X)%X " Integrate in [0;10] (10%X)#+/f dom " Compute integral 3.583514772 ≈ 2(ln 12 − ln 2) = 3:5835189 Martin Elsman (DIKU) Parallel Functional Programming, APL Lecture 1 December 19, 2016 9 / 18 Introduction to APL APL Multi-Dimensional Arrays APL Multi-Dimensional Arrays a _ 2 3 5 " Reshape a Most vector operations are 1 2 3 4 5 1 generalised straightforwardly b _ \a © b " Transpose to work on multi-dimensional 1 4 arrays (e.g., |, ^, , +/) 2 5 3 1 All values are arrays and each array has a shape, a vector b " Shape of containing the index range of 3 2 each dimension. The shape of a " 1 b Drop scalar is the empty vector. 2 5 3 1 The rank of an array is the shape of the shape of the array. # " ( 3) . 4 Outer prod Scalars have rank 0 and vectors 1 2 3 4 2 4 6 8 have rank 1. 3 6 9 12 Martin Elsman (DIKU) Parallel Functional Programming, APL Lecture 1 December 19, 2016 10 / 18 Introduction to APL APL Multi-Dimensional Arrays Inner Products a _ 3 2 5 1 3 5 b _ \ a 2 4 1 a +.# b 5 11 7 1 2 5 11 7 11 25 19 3 4 11 25 19 7 19 26 5 1 7 19 26 Inner Product is Generic The inner product operator is f _ { ¥ &. 100 } f 1 2 3 100 232 22 3 generic in the applied dyadic 0 functions used. f 1 2 3 12 232 22 3 Inner product works on 1 compatible arrays of any rank! Martin Elsman (DIKU) Parallel Functional Programming, APL Lecture 1 December 19, 2016 11 / 18 Introduction to APL APL Multi-Dimensional Arrays Example—Calculating Primes A_1 10 primes _ (1=+/-0=A.|A)/A primes 2 3 5 7 +/ primes 17 0=A.|A Dyadic | is the residual 1 0 1 0 1 0 1 0 1 function. 0 1 0 0 1 0 0 1 0 +/- reduces along the last axis. 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Martin Elsman (DIKU) Parallel Functional Programming, APL Lecture 1 December 19, 2016 12 / 18 Introduction to APL Iterations The APL Power Operator The power operator is a dyadic operator that, when applied, ({ ¥ + 3 } §*4) 100 results in a monadic function. 112 ({ ¥ ,’-’, ¥ } §*3) 'ab' The operator takes a function ab-ab-ab-ab-ab-ab-ab-ab as its left argument and an “iteration count” as its right argument. Martin Elsman (DIKU) Parallel Functional Programming, APL Lecture 1 December 19, 2016 13 / 18 Introduction to APL Iterations Example—Sierpinski f _ {(¥,( ¥) ’ ’),-¥,¥} S _ {(f§*¥)1 1 '+'} S 1 + ++ S 4 + ++ If S is the triangle at level n, + + then the triangle at level n + 1 ++++ S0 is . + + SS ++ ++ + + + + ++++++++ + + ++ ++ + + + + ++++ ++++ Martin Elsman (DIKU) Parallel Functional Programming, APL Lecture 1 December 19, 2016 14 / 18 Introduction to APL Declaring APL Operators Declaring APL Operators APL operators are second-order functions, which may take functions (monadic or dyadic) as arguments and results in a function (monadic or dyadic). Operators in APL are declared similarly to how functions are declared. In the body of the operator, the function parameters are referred to by ¤¤ and ¥¥ and the residual function’s parameters are referred to by ¤ and ¥. Example op _ {¤¤/2+¥} # op 5 2520 Martin Elsman (DIKU) Parallel Functional Programming, APL Lecture 1 December 19, 2016 15 / 18 Introduction to APL Function Trains Function Trains Function trains are used for writing APL code in “points-free notation”. Function trains can make code very concise. A “train” fgh is identical (in λ-calculus) to λx:g(f x; h x). Example mean _ +/%6≡ " f is +/ ; g is dyadic % mean 1 3 7 3 8 5 " h is 6≡ (tally) 4.5 Martin Elsman (DIKU) Parallel Functional Programming, APL Lecture 1 December 19, 2016 16 / 18 Introduction to APL Examples Game of Life life _ { rowsum _ {(1|¥) + ¥ + 1|¥ } .......... neighbor _ { .......... (rowsum 1¥- ) + (rowsum ¥) + rowsum 1¥- ..###..... } ..#....... n _ neighbor ¥ ...#...... (n=3) ¨ (n=4) & ¥ .......... } .......... nlife _ { (life §*¤) ¥ } .......... glider _ 3 3 1 1 1 1 0 0 0 1 0 .......... board _ \10 ^ \10 ^ glider .......... ’.#’[1+20 nlife board] Martin Elsman (DIKU) Parallel Functional Programming, APL Lecture 1 December 19, 2016 17 / 18 Introduction to APL Reading Possible Reading Ken E. Iverson. 1979 Turing Award Lecture: Notation as a Tool of Thought. http://www.eecg.toronto.edu/˜jzhu/csc326/readings/ iverson.pdf. In addition to the executability and universality emphasized in the introduction, a good notation should embody characteristics familiar to any user of mathematical notation:” Ease of expressing constructs arising in problems. Suggestivity. Ability to subordinate detail.
Recommended publications
  • R from a Programmer's Perspective Accompanying Manual for an R Course Held by M
    DSMZ R programming course R from a programmer's perspective Accompanying manual for an R course held by M. Göker at the DSMZ, 11/05/2012 & 25/05/2012. Slightly improved version, 10/09/2012. This document is distributed under the CC BY 3.0 license. See http://creativecommons.org/licenses/by/3.0 for details. Introduction The purpose of this course is to cover aspects of R programming that are either unlikely to be covered elsewhere or likely to be surprising for programmers who have worked with other languages. The course thus tries not be comprehensive but sort of complementary to other sources of information. Also, the material needed to by compiled in short time and perhaps suffers from important omissions. For the same reason, potential participants should not expect a fully fleshed out presentation but a combination of a text-only document (this one) with example code comprising the solutions of the exercises. The topics covered include R's general features as a programming language, a recapitulation of R's type system, advanced coding of functions, error handling, the use of attributes in R, object-oriented programming in the S3 system, and constructing R packages (in this order). The expected audience comprises R users whose own code largely consists of self-written functions, as well as programmers who are fluent in other languages and have some experience with R. Interactive users of R without programming experience elsewhere are unlikely to benefit from this course because quite a few programming skills cannot be covered here but have to be presupposed.
    [Show full text]
  • Programming Language
    Programming language A programming language is a formal language, which comprises a set of instructions that produce various kinds of output. Programming languages are used in computer programming to implement algorithms. Most programming languages consist of instructions for computers. There are programmable machines that use a set of specific instructions, rather than general programming languages. Early ones preceded the invention of the digital computer, the first probably being the automatic flute player described in the 9th century by the brothers Musa in Baghdad, during the Islamic Golden Age.[1] Since the early 1800s, programs have been used to direct the behavior of machines such as Jacquard looms, music boxes and player pianos.[2] The programs for these The source code for a simple computer program written in theC machines (such as a player piano's scrolls) did not programming language. When compiled and run, it will give the output "Hello, world!". produce different behavior in response to different inputs or conditions. Thousands of different programming languages have been created, and more are being created every year. Many programming languages are written in an imperative form (i.e., as a sequence of operations to perform) while other languages use the declarative form (i.e. the desired result is specified, not how to achieve it). The description of a programming language is usually split into the two components ofsyntax (form) and semantics (meaning). Some languages are defined by a specification document (for example, theC programming language is specified by an ISO Standard) while other languages (such as Perl) have a dominant implementation that is treated as a reference.
    [Show full text]
  • RAL-TR-1998-060 Co-Array Fortran for Parallel Programming
    RAL-TR-1998-060 Co-Array Fortran for parallel programming 1 by R. W. Numrich23 and J. K. Reid Abstract Co-Array Fortran, formerly known as F−− , is a small extension of Fortran 95 for parallel processing. A Co-Array Fortran program is interpreted as if it were replicated a number of times and all copies were executed asynchronously. Each copy has its own set of data objects and is termed an image. The array syntax of Fortran 95 is extended with additional trailing subscripts in square brackets to give a clear and straightforward representation of any access to data that is spread across images. References without square brackets are to local data, so code that can run independently is uncluttered. Only where there are square brackets, or where there is a procedure call and the procedure contains square brackets, is communication between images involved. There are intrinsic procedures to synchronize images, return the number of images, and return the index of the current image. We introduce the extension; give examples to illustrate how clear, powerful, and flexible it can be; and provide a technical definition. Categories and subject descriptors: D.3 [PROGRAMMING LANGUAGES]. General Terms: Parallel programming. Additional Key Words and Phrases: Fortran. Department for Computation and Information, Rutherford Appleton Laboratory, Oxon OX11 0QX, UK August 1998. 1 Available by anonymous ftp from matisa.cc.rl.ac.uk in directory pub/reports in the file nrRAL98060.ps.gz 2 Silicon Graphics, Inc., 655 Lone Oak Drive, Eagan, MN 55121, USA. Email:
    [Show full text]
  • Programming the Capabilities of the PC Have Changed Greatly Since the Introduction of Electronic Computers
    1 www.onlineeducation.bharatsevaksamaj.net www.bssskillmission.in INTRODUCTION TO PROGRAMMING LANGUAGE Topic Objective: At the end of this topic the student will be able to understand: History of Computer Programming C++ Definition/Overview: Overview: A personal computer (PC) is any general-purpose computer whose original sales price, size, and capabilities make it useful for individuals, and which is intended to be operated directly by an end user, with no intervening computer operator. Today a PC may be a desktop computer, a laptop computer or a tablet computer. The most common operating systems are Microsoft Windows, Mac OS X and Linux, while the most common microprocessors are x86-compatible CPUs, ARM architecture CPUs and PowerPC CPUs. Software applications for personal computers include word processing, spreadsheets, databases, games, and myriad of personal productivity and special-purpose software. Modern personal computers often have high-speed or dial-up connections to the Internet, allowing access to the World Wide Web and a wide range of other resources. Key Points: 1. History of ComputeWWW.BSSVE.INr Programming The capabilities of the PC have changed greatly since the introduction of electronic computers. By the early 1970s, people in academic or research institutions had the opportunity for single-person use of a computer system in interactive mode for extended durations, although these systems would still have been too expensive to be owned by a single person. The introduction of the microprocessor, a single chip with all the circuitry that formerly occupied large cabinets, led to the proliferation of personal computers after about 1975. Early personal computers - generally called microcomputers - were sold often in Electronic kit form and in limited volumes, and were of interest mostly to hobbyists and technicians.
    [Show full text]
  • Tangent: Automatic Differentiation Using Source-Code Transformation for Dynamically Typed Array Programming
    Tangent: Automatic differentiation using source-code transformation for dynamically typed array programming Bart van Merriënboer Dan Moldovan Alexander B Wiltschko MILA, Google Brain Google Brain Google Brain [email protected] [email protected] [email protected] Abstract The need to efficiently calculate first- and higher-order derivatives of increasingly complex models expressed in Python has stressed or exceeded the capabilities of available tools. In this work, we explore techniques from the field of automatic differentiation (AD) that can give researchers expressive power, performance and strong usability. These include source-code transformation (SCT), flexible gradient surgery, efficient in-place array operations, and higher-order derivatives. We implement and demonstrate these ideas in the Tangent software library for Python, the first AD framework for a dynamic language that uses SCT. 1 Introduction Many applications in machine learning rely on gradient-based optimization, or at least the efficient calculation of derivatives of models expressed as computer programs. Researchers have a wide variety of tools from which they can choose, particularly if they are using the Python language [21, 16, 24, 2, 1]. These tools can generally be characterized as trading off research or production use cases, and can be divided along these lines by whether they implement automatic differentiation using operator overloading (OO) or SCT. SCT affords more opportunities for whole-program optimization, while OO makes it easier to support convenient syntax in Python, like data-dependent control flow, or advanced features such as custom partial derivatives. We show here that it is possible to offer the programming flexibility usually thought to be exclusive to OO-based tools in an SCT framework.
    [Show full text]
  • Abstractions for Programming Graphics Processors in High-Level Programming Languages
    Abstracties voor het programmeren van grafische processoren in hoogniveau-programmeertalen Abstractions for Programming Graphics Processors in High-Level Programming Languages Tim Besard Promotor: prof. dr. ir. B. De Sutter Proefschrift ingediend tot het behalen van de graad van Doctor in de ingenieurswetenschappen: computerwetenschappen Vakgroep Elektronica en Informatiesystemen Voorzitter: prof. dr. ir. K. De Bosschere Faculteit Ingenieurswetenschappen en Architectuur Academiejaar 2018 - 2019 ISBN 978-94-6355-244-8 NUR 980 Wettelijk depot: D/2019/10.500/52 Examination Committee Prof. Filip De Turck, chair Department of Information Technology Faculty of Engineering and Architecture Ghent University Prof. Koen De Bosschere, secretary Department of Electronics and Information Systems Faculty of Engineering and Architecture Ghent University Prof. Bjorn De Sutter, supervisor Department of Electronics and Information Systems Faculty of Engineering and Architecture Ghent University Prof. Jutho Haegeman Department of Physics and Astronomy Faculty of Sciences Ghent University Prof. Jan Lemeire Department of Electronics and Informatics Faculty of Engineering Vrije Universiteit Brussel Prof. Christophe Dubach School of Informatics College of Science & Engineering The University of Edinburgh Prof. Alan Edelman Computer Science & Artificial Intelligence Laboratory Department of Electrical Engineering and Computer Science Massachusetts Institute of Technology ii Dankwoord Ik wist eigenlijk niet waar ik aan begon, toen ik in 2012 in de cata- comben van het Technicum op gesprek ging over een doctoraat. Of ik al eens met LLVM gewerkt had. Ondertussen zijn we vele jaren verder, werk ik op een bureau waar er wel daglicht is, en is het eindpunt van deze studie zowaar in zicht. Dat mag natuurlijk wel, zo vertelt men mij, na 7 jaar.
    [Show full text]
  • Design and Implementation of an Array Language
    Design and Implementation of an Array Language Bernd Ulmann V. 1.1, 03-AUG-2013 To my beloved wife Rikka. Acknowledgments This book would not have been possible without the support and help of many people. First of all, I would like to thank my wife Rikka Mitsam who never complained about the many hours I spent writing instead of being with her and did a lot of proofreading. I am also greatly indebted to Thomas Kratz who did most of the implementation of the Lang5-interpreter and the Array::DeepUtils module. I am particularly grateful for the support and help of Jens Breitenbach and Hans Franke show did a magnificent job at proof reading and made many valuable sugges- tions which greatly enhanced this booklet. In addition to that, I would like to thank Patrick Hedfeld for countless fruitful discus- sions about languages in general and programming languages and Lang5 in special. He also did a terrific job with writing the Lang5-Redbook. In addition to that he spotted many flaws and faults in this booklet which were corrected accordingly. ©Bernd Ulmann Contents 1 Introduction 1 1.1 Preliminaries. .1 1.2 Array languages. .1 2 The design of Lang5 7 2.1 Reverse Polish notation . .7 2.2 Dynamic typing . .9 2.3 Data structures . 10 3 Installing and running Lang5 13 3.1 Installation. 13 3.2 Starting the interpreter . 15 3.3 First steps . 17 4 Lang5 basics 21 4.1 Getting started . 21 4.2 Basic data structures . 22 4.3 Language elements. 24 4.3.1 Operators .
    [Show full text]
  • Runtime Compilation of Array-Oriented Python Programs
    Runtime Compilation of Array-Oriented Python Programs by Alex Rubinsteyn A dissertation submitted in partial fulllment of the requirements for the degree of Doctor of Philosophy Department of Computer Science New York University September 2014 Professor Dennis Shasha Dedication This thesis is dedicated to my parents and to the area code 60076. iii Acknowledgements When I came to New York in 2007, I brought with me a Subaru Outback (mostly full of books), a thinly acquired degree in Neuroscience, a rapidly shrinking bank ac- count, and a nebulous plan to become a mathematician. When I wrote to a researcher at MIT, seeking a position in his lab, I had to admit that: “my GPA is horrible, my rec- ommendations grudgingly extracted from laughable sources.” To my earnest surprise, he never replied. Undeterred and full of condence in the victory of my enthusiasm over my historical inability to get anything done, I applied to Courant’s Masters pro- gram in Mathematics and was promptly rejected. In a panic, I applied to Columbia’s School of Continuing Education and was just as quickly turned away. I peppered them with embarrassing pleas to reconsider, until one annoyed administrator replied that “inconsistency and concern permeate each semester” of my transcript. Ouch. That I still ended up having the privilege to pursue my curiosity feels like a miracle and I owe a large debt of gratitude to many people. I would like to thank: • My former project-mate Eric Hielscher, with whom I carved out many of the ideas present in this thesis. • My advisor, Dennis Shasha, who gave us guidance, support, discipline and choco- late almonds.
    [Show full text]
  • APL / J by Seung­Jin Kim and Qing Ju
    APL / J by Seung-jin Kim and Qing Ju What is APL and Array Programming Language? APL stands for ªA Programming Languageº and it is an array programming language based on a notation invented in 1957 by Kenneth E. Iverson while he was at Harvard University[Bakker 2007, Wikipedia ± APL]. Array programming language, also known as vector or multidimensional language, is generalizing operations on scalars to apply transparently to vectors, matrices, and higher dimensional arrays[Wikipedia - J programming language]. The fundamental idea behind the array based programming is its operations apply at once to an entire array set(its values)[Wikipedia - J programming language]. This makes possible that higher-level programming model and the programmer think and operate on whole aggregates of data(arrary), without having to resort to explicit loops of individual scalar operations[Wikipedia - J programming language]. Array programming primitives concisely express broad ideas about data manipulation[Wikipedia ± Array Programming]. In many cases, array programming provides much easier methods and better prospectives to programmers[Wikipedia ± Array Programming]. For example, comparing duplicated factors in array costs 1 line in array programming language J and 10 lines with JAVA. From the given array [13, 45, 99, 23, 99], to find out the duplicated factors 99 in this array, Array programing language J©s source code is + / 99 = 23 45 99 23 99 and JAVA©s source code is class count{ public static void main(String args[]){ int[] arr = {13,45,99,23,99}; int count = 0; for (int i = 0; i < arr.length; i++) { if ( arr[i] == 99 ) count++; } System.out.println(count); } } Both programs return 2.
    [Show full text]
  • The Functional Imperative: Shape!
    139 The Functional Imperative: Shape! C.B. Jay P.A. Steckler School of Computing Sciences, University of Technology, Sydney, P.O. Box 123, Broadway NSW 2007, Australia; email: {cbj, steck}@socs, uts. edu. au fax: 61 (02) 9514 1807 1 Introduction FISH is a new programming language for array computation that compiles higher-order polymorphic programs into simple imperative programs expressed in a sub-language TURBOT, which can then be translated into, say, C. Initial tests show that the resulting code is extremely fast: two orders of magnitude faster than HASKELL, and two to four times faster than OBJECTIVE CAML, one of the fastest ML variants for array programming. Every functional program must ultimately be converted into imperative code, but the mechanism for this is often hidden. FISH achieves this transparently, using the "equation" from which it is named: Functional = Imperative + Shape Shape here refers to the structure of data, e.g. the length of a vector, or the number of rows and columns of a matrix. The FISH compiler reads the equation from left to right: it converts functions into procedures by using shape analysis to determine the shapes of all array expressions, and then allocating appropriate amounts of storage on which the procedures can act. We can also read the equation from right to left, constructing functions from shape functions and procedures. Let us consider some examples. >-I> let v = [I 0;1;2;3 I] ;; declares v to be a vector whose entries are 0, 1, 2 and 3. The compiler responds with both the the type and shape of v, that is, v : vec[int] #v = (-4,int_shape) This declares v has the type of an expression for a vector of integers whose shape #v is given by the pair ('4,int_shape) which determines the length of v, ~4, and the common shape int_shape of its entries.
    [Show full text]
  • Arrays of Objects Morten Kromberg Dyalog Ltd
    Arrays of Objects Morten Kromberg Dyalog Ltd. South Barn, Minchens Court, Minchens Lane, Bramley RG26 5BH, UK +44 1256 830 030 [email protected] ABSTRACT 1.1 Typical Uses of APL This paper discusses key design decisions faced by a language Users of APL tend to “live in their data”. Interactive interpreters design team while adding Object Oriented language features to allow them to inspect, almost feel their way forward, discovering Dyalog, a modern dialect of APL. Although classes and interfaces successful snippets of code through experimentation and are first-class language elements in the new language, and arrays collecting them into imperative or functional programs according can both contain and be contained by objects, arrays are not to taste. This does not mean that experienced APL developers objects. The use of object oriented features is optional, and users who understand the task never plan ahead; they sometimes do can elect to remain entirely in the functional and array paradigms “architect” and write pages of code without running them first of traditional APL. The choice of arrays as a “higher” level of (there do exist APL systems with more than a million lines of organization allows APL‟s elegant notation for array manipulation code), but the ability to stop a program at any point and return to to extend smoothly to arrays of objects. experimentation is a key factor for those individuals who are attracted to the use of APL as a tool of thought. Categories and Subject Descriptors Many of the most successful APL programmers are domain D.3.2 [Programming Languages]: Language Classifications – experts from other engineering fields than computer science or Object-oriented languages, APL; D.3.3 [Programming software engineering; they are stock brokers and traders who Languages]: Language Constructs and Features –classes and became coders, actuaries and crystallographers, electrical and objects, data types and structures, patterns.
    [Show full text]
  • Keir, Paul G (2012) Design and Implementation of an Array Language for Computational Science on a Heterogeneous Multicore Architecture
    Keir, Paul G (2012) Design and implementation of an array language for computational science on a heterogeneous multicore architecture. PhD thesis. http://theses.gla.ac.uk/3645/ Copyright and moral rights for this thesis are retained by the author A copy can be downloaded for personal non-commercial research or study, without prior permission or charge This thesis cannot be reproduced or quoted extensively from without first obtaining permission in writing from the Author The content must not be changed in any way or sold commercially in any format or medium without the formal permission of the Author When referring to this work, full bibliographic details including the author, title, awarding institution and date of the thesis must be given Glasgow Theses Service http://theses.gla.ac.uk/ [email protected] Design and Implementation of an Array Language for Computational Science on a Heterogeneous Multicore Architecture Paul Keir Submitted in fulfilment of the requirements for the degree of Doctor of Philosophy School of Computing Science College of Science and Engineering University of Glasgow July 8, 2012 c Paul Keir, 2012 Abstract The packing of multiple processor cores onto a single chip has become a mainstream solution to fundamental physical issues relating to the microscopic scales employed in the manufac- ture of semiconductor components. Multicore architectures provide lower clock speeds per core, while aggregate floating-point capability continues to increase. Heterogeneous multicore chips, such as the Cell Broadband Engine (CBE) and modern graphics chips, also address the related issue of an increasing mismatch between high pro- cessor speeds, and huge latency to main memory.
    [Show full text]