I wrote:
> If we restrict the range of p.^:_1 it may not systematic
> useful, but an error is systematically useless.
Raul wrote:
> However, once you have committed to a non-error case you
> can run into issues if you later on decide that some
> conflicting non-error case would have been better.
Correct. But the point is, in this case, there really aren't any candidates
for "something better". All answers are equally arbitrary.
Given that, here's how I would select my root:
pInv =. ((-~ {.) p.@, [EMAIL PROTECTED])~
NB. polynomial inverse
normalest =. \: (0 = {:@+.) ,. (=<.) ,. (0 <: [EMAIL PROTECTED])
,. -@| NB. "intuitive" selection of root
pI =: [EMAIL PROTECTED]@>@{:@pInv f.
NB. p.^:_1
That is, I prefer real to complex, whole to fractional, nonnegative to
negative, and smaller to larger (closer to zero).
Here's an example of how that gives "the expected" result. For scalar x the
expression x #. y is essentially a polynomial evaluated at x .
Concretely, for scalar x , dyad #. is defined as +/(*/\.}.( (($y)$x) , 1 )
) * y . This reduces to +/(x^i.-#y) * y so:
(x #. y) = +/ y * x^i.-#y
Recall the dyad p. is defined thus:
(x p. y) = +/ x * y^i. #x
There are only two differences in these expressions: the arguments are
switched (which we can reconcile using ~ ) and the list of powers is reversed
(which we can reconcile using |. ).
Therefore x #. y is x p.~ |. y for scalar x and non-scalar (rather,
non-singleton) y . Knowing this, we could leverage p.^:_1 as defined above
to answer the following question [1]:
Given a number x and a list of digits y , where x is equivalent to
the digits y evaluated in base b , determine b .
Equivalently: given x and y where x =. b #. y , produce b .
For example:
x =. 47822
y =. 11 10 12 14
b =. x pI~ |. y NB. Find secret base
x = b #. y NB. Were we on target?
1
b
16
Or, we can use polynomial inverse to find the base "hidden" in the
implementation of monad #. :
(|. pI #.) 14 ?. 1e6 NB. Any non-singleton input
2
My root-selection function is as arbitrary as any other, yet it was easy to
find an application. I really don't think anyone will find an application for
the current domain error.
-Dan
[1] There is an analogous puzzle with ^ substituted for #. .
In the expression z =. x ^ y , given any 2 nouns, we can produce the
third using only inverses:
z = x ^ y
y = x&^ ^:_1 z NB. y = x ^. z
x = ^ &y ^:_1 z NB. x = y %: z
But with z =. x #. y we only have the left inverse, not the right
inverse:
z = x #. y
y = x&#. ^:_1 z NB. y = z #:~ x $~ $z
x = #.&y ^:_1 z NB. Domain error. Should be z p.^:_1~ |.
y .
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm