Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
APL (programming language)
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Prime numbers ==== The following expression finds all [[prime number]]s from 1 to R. In both time and space, the calculation complexity is <math>O(R^2)\,\!</math> (in [[Big O notation]]). <syntaxhighlight lang="apl"> (~RβRβ.ΓR)/Rβ1ββ³R </syntaxhighlight> Executed from right to left, this means: * ''[[Iota]]'' <code>β³</code> creates a vector containing [[integer]]s from <code>1</code> to <code>R</code> (if <code>R= 6</code> at the start of the program, <code>β³R</code> is <code>1 2 3 4 5 6</code>) * ''Drop'' first element of this vector (<code>β</code> function), i.e., <code>1</code>. So <code>1ββ³R</code> is <code>2 3 4 5 6</code> * ''Set'' <code>R</code> to the new vector (<code>β</code>, ''assignment'' primitive), i.e., <code>2 3 4 5 6</code> * The <code>/</code> ''replicate'' operator is dyadic (binary) and the interpreter first evaluates its left argument (fully in parentheses): * Generate ''[[outer product]]'' of <code>R</code> multiplied by <code>R</code>, i.e., a matrix that is the ''[[multiplication table]]'' of R by R (<code>Β°.Γ</code> operator), i.e., {| class="wikitable" style="text-align:right;" |- | 4 | 6 | 8 | 10 | 12 |- | 6 | 9 | 12 | 15 | 18 |- | 8 | 12 | 16 | 20 | 24 |- | 10 | 15 | 20 | 25 | 30 |- | 12 | 18 | 24 | 30 | 36 |} * Build a vector the same length as <code>R</code> with <code>1</code> in each place where the corresponding number in <code>R</code> is in the outer product matrix (<code>β</code>, ''set inclusion'' or ''element of'' or ''[[Epsilon]]'' operator), i.e., <code>0 0 1 0 1</code> * Logically negate (''not'') values in the vector (change zeros to ones and ones to zeros) (<code>βΌ</code>, logical ''not'' or ''[[Tilde]]'' operator), i.e., <code>1 1 0 1 0</code> * Select the items in <code>R</code> for which the corresponding element is <code>1</code> (<code>/</code> ''replicate'' operator), i.e., <code>2 3 5</code> (This assumes the APL origin is 1, i.e., indices start with 1. APL can be set to use 0 as the origin, so that <code>ΞΉ6</code> is <code>0 1 2 3 4 5</code>, which is convenient for some calculations.)
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
APL (programming language)
(section)
Add topic