my first workaround causes more problems than it fixes for different v
arguments.
another workaround approach would be (needs dyadic version of power2)
power3 =: 2 : 'u^:([: * v"_) ^:([: | v"_)'
power2 =: 2 : ('for_i. v"_ y do. if. 0~: i do. u power3 i y end. end.')
''[ (pD@:('norm ',":@:])) :. (pD@:('inverse ',":@:]))power2 _2 _1 'abc'
inverse abc
inverse inverse abc
inverse abc
''[ (pD@:('norm ',":@:])) :. (pD@:('inverse ',":@:]))power2 _2 _1 0 2 'abc'
inverse abc
inverse inverse abc
inverse abc
norm abc
norm norm abc
the above processes left to right instead of right to left, but
another bug with ^: is in addition to the first wrong 'norm', there is a
missing 'inverse'
''[ (pD@:('norm ',":@:])) :. (pD@:('inverse ',":@:]))^: _2 _1 0 2 'abc'
norm abc
norm abc
norm norm abc
inverse abc
inverse inverse abc
----- Original Message -----
From: 'Pascal Jasmin' via Programming <[email protected]>
To: "[email protected]" <[email protected]>
Cc:
Sent: Tuesday, July 15, 2014 1:18:28 PM
Subject: Re: [Jprogramming] Why does u^:_2 execute u?
bug I think, but a partial workaround
pD =: 1!:2&2
''[(pD@:('norm ',":)) :. (pD@:('inverse ',":))^:_1^:2 'abc'
inverse abc
inverse inverse abc
doesn't help with _1 0 , or _1 _1. Also affects ^:v
''[0 _1 (pD@:('norm ',":@:])) :. (pD@:('inverse ',":@:]))(^:[ ) 'abc'
norm abc
inverse abc
there is also a problem with any multiple argument:
''[ (pD@:('norm ',":@:])) :. (pD@:('inverse ',":@:]))^: 0 1 'abc'
norm abc
norm abc
can be partial fixed with removing 0s when the v argument contains multiple
items :
scalarize =: {.^:((,1) -: $)
power =: 2 : 'u^:(0 (scalarize@:-.~^:(1<#@:]) *) v"_) ^:([: | 0
scalarize@:-.~^:(1<#@:]) v"_)'
''[ (pD@:('norm ',":@:])) :. (pD@:('inverse ',":@:]))power _2 'abc'
inverse abc
inverse inverse abc
''[ (pD@:('norm ',":@:])) :. (pD@:('inverse ',":@:]))power 0 2 'abc'
norm abc
norm norm abc
''[ 0 _2 (pD@:('norm ',":@:])) :. (pD@:('inverse ',":@:]))power [ 'abc'
inverse abc
inverse inverse abc
just _1 _1 remains a problem, but could be fixed with nub.
----- Original Message -----
From: "[email protected]" <[email protected]>
To: [email protected]
Cc:
Sent: Tuesday, July 15, 2014 11:57:26 AM
Subject: [Jprogramming] Why does u^:_2 execute u?
u^:_1 executes the inverse of u, but u&:_2, or any other value
of n containing a negative value, executes u first. I am just wondering why
'' [ (>:@[ smoutput@('+',":)) :. (<:@[ smoutput@('-',":)) ^:(_1) 0
-0
'' [ (>:@[ smoutput@('+',":)) :. (<:@[ smoutput@('-',":)) ^:(_1 0) 0
+0
-0
'' [ (>:@[ smoutput@('+',":)) :. (<:@[ smoutput@('-',":)) ^:(_2) 0
+0
-0
-_1
The +0 lines are the surprise executions of u. The execution seems to mean
business:
[: :. (smoutput@('inverse ',":))^:_1 'abc'
inverse abc
[: :. (smoutput@('inverse ',":))^:_1 _1 'abc'
|domain error
| [: :.(smoutput@('inverse ',":))^:_1 _1'abc'
I just can't imagine what the business might be.
Henry Rich
----------------------------------------------------------------------
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