Whoops!

Yes,  I'd been using I. in a slightly different structure,
with a two-column table of lower and upper bounds on
n for every m,  and had forgotten to change it to (i. <./)
for the vector form with all lower bounds followed by
all upper bounds;  I'd found it slightly less messy,
and (i.<./) is indeed preferable if the solution is unique.

Actually,  though, I think you've shown that I should have
used the floor of the solution for m,  in bestmn,  so that
m would only run to 7,  and n would then stay >: m, ie
   mmax=. <. _0.5 + %:_0.75 + 2*%:req
          NB. round DOWN solution when m=n


The real-valued solution for 1000 clearly lies in the unit
square with diagonal (7,7) (8,8) .

I suppose there might be different m<:n yielding the same
best value, for some targets,  in which case the I. method
should be preferred (together with mmax set to the floor
rather than ceiling).


Somebody had pointed out that this could be considered
as a problem in factoring values close to the target.  A highly
composite number might have the property that it can be
expressed as a(a+1)b(b+1) for more than one pair of a<:b....

bestmn seems to work well enough and much faster
without recourse to extended numbers for "large" targets:

   timer'bestmn <.9.87654321e19'
+--------+------------+
|0.134003|20214 983262|
+--------+------------+

   timer'bestmn 123456789123456789'
+---------+----------+
|0.0219955|7198 97621|
+---------+----------+

One of the PE correspondents was reporting ~45
minutes run-time in Python for one of these!

Thanks again to Raul.

Mike

On 14/10/2014 15:04, Raul Miller wrote:
Your approach looks very sensible. But I am curious about this result,
which is not what I expected:
    bestmn 1e3
7 8 8 7

If I change the second to last line in bestmnv to read
   i =. (i. <./) d

I get
    bestmn 1e3
7 8

Are there cases where this would be a problem?

Thanks,



---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com



-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2014.0.4765 / Virus Database: 4040/8387 - Release Date: 10/14/14

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to