Array-oriented Solutions in APL: A Comprehensive Approach
Delve into the world of array-oriented solutions in APL through a series of informative slides and heuristics by Richard Park and R.C. Metzger. Explore concepts like data transformation, value-first approach, shape-first methodology, and more to enhance your problem-solving skills. Discover the power of thinking big and leveraging function listings for efficient coding practices.
Download Presentation
Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
E N D
Presentation Transcript
1 Thinking in APL: Array-oriented Solutions (Part 2) Richard Park
2 Previously Thinking in APL: Array-oriented Solutions Part 1 dyalog.tv/Webinar/?v=myoK22rq1jk
3 Heuristics Metzger, R.C., 1981. APL thinking finding array-oriented solutions. ACM SIGAPL APL Quote Quad, 12(1), pp.212-218.
4 Heuristics Metzger, R.C., 1981. APL thinking finding array-oriented solutions. 1) Value First, Then Shape; 2) Shape First, Then Value; 3) Data Transformation; 4) Loop First; 5) Think Big; 6) Function Listing; 7) Synonym Search.
5 Black Box / Data Transformation b 'l'=t 'hello' t b h e l l o 0 0 1 1 0 e ExpansionVector b 1 1 1 0 1 0 1 e\t hel l o
6 Black Box / Data Transformation h e l l o 0 0 1 1 0 ? 1 1 1 0 1 0 1
7 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 1 z
8 Black Box / Data Transformation h e l l o 0 0 1 1 0 0 0 1 1 1 1 1 z
9 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 z 1
10 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 1
11 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 1
12 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 1 1 0 1 0 1 1
13 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1
14 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1
15 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1
16 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1
17 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 1 0 1 1 1 1 1 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 0 1
18 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 0 1 1
19 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 1 0 1 1 0 1 1 1 1 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 0 1 1 0
20 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 0 1 1 0 0 1 1 0 1 0 1 0 0 1 1 0
21 Black Box / Data Transformation h e l l o 0 0 1 1 0 0 1 0 1 1 0 1 0 0 1
22 Black Box / Data Transformation h e l l o 0 0 1 1 0 0 1 0 1 1 0 1 0 0 1 ? 1 1 1 0 1 0 1
23 Black Box / Data Transformation h e l l o 0 0 1 1 0 0 1 Remove 0 0 1 Remove 0 1 0 Keep 1 0 Keep 0 1 Remove 0 1 1 1 0 1 0 1
24 Black Box / Data Transformation h e l l o 0 0 1 1 0 0 1 Remove 0 0 1 0 1 Remove 0 0 1 1 0 Keep 1 1 1 0 Keep 1 1 0 1 Remove 0 0 1 1 1 1 0 1 0 1
25 Black Box / Data Transformation h e l l o 0 0 1 1 0 0 1 0 1 0 1 0 1 1 0 / 1 1 1 0 1 1 0 1 0 1 1 1 1 0 1 0 1
26 Black Box / Data Transformation h e l l o 0 0 1 1 0 0 1 0 1 0 1 0 1 1 0 1 1 , / 1 0 1 1 0 1 0 1 1 1 1 0 1 0 1
27 Black Box / Data Transformation h e l l o 0 0 1 1 0 0 1 0 1 0 1 0 1 1 1 1 0 , / 1 1 1 0 0 1 0 1 1 1 1 0 1 0 1
28 Black Box / Data Transformation h e l l o 0 0 1 1 0 {(, ,[1.5]1) / 0 1 0 1 1 0 1 0 0 1} 1 1 1 0 1 0 1
29 Black Box / Data Transformation h e l l o 0 0 1 1 0 {(, ,[1.5]1) / (, ,[1.5]~ )} 1 1 1 0 1 0 1
30 Black Box / Data Transformation h e l l o 0 0 1 1 0 {(, ,[1.5]1) / (, ,[1.5]~ )} 1 1 1 0 1 0 1
31 Black Box / Data Transformation h e l l o 0 0 1 1 0 {(, ,[1.5]1)/(, ,[1.5]~ )} (( ,1 ) / ,( ,~)) aplcart.info 1 1 1 0 1 0 1
32 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 1 What is the mapping? 0 1 1 1 0
33 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 1 What is the mapping? 0 1 ~ 1 1 0 ~0 0 1 1 0 1 1 0 0 1
34 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 1 What is the mapping? 0 1 ~ 1 1 0
35 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 1 What is the mapping? 0 1 ~ 1 1 0
36 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 1 What is the mapping? 0 1 ~ 1 1 0 1,~
37 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 1 What is the mapping? 0 1 ~ 1 1 0 1,~ 1, 0 0 1 0 1 0
38 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 1 What is the mapping? 0 1 ~ 1 1 0 1,~ ~0 0 1 1 0 1 1 0 0 1
39 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 1 What is the mapping? 0 1 ~ 1 1 0 1,~ @~~0 0 1 1 0 1 1 0 0 1
40 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 1 What is the mapping? 0 1 ~ 1 1 0 1,~ 1, @~~0 0 1 1 0 1 1 0 0 1
41 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 1 What is the mapping? 0 1 ~ 1 1 0 1,~ 1, @~~0 0 1 1 0 1 1 1 0 1 0 1
42 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 1 What is the mapping? 0 1 ~ 1 1 0 1,~ 1, @~~0 0 1 1 0 1 1 1 0 1 0 1
43 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 1 What is the mapping? 0 1 1 1 0
44 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 1 What is the mapping? 0 1 1 1 1 1 0 2 1 1+0 0 1 1 0 1 1 2 2 1
45 Black Box / Data Transformation h e l l o 0 0 1 1 0 1 1 1 0 1 0 1 What is the mapping? 0 1 1 1 1 1 0 2 1 1 1+0 0 1 1 0 1 1 1 0 1 0 1
46 Loop First r Loop bits;bit [1] r [2] :For bit :In bits [3] r, (bit 1),~bit [4] :EndFor
47 Loop First: How big is the output array? b 'l' = 'hellolo' 0 0 1 1 0 1 0 +/b One 0 per 1 3 b One 1 per element 7 (+/+ )b 10
48 Loop First: How big is the output array? b 0 0 1 1 0 1 0 Input bits 1 2 3 4 5 6 7 p 1 1 1 1 1 1 1 1 1 1 Pre-allocated r 1 1 1 0 1 0 1 1 0 1 Output 1 2 3 4 5 6 7 8 9 10 b 3 4 6 ~r 4 6 9 ( ~r) - ( b) 1 2 3
49 Loop First (where 1s in b) + (integers to sum of b) ( b) + +/b 1 ( ++/)b 1 1 1 1 1 1 1 1 1 1 ( b) + +/b 4 6 9 ~@(( b) + +/b) 1 ( ++/)b 1 1 1 0 1 0 1 1 0 1
50 Performance ]defs Old {(, ,[1.5]1)/, ,[1.5]~ } New ( ,1 ) / , ,~ Cat 1, @~~ Repl 1 0 @~ ~ Take { 1 1+ } Calc {~@(( )+ +/ ) 1 ( ++/) }