John wrote:
> You can simulate this in J along the lines
> g=:<:@(# - i:&1)@#:
For a cute use of under:
castOut2a =: ({.~ 1+i:&1)&.#:
castOut2a 68
17
And a closer approximation to how it's done at the machien level (using bitwise
operations):
castOut2b =: (_1: 33 b. ])^:(1: 18 b. ])^:_:
castOut2b 68
17
I'm also trying to generalize my original castOut to non-prime LHAs:
castOut =: 2 & $: : (dyad define)&.:(__&q:)
'xp xe' =. x
'yp ye' =. y,.1
ne =. (ye,1) {~ pi =. yp i. xp
yp ,: (xe | ne) pi} ye
)
4 castOut 68
17
But xe | ne isn't quite what I want:
primes =. 3 7x
exps =. 2 5x
factor =. primes */ .^ exps
reps =. factor^2x
big =. */ 2 11 13x , (primes */ .^ exps * 2 0) , reps^2x
result =. factor castOut big
result = big%reps
0
I want to remove powers of (3^2) and (7^5) on a one-to-one basis. I
shouldn't be allowed to remove (e.g.) 3 powers of the former but only 2 powers
of the latter. Could (anti) base provide a solution?
-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm