Cleaning up a bit. And reusing resources gives a small improvement:
mS=: 4 : 0
ny=. #y
ax=. i:<.-: #x
hy=. <.-: ny
xi=: hy + I - ax
xj=: hy + J - ax
p1=. +/ x * xi{y,0$~+/ny<: xi
p2=. +/ x * xj{y,0$~+/ny<: xj
p1*p2
)
NoKPs =: 4 : 0
'I J'=: y
ep=. ((0x&(,+,~)^: (]`1:))*(_1x&*^:(<@(1&+)`(_1x&^)))) x
pa=. 1 1 0 1 1 & (+//.@(*/)) &.>^: (<x+1) <1
(2x^x)%~ +/ ep * > pa mS &.> |. (*1 _1$~#)&.> pa
)
Aai schreef:
> Update:
>
> ah=: 1 1 0 1 1x
> bh=: 1 _1 0 _1 1x
>
> ppr=: +//.@(*/)
>
> mulSqAt=: 4 : 0
> nx=. #x
> ax=. i:<.-: nx
> ay=. <.-: #y
> aymi=. ay + I - ax
> aymj=. ay + J - ax
> nuli=. 0$~+/-.(#y)>aymi
> nulj=. 0$~+/-.(#y)>aymj
> p1=. +/ x * (aymi){y,nuli
> p2=. +/ x * (aymj){y,nulj
> p1*p2
> )
>
> pathstr =: 4 : 0
> 'I J'=: y
> ep=: ((0x&(,+,~)^: (]`1:))*(_1x&*^:(<@(1&+)`(_1x&^)))) x
> tp=: (ah&ppr&.>^: (<x+1) <1) mulSqAt &.> |. bh&ppr&.>^: (<x+1) <1
> (2x^x)%~ +/ ep * > tp
> )
>
> 100 pathstr 4 4
> 2422219241769802380469882122062019059350760968380804461263234408581143863208781993964800
>
> ts '100 pathstr 4 4'
> 0.535013 10054144
>
> Time to speed up things!
>
> =@@i
>
>
> Aai schreef:
>
>> Trying to translate some parts of pathstensor from part IV:
>>
>> The part with 'multinomial' * sign:
>> multinomial [na,nb] * (-1)^nb
>>
>> can be interpreted as:
>>
>> mnpd=: (0&(,+,~)^: (]`1:))*(_1&*^:(<@(1&+)`(_1&^)))
>>
>> (not really a first shot for) emulating mulArray and powers_of:
>>
>> a=: _2]\ _2 1 _1 1 0 0 1 1 2 1
>> b=: _2]\ _2 1 _1 _1 0 0 1 _1 2 1
>>
>> mularr=: [:({...@{.,+/@{:)@|:/.({.,{:)@(+,*)"1"1 _
>>
>> powers_of=: 4 : 0
>> if. 0=y do. 0 1 return. end.
>> if. 1=y do. x return. end.
>> x&mularr^: (y-1) x
>> )
>>
>> Some examples:
>>
>> a powers_of 0
>> 0 1
>> a powers_of 1
>> _2 1
>> _1 1
>> 0 0
>> 1 1
>> 2 1
>> a powers_of 2
>> _4 1
>> _3 2
>> _2 1
>> _1 2
>> 0 4
>> 1 2
>> 2 1
>> 3 2
>> 4 1
>>
>> However they will be way too slow for pathstensor 100 (4,4). So
>> something to chew on.
>>
>> ... still trying to wrap my brain around 'mulSquareAt arr arr (i,j)' and
>> all the other stuff :-)
>>
>>
>>
>> =@@i
>>
>>
>>
>> Tracy Harms schreef:
>>
>>
>>> There is a lot of array-oriented thinking in a series of four blog
>>> posts by Twan van Laarhoven. The ideas include tensor product of rings
>>> and arrays as polynomials. Although his code is in Haskell, some here
>>> may share my interest in what he's written. I won't be surprised if
>>> somebody finds something fun to translate into J, or to do differently
>>> in J.
>>>
>>> Part one is here:
>>> http://twan.home.fmf.nl/blog/haskell/Knight1.details
>>>
>>> The overall blog post series (with all four parts) is here:
>>> http://twan.home.fmf.nl/blog/
>>>
>>> The problem examined is: A knight is placed at the origin of a
>>> chessboard that is infinite in all directions. How many ways are there
>>> for that knight to reach cell (i,j) in exactly n moves?
>>>
>>> --
>>> Tracy
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>
>>>
>>>
>>>
>>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>>
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
>
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm