Case Conversion: Mapping and Folding
Dyalog v18.0 introduced ⎕C, which converts the case of characters in an array by mapping to lower case, mapping to upper case, or folding. This superseded an earlier experimental I-beam (819⌶) that could map to lower or upper case but not fold – this I-beam is currently deprecated and will be removed in Dyalog v20.0. […]
Formal Proposal for APL Array Notation – Seeking Feedback
One of the defining features of the APL language is the ability to denote numeric vectors directly through juxtaposition — separating the elements by spaces, as in 0 1 1 2 3 5 8. The notation for character “vectors” is similar to that for “strings” in most other languages, using quotes to denote the start […]
Structural vs. Mathematical "Under"
The APL Farm has recently hosted discussions about the proposed under operator, asking “why Dyalog hasn’t implemented it a long time ago”. I claimed that an important reason was that Roger Hui wasn’t a big fan of the proposed extension known as “structural under”. Stefan Kruger then asked me why that was so. Since Roger […]
Code Golf: Generating Empty Arrays
By: Stefan Kruger Recently, I was looking for a Dyalog problem to pit my wits against, and I asked in the APL Orchard if Adám could make one up: @Adám Any CMCs today? A CMC, if you’re unfamiliar with the APL Orchard, is a Chat Mini Challenge – typically an informal code golf challenge to […]
Towards Improvements to Stencil
Background The stencil operator ⌺ was introduced in Dyalog version 16.0 in 2017. Recently we received some feedback (OK, complaints) that (a) stencil does padding which is unwanted sometimes and needs to be removed from the result and (b) stencil is too slow when it is not supported by special code. First, stencil in cases […]
Ascending and Descending
Lexicographic Ordering Lexicographic ordering is what the APL primitives ⍋ and ⍒ provide: ⎕io←0 ⍝ ⎕io delenda est ⎕rl←7*5 ⍝ to get reproducible random results a←?11 3⍴3 a a ⌷⍨⊂ ⍋a 2 1 0 0 1 0 0 2 2 0 2 2 1 1 1 1 0 0 1 0 0 1 0 1 […]
Dyalog '18 Videos, Week 6
Happy New Year – and Welcome to the 6th week of Dyalog ’18 video releases! If you enjoy geometry, 2019 starts with a couple of real treats; one which builds up to the use of complex numbers just before the end, and another which starts with them and moves on to Quaternions. Alternatively, if you […]
Progressive Index-Of
⎕io=0 is assumed throughout. A recent Forum post motivated investigations into the progressive index-of functions in the FinnAPL Idiom Library: pix ← {((⍴⍺)⍴⍋⍋⍺⍳⍺,⍵) ⍳ ((⍴⍵)⍴⍋⍋⍺⍳⍵,⍺)} ⍝ FinnAPL Idiom 1 pixa ← {((⍋⍺⍳⍺,⍵)⍳⍳⍴⍺) ⍳ ((⍋⍺⍳⍵,⍺)⍳⍳⍴⍵)} ⍝ FinnAPL Idiom 5 In this note, we: explain what is progressive index-of explain why the two functions work investigate the […]
Is it Sorted?
Motivation I have been working on the Dyalog APL quicksort implementation. The following programming puzzle arose in the process of doing the QA for this work. ⍵ is a simple array. Write a function sorted, without using ⍋ or ⍒, such that sorted ⍵ is 1 if ⍵ is sorted in ascending order and 0 […]
Dyadic Grade
⎕io=0 is assumed throughout. The essay talks only about ⍋ but the same ideas apply to ⍒. Background ⍋ has the distinction of being the first (in 1980) APL primitive function defined on major cells: the result orders items of a vector, rows of a matrix, planes of a 3-d array, etc. In the ordering […]
Linear Interpolation
⎕io=0 assumed throughout; works in 1-origin with the obvious modifications. Introduction On Wednesday, a question arrived via Dyalog Support from an intern in Africa: If M is the matrix on the left, use linear interpolation to compute the result on the right. 1 20 1 20 4 80 2 40 6 82 3 60 4 […]
Stencil Lives
⎕io←0 throughout. ⎕io delenda est. Stencil A stencil operator ⌺ is available with Dyalog version 16.0. In brief, stencil is a dyadic operator f⌺s which applies f to (possibly overlapping) rectangles. The size of the rectangle and its movement are controlled by s. For example, enclosing 3-by-3 rectangles with default movements of 1: ⊢ a←4 […]
Stencil Maneuvers
Introduction The e-mail arrived in the early afternoon from Morten, in Finland attending the FinnAPL Forest Seminar. How do I speed this up and impress the Finns? 0 cmpx ‘e←⊃∨/0.2 edges¨r g b’ 6.4E¯1 edges {⍺←0.7 ⋄ 1 1↓¯1 ¯1↓⍺<(|EdgeDetect apply ⍵)÷1⌈(+⌿÷≢),⍵} apply {stencil←⍺ ⋄ {+/,⍵×stencil}⌺(⍴stencil)⊢⍵} EdgeDetect ¯1 ¯1 ¯1 ¯1 8 ¯1 ¯1 ¯1 […]
Calculation v Look-Up
(⎕io←0 and timings are done in Dyalog version 15.0.) Table Look-Up Some functions can be computed faster by table look-up than a more traditional and more conventional calculation. For example: b←?1e6⍴2 cmpx ‘*b’ ‘(*0 1)[b]’ *b → 1.32E¯2 | 0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕ (*0 1)[b] → 1.23E¯3 | -91% ⎕⎕⎕ Some observations about this benchmark: (a) The […]
Beauty and the Beast
Finally, the last accessory I ordered for my Raspberry Pi Zero (that’s the little red thing behind my keyboard) has arrived – an Acer 43″ ET430K monitor. The Zero won’t quite drive this monitor at its maximum resolution of 3840×2160 pixels, but as you can see, you get enough real estate to do real graphics […]
Charting Reaction Times on the Raspberry Pi
Earlier this week I collected some reaction timer data on my Pi using the BBC micro:bit as an input device. I only produced an “ASCII art” chart at the time: times←ReactionTimer.Play times 251 305 294 415 338 298 294 251 378 ReactionTimer.AsciiChart times 425| 400| * 375| * 350+ 325| * 300| […]
micro:bit Reaction Timer in APL on the Pi and BBC micro:bit
I have a bit of a cold today, so I decided that instead of hopping in an icy car and driving to the office in order to spend the day drinking coffee and answering e-mail, I should stay at home, turn up the radiators, make lots of tea (with honey!) and have some fun writing […]
50847534
⎕io←0 throughout. I was re-reading A Mathematician’s Apology before recommending it to Suki Tekverk, our summer intern, and came across a statement that the number of primes less than 1e9 is 50847478 (§14, page 23). The function pco from the dfns workspace does computations on primes; ¯1 pco n is the number of primes less […]
A Memo Operator
Abstract Some functions are simply stated and easily understood as multiply-recursive functions. For example, the Fibonacci numbers are {1≥⍵:⍵ ⋄ (∇ ⍵-2)+∇ ⍵-1}. A drawback of multiple recursion is abysmal performance even for moderate-sized arguments, consequently motivating resorts to circumlocutions. The memo operator addresses the performance problem and restores multiple recursion to the toolkit of […]
I-Beam Mnemonics
I-Beam (⌶) is an operator that takes as its operand a numeric code and derives a function which isn’t really considered to be part of the APL language – for example: something which could be experimental, which might provide access to parts of the interpreter that should only be accessed with care, or may set […]
Shuffle Faster Please!
Andy reported that in the shuffle QA some functions take a long time: m9249 “4½ days so far” rankop 21.5 hours m12466 26.3 hours points 7.2 hours Background: Shuffle QA is an intensification of the normal QA. The suite of over 1800 QA functions is run under shuffle, whereby every getspace (memory allocation) is followed by every APL array […]
Loops, Folds and Tuples
For-loops Given an initial state defined by a number of variables, a for-loop iterates through its argument array modifying the state. A←… ⋄ B←… ⋄ C←… ⍝ initial state :For item :In items ⍝ iterating through array “items” A←A … item ⍝ new value for A depending on item C←C … A … item ⍝ new value for C depending on A and item … ⍝ state updated :EndFor A B C ⍝ […]
Quicksort in APL Revisited
A message in the Forum inquired on sorting strings in APL with a custom comparison function. First, sorting strings without a custom comparison function obtains with a terse expression: {⍵[⍋↑⍵]} ‘syzygy’ ‘boustrophedon’ ‘kakistocracy’ ‘chthonic’ ┌─────────────┬────────┬────────────┬──────┐ │boustrophedon│chthonic│kakistocracy│syzygy│ └─────────────┴────────┴────────────┴──────┘ Sorting strings with a custom comparison function can also be accomplished succinctly by simple modifications to the Quicksort […]
Response to Feedback on Cut, Under and Merge
At Dyalog ’15 John Scholes and I presented proposals for future operators cut, under, and merge. Following the release of the video of this presentation, we received some feedback from a user. Our response to the feedback may be of wider interest. It’s early days yet for cut, under, and merge (they are tentatively planned […]
The Reflex/Commute Operator
The monadic operator ⍨ is defined and modeled as follows: f⍨ ⍵ ←→ ⍵ f ⍵ ⍺ f⍨ ⍵ ←→ ⍵ f ⍺ {⍺←⍵ ⋄ ⍵ ⍺⍺ ⍺} Reflex Some common well-known functions can be written as f⍨ where f is itself a well-known function: +⍨ double ×⍨ square ?⍨ […]
Parallel Programming with Futures/Isolates
Morten Kromberg went right to it with his well-prepared workshop on the prototype features that were introduced in version 14.0 of Dyalog APL. The features are still partly modelled in APL to allow the first wave of users to pass judgement on the design. Throughout the workshop, we were asked for feedback, to ensure that […]
Permutations
I started composing a set of APL exercises in response to a query from a new APL enthusiast who attended Morten’s presentation at Functional Conf, Bangalore, October 2014. The first set of exercise are at a low level of difficulty, followed by another set at an intermediate level. One of the intermediate exercises is: Permutations […]
Type Comments
I’ve taken to commenting the closing brace of my inner dfns with a home-grown type notation pinched from the Functional Programming community: dref←{ ⍝ Value for name ⍵ in dictionary ⍺ names values←⍺ ⍝ dictionary pair (names⍳⊂⍵)⊃values ⍝ value corresponding to name ⍵ } ⍝ :: Value ← Dict ∇ Name I keep changing my […]
In Praise of Magic Functions: Part II
Part I of this post was concerned with the development speed and execution speed of magic functions and should be read before this post. Benefitting from Future and Past Improvements Looking at the magic function for key in Part I, we see that its performance depends on the following APL primitives, listed with information on […]
In Praise of Magic Functions: Part I
A magic function is an APL-coded (dfn) computation in the C source of the interpreter. For example, some cases of ∧.= are coded as MAGIC(“(≢⍺)(↑∘.=↓)⍺⍳⍺⍪⍉⍵”). The rubric “magic function” includes magic functions and magic operators. Acknowledgments. Magic functions in Dyalog are made possible due to work done by John Scholes and Richard Smith. Development Speed […]
Response to Name Colouring for Dfns
This post contains comments to John Scholes’ post on name colouring; please continue to post any further comments with the original post. This is a very interesting topic – as the discussion has already showed, there are many different needs. It seems to me that some of the suggestions that have been made are forms of highlighting […]
Name Colouring for Dfns
APL is sometimes criticised because expressions that include names cannot, in general, be parsed without knowing whether the names represent functions or variables. For example, the name thing in the expression thing⍳3 could reference an array (in which case the ⍳ is dyadic) or it could reference a function (making the ⍳ monadic). An APL […]
A Dialog on APL
A discussion between Nicolas Delcros and Roger Hui Nicolas, Prologue: From a language point of view, thanks to Ken Iverson, it is obvious that you want grade rather than sort as a primitive. Yet from a performance point of view, sort is currently faster than grade. Can one be “more fundamental” than the other? If […]
Do Functions Know Their Own Names?
Going back a long way when John Scholes and I were writing version 0 of Dyalog there was a big discussion about whether functions knew their own names. This discussion still surfaces, with John taking the side that they don’t and me taking the side that they do. Essentially, John would argue that after A←2, […]
Exploring Key
In ⍺ f⌸ ⍵, major cells of ⍺ specify keys for the corresponding major cells of ⍵, and f applies to each unique major cell of ⍺ and the major cells of ⍵ having that key. The monadic case f⌸⍵ is equivalent to ⍵ f⌸ ⍳≢⍵. Key is similar to the GROUP BY clause in […]
Foo, Shmoo
“We do not realize what tremendous power the structure of an habitual language has. It is not an exaggeration to say that it enslaves us through the mechanism of s[emantic] r[eactions] and that the structure which a language exhibits, and impresses upon us unconsciously, is automatically projected upon the world around us.” —Korzybski (1930) in […]
Changes of Heart
Karen Shaw started the ball rolling (hearts afluttering?) by asking Jay Foad to come up with a one-liner for St. Valentine’s Day; he then solicited contributions from the language development group. Nick Nickolov responded with the following, with no explanation other than that there is room for improvement: ⎕io←0 ⋄ (⊢,⌽)’ X'[{(.5×n*2)>+/(⍺-.6×⍵)⍵*2}/¨0↓n-⍳(2×n),n←20] XXXXX XXXXX XXXXXXXXXX […]
Zero-length Regular Expression Matches Considered Harmful
I was asked by a colleague why ⎕S reports two matches in the following example: (‘\d*’⎕S 0 1)’321’ ┌───┬───┐ │0 3│3 0│ └───┴───┘ Here we are asking for the position and length of sequences of zero or more digits in an input document containing three numeric characters. Intuitively there is just one match of all […]
Solving the 2014 APL Problem Solving Competition – Cryptography Problem 3
This post is the continuation of the series where we examine some of the problems selected for the 2014 APL Problem Solving Competition. In this post we’ll conclude looking at the cryptography problems from Phase II that we started looking at in a previous blog post and continued in a further blog post. Cryptography Problem […]
Solving the 2014 APL Problem Solving Competition – Cryptography Problem 2
This post is the continuation of the series where we examine some of the problems selected for the 2014 APL Problem Solving Competition. In this post we’ll continue looking at the cryptography problems from Phase II that we started looking at in a previous blog post. Cryptography Problem 2 – Book Cipher Variation Task 1 […]
Solving the 2014 APL Problem Solving Competition – Cryptography Problem 1
This post is a continuation of the series where we examine some of the problems selected for the 2014 APL Problem Solving Competition. I’ll start by looking at the cryptography problems from Phase II. Cryptography Problem 1 – Vigenère Cipher The cipher is described using a large table of letters, but you don’t need to […]
The Diamond Kata
Acknowledgments Morten Kromberg is the other co-author of this text but the blogging software prevents his being listed as such. We are indebted to Jay Foad, Nick Nikolov, John Scholes, and Fiona Smith for comments on successive drafts of the MS. The Problem The diamond kata is a programming exercise used in the agile development, […]
Cholesky Decomposition
Morten was visiting Dyalog clients and forwarded a request: Can we have the Cholesky decomposition? If A is a Hermitian, positive-definite matrix, its Cholesky decomposition [0] is a lower-triangular matrix L such that A ≡ L +.× +⍉L. The matrix L is a sort of “square root” of the matrix A. For example: ⎕io←0 ⋄ […]
Three-and-a-bit
The most obvious expression for computing π in APL is ○1. But what if you can’t remember how ○ works, or your O key is broken, or you feel like taking the road less travelled? With thanks to Wikipedia’s excellent list of Approximations of π, here are some short sweet APL expressions for three-and-a-bit: 3 ⍝ very short […]
Quicksort in APL
Quicksort is a classic sorting algorithm invented by C.A.R. Hoare in 1961 [0, 1]. It has been known for some time that quicksort has a terse rendition in APL [2]. To get right to it, here is the code: Q←{1≥≢⍵:⍵ ⋄ S←{⍺⌿⍨⍺ ⍺⍺ ⍵} ⋄ ⍵((∇<S)⍪=S⍪(∇>S))⍵⌷⍨?≢⍵} The “pivot” ⍵⌷⍨?≢⍵ is randomly chosen. ((∇<S)⍪=S⍪(∇>S)) is a […]
Ken Iverson's Favourite APL Expression?
What was Ken Iverson’s favourite APL expression? I don’t know that he had one and if he had I don’t know what it was, but if I have to guess … From Sixteen APL Amuse-Bouches: The expression (0,x)+(x,0) or its commute, which generates the next set of binomial coefficients, is present in the document that […]
Musings on Reduction
In one man’s humble opinion, reduction (⌿) is the Queen of Operators. Each (¨) comes a close second, but doesn’t get the cigar because each can be written in terms of reduction. Two special cases are of interest: reduction along axes of length 1 (or reduction of a scalar) and reduction along axes of length […]
Solving the 2014 APL Problem Solving Competition – it's as easy as 1 1 2 3…
The winners of the 2014 APL Problem Solving Competition were recognized at the Dyalog ’14 user meeting and had a chance to share their competition experiences. Emil Bremer Orloff won the student competition and received $2500 USD and an expenses-paid trip to Dyalog ’14, while Iryna Pashenkovska took first place among the non-student entries and received a complimentary […]
A Speed-Up Story
The first e-mail of the work week came from Nicolas Delcros. He wondered whether anything clever can be done with ∘.≡ on enclosed character strings. I immediately thought of using “magic functions“, an implementation technique whereby interpreter facilities are coded as dfns. I thought of magic functions because the APL expressions involved in this case […]
Selective Expression Tracing
Operator trace from dfns.dws is a simple and low-tech tool for displaying intermediate results of functions, during the evaluation of an expression. For example, what’s going on here? (+⌿ ÷ ≢) 1 2 3 4 2.5 We can guess that the above fork is computing the average of the right argument. To see how this works: )copy dfns […]
Data-driven Conditionals
ACKNOWLEDGEMENT: My thanks to Andy Shiers for simplifying the examples Visitors to APL from other languages are sometimes a bit sniffy about our use of numbers (1 0) for Boolean values True and False. They’re further bemused by our fondness for moving conditional processing out of code and into data. For example, instead of: 0=2|⍵: […]
Why Dyalog '14 was a Shear Delight
Recent versions of Microsoft Windows support touch screens, which of course means that applications can respond to events originating from touches. Microsoft calls these events “gestures”. Dyalog decided to add support for gestures to version 14.1 and so projects were planned, designs were designed, code was coded and, at Dyalog ’14 (#Dyalog14), a demonstration was […]
Isolated Mandelbrot Set Explorer
It amazes me that an equation so simple can produce images so beautiful and complex. I was first introduced to the Mandelbrot set by the August 1985 issue of Scientific American. Wikipedia says “The Mandelbrot set is the set of complex numbers ‘c’ for which the sequence ( c , c² + c , (c²+c)² + c , […]
Dancing with the Bots
Last week the ‘bots were busy preparing for the J Language Conference in Toronto, where they made their first public appearance together. Upon returning to Bramley they continued training and we are proud to present the first recording of their new dance: [embedplusvideo height=”400″ width=”584″ editlink=”http://bit.ly/1u6Knob” standard=”http://www.youtube.com/v/oO50UqFBsCw?fs=1&vq=hd720″ vars=”ytid=oO50UqFBsCw&width=584&height=400&start=&stop=&rs=w&hd=1&autoplay=0&react=1&chapters=¬es=” id=”ep3993″ /] The ‘bots are both running […]
Creating Shortcuts (Microsoft Windows)
At Dyalog, a developer not only needs access to all of the readily available editions of the interpreter but also to earlier versions that are no longer officially supported. On my Microsoft Windows Desktop I have a folder that contains a shortcut to my developer builds of all these interpreters. I’ve recently suffered a complete […]
Aligning Diff Output
‘Bots are off limits this week so here is a story from this year’s Iverson College – a fantastic week spent in the company of a wonderful mixture of array and functional language gurus and newbies, all learning from each other. One evening, Dhru Patel presented a problem that he was working on which involved […]
APL-Controlled Robot Performs Death-Defying Stunts Using PiCam
Regular readers will remember my whining about the poor precision of both infra-red and ultrasonic sensors. But today, the Raspberry Pi / Dyalog APL – controlled “DyaBot” was observed driving on a dinner table – where the slightest navigational error could mean a 3-foot plunge and certain death! How can this be? [embedplusvideo height=”400″ width=”584″ editlink=”http://bit.ly/19azC9S” […]
PiServer at Thor8.dk
I’ve been wanting to run a Web Server from my home for many years. In fact, I have been paying for the domain Thor8.dk (my street address is Thorsvænget 8), and a fixed IP address for 5 years now – without getting it implemented. But today, with a little help from Jason Rivers who helped […]
APL at work in Africa
My dad is originally from the Cape, and I grew up in Botswana, so hopefully I can be forgiven for feeling that it is very cool to find Dyalog APL at the core of a project which aims to increase financial literacy and support the financial stability of small and medium-sized enterprises in South Africa, […]
Elementary Cellular Light-Emitting Automaton
In response to an earlier post on driving an 8-bar LED using the Raspberry Pi, Roger Hui commented that 8 lights should be sufficient to display the output of a 1-d Game of Life. The code snippets displayed in this post are based on some working code that Roger was also kind enough to forward to me. The […]
Dyalog APL v14.0 Tech Preview
And now, as they say, for something completely different. Our robot is running Dyalog APL version 13.2 for the Raspberry Pi, which was released on our major platforms (Windows, Linux, AIX) in January 2013. The next release of Dyalog APL will be version 14.0, which currently has a tentative delivery date of “sometime in the 1st […]
Dyalog APL now available for the Raspberry Pi!
Although the news had not yet appeared on the Dyalog webpage when this was written, the CTO blog has access to exclusive sources and is therefore able to present this scoop: The big day has finally come – Dyalog APL version 13.2 is now available to anyone with a Raspberry Pi, and can be downloaded […]
Fun with APL on the Raspberry Pi (without a Robot)
The official release of Dyalog APL for the Raspberry Pi now looks as if it going to happen on Friday! In preparation for this, we have been working on some examples to demonstrate things you can do on your Pi without a set of wheels attached – like making lights blink! [embedplusvideo height=”356″ width=”584″ standard=”http://www.youtube.com/v/ztLIQgszE1s?fs=1″ […]