Page 1 of 2
Tacit Primes?
Posted: Tue Dec 06, 2016 2:07 am
by mwr0707
Using this method for finding primes:
primes←
{
(~R∊∘.×⍨R)/R←1↓⍳⍵
}
Is it possible to refactor this as a tacit function?
Re: Tacit Primes?
Posted: Tue Dec 06, 2016 10:17 am
by JohnS|Dyalog
First replace the local assignment of R with an inner dfn:
{(~R∊∘.×⍨R)/R←1↓⍳⍵} → {(~⍵∊∘.×⍨⍵)/⍵}1↓⍳⍵}
Then proceed with stepwise transformations:
{A f Y} → ( A f{Y}) ⍝ dfn → Agh-fork
{X f Y} → ({X}f{Y}) ⍝ dfn → fgh-fork
{ f Y} → ( f{Y}) ⍝ dfn → gh-atop
{⍺} → ⊣ ⍝ dfn → primitive fn
{⍵} → ⊢ ⍝ dfn → primitive fn
where:
A is a constant array-valued expression (not containing an ⍺ or ⍵)
X, Y are array-valued expressions containing ⍺s or ⍵s
f is a function-valued 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}
Re: Tacit Primes?
Posted: Tue Dec 06, 2016 11:19 am
by JohnS|Dyalog
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↓⍳))
Re: Tacit Primes?
Posted: Tue Dec 06, 2016 7:20 pm
by mwr0707
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?
Re: Tacit Primes?
Posted: Tue Dec 06, 2016 9:15 pm
by JohnS|Dyalog
Yes, that would be a good description.
Note that commute can also be coded as a fork:
f⍨ ←→ ⊢f⊣
Re: Tacit Primes?
Posted: Thu Dec 08, 2016 12:34 pm
by mwr0707
And seemingly:
f⍨ ←→ ⊣f⊢
f⍨ ←→ ⊢f⊢
f⍨ ←→ ⊣f⊣
Re: Tacit Primes?
Posted: Thu Dec 08, 2016 1:09 pm
by JohnS|Dyalog
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⍨
Re: Tacit Primes?
Posted: Thu Dec 08, 2016 2:18 pm
by mwr0707
2(÷⍨)4
2
2(⊣÷⊣)4
1
2(⊢÷⊣)4
2
I see!
Re: Tacit Primes?
Posted: Fri Dec 09, 2016 7:30 am
by JohnS|Dyalog
For what it's worth, I'm collecting some notes on this subject:
http://dfns.dyalog.com/n_tacit.htm.
Contributions welcome.
Re: Tacit Primes?
Posted: Fri Dec 09, 2016 2:12 pm
by Dick Bowman
Please bear with my ignorance, but could you explain the benefits of tacit as opposed to non-tacit? 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).