FinnAPL idiom library: Difference between revisions

Jump to navigation Jump to search
1,460 bytes added ,  06:10, 14 August 2020
m
Miraheze>Adám Brudzewsky
(^ to ∧)
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[File:FinnAPL.jpg|thumb|The original FinnAPL idiom library]]
[[File:FinnAPL.jpg|thumb|The original FinnAPL idiom library]]


The '''[[FinnAPL]] idiom library''' is a very valuable resource for APL programmers. It contains a collection of over 700 one-line APL idioms to achieve a large variety of tasks. It was first presented at the 1984 [[APL conference]] in Helsinki, Finland. The huge contribution of the Finnish APL Association is gratefully acknowledged.
The '''[[FinnAPL]] idiom library''' contains a collection of over 700 one-line APL idioms to accomplish a large variety of tasks. It was first presented at the 1984 [[APL conference]] in Helsinki, Finland. The huge contribution of the Finnish APL Association is gratefully acknowledged.  


This listing mainly suffers from two issues:
This listing mainly suffers from two issues:
* Due to its age, it don't make use of modern APL features which can provide a simpler solution. (However, simple-looking expression which uses [[nested arrays]] can be much more computationally expensive than a longer, more involved solution which only uses simple arrays.)
* Due to its age, it doesn't make use of modern APL features which can provide a simpler solution. (However, a simple-looking expression which uses [[nested arrays]] might be far more computationally expensive than a longer, more involved solution which only uses simple arrays.)
* It can be hard to find what one is looking for, both because computing terminology has changed, and because pinpointing the exact term can be difficult.
* It can be hard to find what one is looking for, both because computing terminology has changed, and because pinpointing the exact term can be difficult.  


[[APLcart]] includes all of the below library, updated to use the latest language features, and in an easily searchable format that includes modern day synonyms.
[[APLcart]] includes all of the below library, updated to use the latest language features, and in an easily searchable format that includes modern day synonyms.
Line 198: Line 198:
|colspan=2 style="background-color: #F5F5F5"|<source lang=apl inline>(X,'*')[(⎕IO+⍴X)⌊⍋(⍳⍴X),(Y×⍴G)⍴G]</source>
|colspan=2 style="background-color: #F5F5F5"|<source lang=apl inline>(X,'*')[(⎕IO+⍴X)⌊⍋(⍳⍴X),(Y×⍴G)⍴G]</source>
|- style="background-color: #FFFFFF"
|- style="background-color: #FFFFFF"
|rowspan=2| 36. || Median ||style="text-align: right;"|<source lang=apl inline>X←D1</source>
|rowspan=2| 36. || Median<ref>Note: it doesn't average the middle two elements as per median's definition. A more correct idiomatic expression is <source lang=apl inline>0.5×+/X[(⍋X)[|⌈¯0.5 0.5×1+⍴X]]</source></ref> ||style="text-align: right;"|<source lang=apl inline>X←D1</source>
|- style="background-color: #FFFFFF"
|- style="background-color: #FFFFFF"
|colspan=2 style="background-color: #FFFFFF"|<source lang=apl inline>X[(⍋X)[⌈.5×⍴X]]</source>
|colspan=2 style="background-color: #FFFFFF"|<source lang=apl inline>X[(⍋X)[⌈.5×⍴X]]</source>
Line 1,407: Line 1,407:
|}
|}


=== Scan ⌈\ ⌊\ ×\ -\ ===
=== Scan <source lang=apl inline>⌈\</source> <source lang=apl inline>⌊\</source> <source lang=apl inline>×\</source> <source lang=apl inline>-\</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|338. || Groups of ones in Y pointed to by X (or trailing parts) ||style="text-align: right;"|<source lang=apl inline>X←B; Y←B</source>
|rowspan=2|338. || Groups of ones in Y pointed to by X (or trailing parts) ||style="text-align: right;"|<source lang=apl inline>X←B; Y←B</source>
Line 1,434: Line 1,434:
|}
|}


=== Scan ⍲\ <\ ≤\ ≠\ ===
=== Scan <source lang=apl inline>⍲\</source> <source lang=apl inline><\</source> <source lang=apl inline>≤\</source> <source lang=apl inline>≠\</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|346. || Value of saddle point ||style="text-align: right;"|<source lang=apl inline>X←D2</source>
|rowspan=2|346. || Value of saddle point ||style="text-align: right;"|<source lang=apl inline>X←D2</source>
Line 1,485: Line 1,485:
|}
|}


=== Scan ∨\ ∧\ ===
=== Scan <source lang=apl inline>∨\</source> <source lang=apl inline>∧\</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|360. || Removing leading and trailing blanks ||style="text-align: right;"|<source lang=apl inline>X←C1</source>
|rowspan=2|360. || Removing leading and trailing blanks ||style="text-align: right;"|<source lang=apl inline>X←C1</source>
Line 1,552: Line 1,552:
|}
|}


=== Scan +\ ===
=== Scan <source lang=apl inline>+\</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|378. || Vector (<source lang=apl inline>X[1]⍴1),(Y[1]⍴0),(X[2]⍴1),...</source> ||style="text-align: right;"|<source lang=apl inline>X←I1; Y←I1</source>
|rowspan=2|378. || Vector (<source lang=apl inline>X[1]⍴1),(Y[1]⍴0),(X[2]⍴1),...</source> ||style="text-align: right;"|<source lang=apl inline>X←I1; Y←I1</source>
Line 1,683: Line 1,683:
|}
|}


=== Reduction ○/ ÷/ -/ ×/ ===
=== Reduction <source lang=apl inline>○/</source> <source lang=apl inline>÷/</source> <source lang=apl inline>-/</source> <source lang=apl inline>×/</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|411. || Complementary angle (arccos sin X) ||style="text-align: right;"|<source lang=apl inline>X←D0</source>
|rowspan=2|411. || Complementary angle (arccos sin X) ||style="text-align: right;"|<source lang=apl inline>X←D0</source>
Line 1,742: Line 1,742:
|}
|}


=== Reduction ⌈/ ⌊/ ===
=== Reduction <source lang=apl inline>⌈/</source> <source lang=apl inline>⌊/</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|425. || Test if all elements of vector X are equal ||style="text-align: right;"|<source lang=apl inline>X←D1</source>
|rowspan=2|425. || Test if all elements of vector X are equal ||style="text-align: right;"|<source lang=apl inline>X←D1</source>
Line 1,789: Line 1,789:
|}
|}


=== Reduction ∨/ ⍲/ ≠/ ===
=== Reduction <source lang=apl inline>∨/</source> <source lang=apl inline>⍲/</source> <source lang=apl inline>≠/</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|436. || Test if all elements of vector X are equal ||style="text-align: right;"|<source lang=apl inline>X←B1</source>
|rowspan=2|436. || Test if all elements of vector X are equal ||style="text-align: right;"|<source lang=apl inline>X←B1</source>
Line 1,836: Line 1,836:
|}
|}


=== Reduction ∧/ ===
=== Reduction <source lang=apl inline>∧/</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|447. || Number of areas intersecting areas in X ||style="text-align: right;"|<source lang=apl inline>X←D3 (n × 2 × dim)</source>
|rowspan=2|447. || Number of areas intersecting areas in X ||style="text-align: right;"|<source lang=apl inline>X←D3 (n × 2 × dim)</source>
Line 1,899: Line 1,899:
|}
|}


=== Reduction +/ ===
=== Reduction <source lang=apl inline>+/</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|462. || Standard deviation of X ||style="text-align: right;"|<source lang=apl inline>X←D1</source>
|rowspan=2|462. || Standard deviation of X ||style="text-align: right;"|<source lang=apl inline>X←D1</source>
Line 1,966: Line 1,966:
|}
|}


=== Reverse ⌽ <source lang=apl inline>⊖</source> ===
=== Reverse <source lang=apl inline></source> <source lang=apl inline>⊖</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|478. || Scan from end with function <source lang=apl inline>⍺</source> ||style="text-align: right;"|<source lang=apl inline>X←A</source>
|rowspan=2|478. || Scan from end with function <source lang=apl inline>⍺</source> ||style="text-align: right;"|<source lang=apl inline>X←A</source>
Line 2,005: Line 2,005:
|}
|}


=== Rotate ⌽ <source lang=apl inline>⊖</source> ===
=== Rotate <source lang=apl inline></source> <source lang=apl inline>⊖</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|488. || Vector (cross) product of vectors ||style="text-align: right;"|<source lang=apl inline>X←D; Y←D</source>
|rowspan=2|488. || Vector (cross) product of vectors ||style="text-align: right;"|<source lang=apl inline>X←D; Y←D</source>
Line 2,019: Line 2,019:
|colspan=2 style="background-color: #F5F5F5"|<source lang=apl inline>(¯1⌽1↓(X≠¯1⌽X),1)/X</source>
|colspan=2 style="background-color: #F5F5F5"|<source lang=apl inline>(¯1⌽1↓(X≠¯1⌽X),1)/X</source>
|- style="background-color: #FFFFFF"
|- style="background-color: #FFFFFF"
|rowspan=2| 491. || An expression giving itself ||style="text-align: right;"|<source lang=apl inline></source>
|rowspan=2| 491. || [[Quine|An expression giving itself]] ||style="text-align: right;"|<source lang=apl inline></source>
|- style="background-color: #FFFFFF"
|- style="background-color: #FFFFFF"
|colspan=2 style="background-color: #FFFFFF"|<source lang=apl inline>1⌽22⍴11⍴'''1⌽22⍴11⍴'''</source>
|colspan=2 style="background-color: #FFFFFF"|<source lang=apl inline>1⌽22⍴11⍴'''1⌽22⍴11⍴'''</source>
Line 2,135: Line 2,135:
|}
|}


=== Maximum ⌈ Minimum <source lang=apl inline>⌊</source> ===
=== Maximum <source lang=apl inline></source> Minimum <source lang=apl inline>⌊</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|520. || Limiting X between Y[1] and Y[2], inclusive ||style="text-align: right;"|<source lang=apl inline>X←D; Y←D1</source>
|rowspan=2|520. || Limiting X between Y[1] and Y[2], inclusive ||style="text-align: right;"|<source lang=apl inline>X←D; Y←D1</source>
Line 2,166: Line 2,166:
|}
|}


=== Ceiling ⌈ Floor <source lang=apl inline>⌊</source> ===
=== Ceiling <source lang=apl inline></source> Floor <source lang=apl inline>⌊</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|527. || Reshaping X into a matrix of width Y ||style="text-align: right;"|<source lang=apl inline>X←D, Y←I0</source>
|rowspan=2|527. || Reshaping X into a matrix of width Y ||style="text-align: right;"|<source lang=apl inline>X←D, Y←I0</source>
Line 2,280: Line 2,280:
|}
|}


=== Magnitude |, Signum <source lang=apl inline>×</source> ===
=== Magnitude <source lang=apl inline>|</source>, Signum <source lang=apl inline>×</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|554. || Increasing absolute value without change of sign ||style="text-align: right;"|<source lang=apl inline>X←D; Y←D</source>
|rowspan=2|554. || Increasing absolute value without change of sign ||style="text-align: right;"|<source lang=apl inline>X←D; Y←D</source>
Line 2,299: Line 2,299:
|}
|}


=== Expand \ <source lang=apl inline>⍀</source> ===
=== Expand <source lang=apl inline>\</source> <source lang=apl inline>⍀</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|558. || Not first zero (≤\) in each subvector of Y indicated by X ||style="text-align: right;"|<source lang=apl inline>X←B1; Y←B1</source>
|rowspan=2|558. || Not first zero (≤\) in each subvector of Y indicated by X ||style="text-align: right;"|<source lang=apl inline>X←B1; Y←B1</source>
Line 2,350: Line 2,350:
|}
|}


=== Compress / <source lang=apl inline>⌿</source> ===
=== Compress <source lang=apl inline>/</source> <source lang=apl inline>⌿</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|570. || Lengths of groups of ones in X ||style="text-align: right;"|<source lang=apl inline>X←B1</source>
|rowspan=2|570. || Lengths of groups of ones in X ||style="text-align: right;"|<source lang=apl inline>X←B1</source>
Line 2,717: Line 2,717:
|}
|}


=== Logical Functions ~ ∨ ∧ ⍱ <source lang=apl inline>⍲</source> ===
=== Logical Functions <source lang=apl inline>~</source> <source lang=apl inline></source> <source lang=apl inline></source> <source lang=apl inline></source> <source lang=apl inline>⍲</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|661. || Demote non-boolean representations to booleans ||style="text-align: right;"|<source lang=apl inline>X←B</source>
|rowspan=2|661. || Demote non-boolean representations to booleans ||style="text-align: right;"|<source lang=apl inline>X←B</source>
Line 2,748: Line 2,748:
|}
|}


=== Comparison <≤> <source lang=apl inline>≠</source> ===
=== Comparison <source lang=apl inline><≤></source> <source lang=apl inline>≠</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|669. || X implies Y ||style="text-align: right;"|<source lang=apl inline>X←B; Y←B</source>
|rowspan=2|669. || X implies Y ||style="text-align: right;"|<source lang=apl inline>X←B; Y←B</source>
Line 2,885: Line 2,885:
|}
|}


=== Indexing [ <source lang=apl inline>]</source> ===
=== Indexing <source lang=apl inline>[ ]</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|702. || Value of fixed-degree polynomial Y at points X ||style="text-align: right;"|<source lang=apl inline>Y←D1; X←D</source>
|rowspan=2|702. || Value of fixed-degree polynomial Y at points X ||style="text-align: right;"|<source lang=apl inline>Y←D1; X←D</source>
Line 2,974: Line 2,974:
|}
|}


=== Arithmetic + - × <source lang=apl inline>÷</source> ===
=== Arithmetic <source lang=apl inline>+</source> <source lang=apl inline>-</source> <source lang=apl inline>×</source> <source lang=apl inline>÷</source> ===
{|class=wikitable style="background-color: #EBEBEB"
{|class=wikitable style="background-color: #EBEBEB"
|rowspan=2|724. || Continued fraction ||style="text-align: right;"|<source lang=apl inline></source>
|rowspan=2|724. || Continued fraction ||style="text-align: right;"|<source lang=apl inline></source>
Line 3,039: Line 3,039:
|colspan=2 style="background-color: #FFFFFF"|<source lang=apl inline>⍎⊖⍕⊃⊂|⌊-*+○⌈×÷!⌽⍉⌹~⍴⍋⍒,⍟?⍳0</source>
|colspan=2 style="background-color: #FFFFFF"|<source lang=apl inline>⍎⊖⍕⊃⊂|⌊-*+○⌈×÷!⌽⍉⌹~⍴⍋⍒,⍟?⍳0</source>
|}
|}
== Notes ==
<references/>
[[Category:Lists]][[Category:Publications]]
trusted
69

edits

Navigation menu