Tacit Primes?
13 posts
• Page 1 of 2 • 1, 2
Tacit Primes?
Using this method for finding primes:
primes←
{
(~R∊∘.×⍨R)/R←1↓⍳⍵
}
Is it possible to refactor this as a tacit function?
primes←
{
(~R∊∘.×⍨R)/R←1↓⍳⍵
}
Is it possible to refactor this as a tacit function?
 mwr0707
 Posts: 11
 Joined: Wed Oct 28, 2015 9:49 am
Re: Tacit Primes?
First replace the local assignment of R with an inner dfn:
Then proceed with stepwise transformations:
where:
A is a constant arrayvalued expression (not containing an ⍺ or ⍵)
X, Y are arrayvalued expressions containing ⍺s or ⍵s
f is a functionvalued expression
The only tricky transformation is for /, which is a function/operator hybrid in Dyalog, so X/Y ~→ ({X}/{Y}). Instead, use:
There are several optimisations, which reduce the size of the final "compiled" tacit function. Here's an example:
{(~R∊∘.×⍨R)/R←1↓⍳⍵} → {(~⍵∊∘.×⍨⍵)/⍵}1↓⍳⍵}
Then proceed with stepwise transformations:
{A f Y} → ( A f{Y}) ⍝ dfn → Aghfork
{X f Y} → ({X}f{Y}) ⍝ dfn → fghfork
{ f Y} → ( f{Y}) ⍝ dfn → ghatop
{⍺} → ⊣ ⍝ dfn → primitive fn
{⍵} → ⊢ ⍝ dfn → primitive fn
where:
A is a constant arrayvalued expression (not containing an ⍺ or ⍵)
X, Y are arrayvalued expressions containing ⍺s or ⍵s
f is a functionvalued expression
The only tricky transformation is for /, which is a function/operator hybrid in Dyalog, so X/Y ~→ ({X}/{Y}). Instead, use:
{X/Y} → ({X}(/∘⊢){Y})
There are several optimisations, which reduce the size of the final "compiled" tacit function. Here's an example:
{X f g Y} → {X f∘(g) Y}
{ f g Y} → { f∘(g) Y}
 JohnSDyalog
Re: Tacit Primes?
So for your specific example:
{(~R∊∘.×⍨R)/R←1↓⍳⍵} ⍝ local var → inner dfn
→ {{(~⍵∊∘.×⍨⍵)/⍵}1↓⍳⍵} ⍝ { f Y} → (f {Y}) ⍝ atop
→ ({(~⍵∊∘.×⍨⍵)/⍵}{1↓⍳⍵}) ⍝ (A f Y} → (A f {Y}), {⍵} → ⊢, f⊢ → f
→ ({(~⍵∊∘.×⍨⍵)/⍵}(1↓⍳)) ⍝ {X / Y} → ({X}(/∘⊢){Y})
→ (({~⍵∊∘.×⍨⍵}(/∘⊢){⍵})(1↓⍳)) ⍝ {⍵} → ⊢
→ (({~⍵∊∘.×⍨⍵}(/∘⊢)⊢)(1↓⍳)) ⍝ X f g Y → X f∘(g) Y
→ (({~⍵∊∘(∘.×⍨)⍵}(/∘⊢)⊢)(1↓⍳)) ⍝ Y f Y → f⍨Y ⍝ commute
→ (({~∊∘(∘.×⍨)⍨⍵}(/∘⊢)⊢)(1↓⍳)) ⍝ f g Y → f∘(g) Y
→ (({~∘(∊∘(∘.×⍨)⍨)⍵}(/∘⊢)⊢)(1↓⍳)) ⍝ {f ⍵} → f
→ ((~∘(∊∘(∘.×⍨)⍨)(/∘⊢)⊢)(1↓⍳))
 JohnSDyalog
Re: Tacit Primes?
Thanks John,
I was struggling with how to get the right argument value all the way to the left of the membership function. I hadn't considered the use of the compose operator.
Can we say that by using compose to glue functions together, that we are increasing the leftward "argument throw" of the following commute operator?
I was struggling with how to get the right argument value all the way to the left of the membership function. I hadn't considered the use of the compose operator.
Can we say that by using compose to glue functions together, that we are increasing the leftward "argument throw" of the following commute operator?
 mwr0707
 Posts: 11
 Joined: Wed Oct 28, 2015 9:49 am
Re: Tacit Primes?
Yes, that would be a good description.
Note that commute can also be coded as a fork:
Note that commute can also be coded as a fork:
f⍨ ←→ ⊢f⊣
 JohnSDyalog
Re: Tacit Primes?
And seemingly:
f⍨ ←→ ⊣f⊢
f⍨ ←→ ⊢f⊢
f⍨ ←→ ⊣f⊣
 mwr0707
 Posts: 11
 Joined: Wed Oct 28, 2015 9:49 am
Re: Tacit Primes?
I think ⊢f⊣ has the edge because it handles both monadic and dyadic functions derived from ⍨:
f⍨⍵ ←→ (⊢f⊣)⍵ ←→ ⍵ f ⍵ ⍝ monadic f⍨
⍺f⍨⍵ ←→ ⍺(⊢f⊣)⍵ ←→ ⍵ f ⍺ ⍝ dyadic f⍨
 JohnSDyalog
Re: Tacit Primes?
For what it's worth, I'm collecting some notes on this subject: http://dfns.dyalog.com/n_tacit.htm.
Contributions welcome.
Contributions welcome.
 JohnSDyalog
Re: Tacit Primes?
Please bear with my ignorance, but could you explain the benefits of tacit as opposed to nontacit? Readability? Performance?
I see the Wikipedia entry saying "... It is also the natural style of certain programming languages, including APL and its derivatives ..."  which is attributed to Neville Holmes (I remember him sending many posts to the J forum on this topic).
I see the Wikipedia entry saying "... It is also the natural style of certain programming languages, including APL and its derivatives ..."  which is attributed to Neville Holmes (I remember him sending many posts to the J forum on this topic).
Visit http://apl.dickbowman.com to read more from Dick Bowman

Dick Bowman  Posts: 235
 Joined: Thu Jun 18, 2009 4:55 pm
13 posts
• Page 1 of 2 • 1, 2
Return to Functional Programming
Who is online
Users browsing this forum: No registered users and 0 guests
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group