Outer Product: Difference between revisions

Jump to navigation Jump to search
445 bytes added ,  09:20, 5 September 2021
m
Added prime number example
m (→‎Application: Added tacit version of dedup)
m (Added prime number example)
Line 53: Line 53:
</source>
</source>
''Note: due to [[function-operator overloading]]'', to use [[replicate]] in a [[fork]], we have to use the workaround <source lang=apl inline>/⍨⍨</source>.
''Note: due to [[function-operator overloading]]'', to use [[replicate]] in a [[fork]], we have to use the workaround <source lang=apl inline>/⍨⍨</source>.
Using similar techniques, we can define a function that generate prime numbers by using an outer product of [[Residue]].
<source lang=apl>
    primes ← {x←1↓⍳⍵ ⋄ (2>+⌿0=x∘.|x)/x}
    primes 10
2 3 5 7
      primes 20
2 3 5 7 11 13 17 19
</source> 
Again, using outer product might not yield the fastest solution. There are faster solutions such as [https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes Sieve of Eratosthenes].
24

edits

Navigation menu