One can find a tacit verb to reproduce the outcome of the expression below
 
   P=:i.4  [   D=:(i.4),(i.3),(i.4),(i.5)
   dot=:+/ .*
   (#P) P&dot\ D
14 8 6 8 5 5 8 14 8 6 8 14 20
 
using brain power as shown earlier in this thread; see the attached messages.  
(The result of my own effort turned out to be almost identical to Aii’s 
solution.)
  
However, one can also use brute force to tacitly generate and apply a 
counterpart of P&dot\ at ‘run time.’  There is an extra complication in this 
case because P&dot\ is operating in dyadic mode and only monadic verbs can be 
‘applied’, but this ‘restriction’ can always be circumvented:
 
   P ((":@[ , '&dot\&>/'"_) 128!:2 #...@[ ; ]) D
14 8 6 8 5 5 8 14 8 6 8 14 20
 
Unfortunately there could be a hefty price to pay in terms of performance if 
the “probe” is a large (as opposed to small) vector:
 
   st=. 7!:2 , 6!:2
   
   P=. 9999?9999
 
   st'P ([ dot"1 #...@[ ]\ ]) D'
198784 0.000213994
   st'P ((":@[ , ''&dot\&>/''"_) 128!:2 #...@[ ; ]) D'
1.13331e6 0.014384
 
What is causing this performance degradation?
 
   a=.128!:2
    
   P=. i.4
   
   v0=. P ((":@[ , '&dot\&>/'"_) ) D
   v0
0 1 2 3&dot\&>/
   P (v0 a #...@[ ; ]) D
14 8 6 8 5 5 8 14 8 6 8 14 20
      
   v1=. 'P&dot\&>/'
   v1
P&dot\&>/
   P (v1 a #...@[ ; ]) D
14 8 6 8 5 5 8 14 8 6 8 14 20
   
   P=. 9999?.9999
 
   v0=. P ((":@[ , '&dot\&>/'"_) ) D
   st'P (v0 a #...@[ ; ]) D'
1.06675e6 0.0137241
      
   v1=. 'P&dot\&>/'
   st'P (v1 a #...@[ ; ]) D'
69568 0.000159797
   
   P ((v0 a #...@[ ; ]) -: (v1 a #...@[ ; ])) D
1
   
   lr=. 5!:5@<
   
   v1
P&dot\&>/
   v2=. P&dot\&>/
   v0 -: lr'v2'
1
 
So, it seems, from the ‘apply’ (128!:2) perspective ‘bonding by name’ could 
be much better than ‘bonding by value’ which might be frustrating to a 
function-level programmer.
 
----------------------------------------------------------------------
 
From: Aai <[email protected]>
To: Programming forum <[email protected]>
Sent: Monday, August 10, 2009 3:19:11 AM
Subject: Re: [Jprogramming] Tacit help needed
AFAICS this produces the same result:
13 :'x dot"1 (#x) ,\y'
-->
  probe ([ dot"1 #...@[ ,\]) data
14 8 6 8 5 5 8 14 8 6 8 14 20

-- 
Met vriendelijke groet,
=@@i
----------------------------------------------------------------------
From: Raul Miller <[email protected]>
To: Programming forum <[email protected]>
Sent: Sunday, August 9, 2009 8:39:43 AM
Subject: Re: [Jprogramming] Tacit help needed
On Sun, Aug 9, 2009 at 7:38 AM, John
Randall<[email protected]> wrote:
> data=:(i.4),(i.3),(i.4),(i.5)
> dot=:+/ .*
> probe=:i.4
>   (#probe) probe&dot\ data
> 14 8 6 8 5 5 8 14 8 6 8 14 20
The problem with a direct conversion to tacit
is that probe&dot\ happens at "compile time"
instead of "run time" -- you are deriving a new
verb each time you run this expression, and
tacit programming uses a fixed set of verbs.
To avoid this issue, you can use box as the
verb for \ and then work from there:
  probe (<@[ dot&> #...@[ <\ ]) data
14 8 6 8 5 5 8 14 8 6 8 14 20
-- 
Raul
----------------------------------------------------------------------
From: John Randall <[email protected]>
To: Programming forum <[email protected]>
Sent: Sunday, August 9, 2009 7:38:11 AM
Subject: [Jprogramming] Tacit help needed
I have a blind spot in making certain forms tacit.
Here is an example, similar to correlation.  I have a small vector
(probe) and I want to calculate its dot product with subarrays of some
data.
data=:(i.4),(i.3),(i.4),(i.5)
dot=:+/ .*
probe=:i.4
  (#probe) probe&dot\ data
14 8 6 8 5 5 8 14 8 6 8 14 20
This is the result I want. I can write an explicit verb
f1=:4 : '(#x) x&dot\ y'
  probe f1 data
14 8 6 8 5 5 8 14 8 6 8 14 20
but I cannot see how to make it tacit.
I can rewrite the tacitly verb using polynomial multiplication to give
essentially the same result:
ppr=:(+//.)@(*/)
f2=:|.@:(ppr |.)
  probe f2 data
0 3 8 14 8 6 8 5 5 8 14 8 6 8 14 20 11 4 0
but I would like to be able to take f1 as is and rewrite it tacitly.

Best wishes,
John
----------------------------------------------------------------------
From: Aai <[email protected]>
To: Programming forum <[email protected]>
Sent: Monday, August 10, 2009 3:19:11 AM
Subject: Re: [Jprogramming] Tacit help needed
AFAICS this produces the same result:
13 :'x dot"1 (#x) ,\y'
-->
probe ([ dot"1 #...@[ ,\]) data
14 8 6 8 5 5 8 14 8 6 8 14 20
 
-- 
Met vriendelijke groet,
=@@i
----------------------------------------------------------------------
From: Raul Miller <[email protected]>
To: Programming forum <[email protected]>
Sent: Sunday, August 9, 2009 8:39:43 AM
Subject: Re: [Jprogramming] Tacit help needed
On Sun, Aug 9, 2009 at 7:38 AM, John
Randall<[email protected]> wrote:
> data=:(i.4),(i.3),(i.4),(i.5)
> dot=:+/ .*
> probe=:i.4
> (#probe) probe&dot\ data
> 14 8 6 8 5 5 8 14 8 6 8 14 20
The problem with a direct conversion to tacit
is that probe&dot\ happens at "compile time"
instead of "run time" -- you are deriving a new
verb each time you run this expression, and
tacit programming uses a fixed set of verbs.
To avoid this issue, you can use box as the
verb for \ and then work from there:
probe (<@[ dot&> #...@[ <\ ]) data
14 8 6 8 5 5 8 14 8 6 8 14 20
-- 
Raul
----------------------------------------------------------------------
From: John Randall <[email protected]>
To: Programming forum <[email protected]>
Sent: Sunday, August 9, 2009 7:38:11 AM
Subject: [Jprogramming] Tacit help needed
I have a blind spot in making certain forms tacit.
Here is an example, similar to correlation. I have a small vector
(probe) and I want to calculate its dot product with subarrays of some
data.
data=:(i.4),(i.3),(i.4),(i.5)
dot=:+/ .*
probe=:i.4
(#probe) probe&dot\ data
14 8 6 8 5 5 8 14 8 6 8 14 20
This is the result I want. I can write an explicit verb
f1=:4 : '(#x) x&dot\ y'
probe f1 data
14 8 6 8 5 5 8 14 8 6 8 14 20
but I cannot see how to make it tacit.
I can rewrite the tacitly verb using polynomial multiplication to give
essentially the same result:
ppr=:(+//.)@(*/)
f2=:|.@:(ppr |.)
probe f2 data
0 3 8 14 8 6 8 5 5 8 14 8 6 8 14 20 11 4 0
but I would like to be able to take f1 as is and rewrite it tacitly.
 
Best wishes,
John
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to