ELI: Programming with Arrays

ELI: Programming with Arrays

ELI: Programming with Arrays Hanfeng Chen1 and Wai-Mee Ching2 1 [email protected] 2 [email protected] https://fastarray.appspot.com In this talk: ELI • What is ELI? • An array programming language^1 • Based on APL and influenced by KDB^2 • Support classic APL1 (flat arrays) and database components • Why is ELI? • No variable declarations • Fast programming, simple syntax, and parallel semantics • Easy to learn and easy to communicate! ^1 ELI homepage: https://fastarray.appspot.com ^2 KX company: https://www.kx.com Page 1 Programming with ELI 2 Introduction • ELI language • An ASCII version of APL • Monadic (unary) and dyadic (binary) primitive functions • Equal precedence of all primitive functions • Right-to-left execution order Page 3 ELI Types • Array types (Homogeneous, multi-dimensional) • Boolean (0 or 1), integer, floating-point number • Complex number (e.g. 2j3 for 2+3i) • Character (e.g. “tea”) • Symbol (e.g. `bubble) • List (Non-homogeneous data) • Database-related types • Date and time • Dictionary and tables Page 4 ELI Examples - I • Generating a vector ELI functions !10 // APL: �10 ! : iota 1 2 3 4 5 6 7 8 9 10 * : multiplication • Multiplying the vector by 100 # : reshape 100 * !10 // APL: 100 × �10 100 200 300 400 500 600 700 800 900 1000 • Generating a 3-by-4 matrix 3 4#!10 // APL: 3 4 � �10 1 2 3 4 5 6 7 8 9 10 1 2 Page 5 ELI Examples - II • Complex number ELI functions @1 // � ! : iota 3.141592654 * : multiplication 0j1*@1 // 0 + �� *.: f(x)= �) 0j3.141592654 @ : pi *.0j1*@1 // �-. _1 • Date and time 2020.11.24 + !7 // Next 7 days 2020.11.25 2020.11.26 2020.11.27 2020.11.28 2020.11.29 2020.11.30 2020.12.01 15:46 + 15 // Next 15 minutes 16:01 Page 6 ELI Examples - III • A table of temperature conversion (C to F) ELI functions • T = T × 9/5 + 32 (°F) (°C) ! : iota c,[1.5]32+1.8*c<-$_10+5*!10 * : multiplication 40 104 $ : rotate 35 95 <-: assign 30 86 ,[1.5]: laminate 25 77 20 68 15 59 10 50 5 41 0 32 _5 23 (C) (F) Page 7 ELI Examples - IV • List of numbers, symbols, and chars ELI functions (2 3#!6;`ny `ma `md;'ABCDE’) ! : iota <1 2 3 # : reshape 4 5 6 <`ny `ma `md <ABCDE • Dictionary and table D<-(`sym `price `hq:(`appl `ibm `hp `goog;449.1 108.2 24.5 890.3;4 2#'CANYCACA’)) D sym | appl ibm hp goog price| 449.1 108.2 24.5 890.3 hq | 'CANYCACA' Page 8 ELI Examples - V • Dictionary to table ELI functions []<-T<-&.D &.: flip sym price hq ------------- do: written in ELI appl 449.1 CA ibm 108.2 NY hp 24.5 CA goog 890.3 CA • Database query do 'SELECT sym,hq FROM T WHERE price>100’ sym hq ------- appl CA Ibm NY goog CA SELECT successful. Page 9 ELI Symbols • ELI use one or two characters to represent one APL symbol (Unicode) • E.g., using ? to represent the member function (∈ in APL) • The second character usually is dot (.) • E.g., using ?. to represent the random function (? in APL) • In other cases, the second character is intuitive • E.g., using <- to represent the assign function (← in APL) Page 10 APL ELI ELI Symbols (Overview) Source: ELI Homepage https://fastarray.appspot.com Page 11 ELI Tutorials • ELI Primer • A detailed document for learning ELI programming • ELI for kids • A novel way to learn math and coding • Introduction to Programming with Arrays using ELI • Paperback available on Amazon.com Source: https://fastarray.appspot.com/documents.html Page 12 ELI Studio IDE for ELI programming 13 ELI Studio • ELI Studio provides a GUI interface for programming ELI • Interactive programming environment • Write and load ELI scripts conveniently • Manage variables and libraries easily • Cross-platform support • Windows • Linux • Mac OS Source: https://fastarray.appspot.com/download.html Page 14 ELI Studio (v0.3) Page 15 Programming in ELI Studio • Standard input []<-’Please enter your name:’ Please enter your name: []<-’Welcome ‘,[] Welcome hanfeng • File handle h<-[]open ‘file1.txt’ @1 3.141592654 h<<@1 h<<3 5#!15 // 3-by-5 matrix []close h 0 Page 16 ELI Compiler Compile ELI programs 17 ECC: ELI-to-C Compiler • A compiler executable • Modeled on an APL-to-C compiler written in APL (operates under an APL interpreter) • Written in ELI and self-compiled into a binary executable^1 • Support ELI built-in functions derived from APL1 • Homogeneous array types Source Code Target Code Binary (ELI) ECC (C) GCC Library ^1 Hanfeng Chen, Wai-Mee Ching, and Laurie Hendren, An ELI-to-C Compiler: Design, Implementation, and Performance, Proceedings of the 4th ACM SIGPLAN International Workshop of Libraries, Languages and Compilers for Array Programming (ARRAY'17), pp. 9-16, June 2017. Page 18 Benchmark: morgan (I) Main function morgan (n is a scalar and a is a 2-M-N array) [0] @.r<-n morgan a;x;y;sx;sx2;sy;sy2;sxy // function: morgan(n,a) [1] x<-a[1;;] [2] y<-a[2;;] [3] sx<-n msum x // sx = msum(n, x) [4] sy<-n msum y // sy = msum(n, y) [5] sx2<-n msum x *. 2 // sx2 = msum(n, x^2) [6] sy2<-n msum y *. 2 // sy2 = msum(n, y^2) [7] sxy<-n msum x * y // sxy = msum(n, x*y) [8] r<-((sxy%n)-(sx*sy)%n*.2)%(|((sx2%n)+(sx%n)*.2)*.0.5)* (|(sy2%n)-(sy%n)*.2)*.0.5 [9] @. Page 19 Benchmark: morgan (II) Function msum (n is a scalar and a is a two-dim. array) [0] @.r<-n msum a // function: msum(n,a) [1] r<-((0,n-1)!.t)-0,(0,-n)!.t <- +\a // | Part3 | Part2 | Part1| [2] @. In steps, • Let the matrix a have P rows and Q columns 7 • Part 1: +\a computes � � � = ∑6 � � [�], given � ∈ [0, �) and � ∈ 0, � • Part 2: 0,(0,-n)!.t cuts n tailing columns, adds a leading column (all 0s) and returns the matrix M0 • Part 3: (0,n-1)!.t cuts the first n-1 columns and returns the matrix M1 • Finally, the return value r gets M1-M0 Page 20 Compilation • Parameter information for compiling the function morgan • Left parameter: morgan(integer, float) &LPARM C 1 9 ‘morgan IE’ & • Right parameter: starting from 0, morgan(salar, 3-dim) &RPARM I 1 6 0 0 3 _1 _1 _1 & • Save functions and parameters to an ELI script file, called cmain.esf • Run ./ecc cmain to generate a C file, morgan.c Page 21 Conclusions & Future Work 22 Conclusions • ELI is a succinct modern array language derived from APL • ELI inherits the classic APL1 and borrows database features from KDB • ELI provides an interpreter with a GUI-based IDE (ELI Studio) and an compiler executable for flat array programs Page 23 Future Plans Performance enhancement • Build GPU-based library functions for the ELI interpreter • Add optimizations to the ELI compiler • Generate parallel code for both CPUs and GPUs Feature improvement • Extend the current compiler to support database-related features • Add more features into ELI Studio to help ELI programming • Code highlighting / automatic completion / etc. Page 24 Publications • Hanfeng Chen, Wai-Mee Ching, and Laurie Hendren, An ELI-to-C Compiler: Design, Implementation, and Performance, Proceedings of the 4th ACM SIGPLAN International Workshop of Libraries, Languages and Compilers for Array Programming (ARRAY’17), pp. 9-16, June 2017. • Hanfeng Chen and Wai-Mee Ching, A Succinct Programming Language with a Native Database Component, Int'l Jour. of Prog. Lang. and Appl.(IJPLA) vol.7, No.1, Jan.2017. • Hanfeng Chen, Wai-Mee Ching and Da Zheng, A comparison study on execution performance of MATLAB and APL, accepted to Vector J. Br. APL Assoc. • Hanfeng Chen and Wai-Mee Ching, ELI: a simple system for array programming, Vector J. Br. APL Assoc. Vol.26, No.1, p94-102, 2013. • Wai-Mee Ching, The design and implementation of an APL dialect, ELI, Proceedings of the APL-Berlin-2000 Conference, p69-76, July 2000. Source: https://fastarray.appspot.com/documents.html Page 25 Thank you ELI: Programming with Arrays Hanfeng Chen and Wai-Mee Ching https://fastarray.appspot.com.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    27 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us