Re: [Jprogramming] 903-beta-d

2021-02-03 Thread 'Michael Day' via Programming

Thanks.

I've updated to beta-d.
Having had a bit of trouble with crashing on loading errors,  I find that

   load'noname'    NB. just after firing up JQt

correctly reports 'not found: /noname' on the first attempt,

but crashes J903 beta-d on the second attempt.

OK in J902.

This is in Windows 10.

Cheers,

Mike


On 03/02/2021 22:34, Eric Iverson wrote:

903-beta-d is available for windows/linux/macos.

If you already run J903-beta, then upgrade is easy:
load'pacman'
'upgrade'jpkg'' NB. ensure base library and addons are current
'upgrade'jpkg'jengine'

If you have not yet installed J903-beta, time to get started!
https://code.jsoftware.com/wiki/System/Installation/J903

Release notes:
https://code.jsoftware.com/wiki/System/ReleaseNotes/J903

Questions/bug reports/etc. should go to the beta forum.
--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread 'Michael Day' via Programming

I know you're interested in developing encode and decode for Playfair,
but members _might_ like to know that the London Times "Listener" 
crosswords*,

which appear every Saturday,  occasionally employ Playfair codes.

FYI,  I've found these pertinent puzzles in my records:
   4236  4303  4406  4451  4480  4517

IIRC,  the key or codeword is always to be deduced (!),  I always 
doubles up as J,

and codewords are always even-lettered words/phrases,  without digraphs.

Some friends disapprove,  but I've tinkered away on a Dyalog APL 
workspace for many
years to help with anagrams and word-matches,  with many of the sneaky 
variants
that Listener setters employ.  I reworked it as a J script a couple of 
years ago.  The
word-list is built up from various open sources,  topped up quite 
frequently when the
setter includes a word unknown to my list.  A minor problem now is that 
J9 is diverging
from J701 on my iPad,  so I can't include direct definition,  say, as 
that is incompatible with
older versions of J;  I had to replace all my APL direct definitions 
with conventional

verbs for the J script when transcribing them.

Playfair is included in the APL w/s,  but it hasn't been needed so far 
in the J version!


Sorry this has been chat rather than programming,  but might have been 
of some interest


Mike

* http://listenercrossword.com/ includes lists by year,  but not the 
actual crosswords.

I could copy those I've listed,  and many others,  by private message.


On 04/02/2021 04:02, Ric Sherlock wrote:

I need to separate any digraphs in a string, that consist of 2 letters the
same, by inserting an 'X' between them.
_2 ]\ 'THEEQUICKBROWFFOX'
TH
EE
QU
IC
KB
RO
WF
FO
X

'EE' is a digraph that needs an 'X' inserted. Doing so will result in:

TH
EX
EQ
UI
CK
BR
OW
FF
OX

So now we also need to separate the 'FF' digraph.

I want to define a verb "dedouble" that will process a string so:
dedouble 'THEEQUICKBROWFFOX'
THEXEQUICKBROWFXFOX
But:
dedouble 'THEEQUICKBROWFOOX'
THEXEQUICKBROWFOOX

I have implemented a solution at
https://rosettacode.org/wiki/Playfair_cipher#J but am interested in
alternative implementations.
--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Progressive insertion into a string

2021-02-04 Thread 'Michael Day' via Programming

Just before I venture into updating to the correct beta d...

Raul's is elegant, single-pass and pretty spare.  Here's a verbose, 
inelegant,
multi-pass one,  but it seems to work,  except perhaps for the last 
example,

below.

I stuck with _2 which means that with odd length strings an error is thrown
on the last pair which is actually not a pair,  so needs to be catered for.

anyway,  (it should appear on one line):
   dedouble =: dtb@:((] ({.~ , 'X' , }.~) 1 (1 + 2 * i.)~ _2 =/\ ]) {.~ 
>:@#) ::($:@:,&' ')


dtb is delete trailing blanks,  in strings,  I think.

   dedouble^:_'THEEQUICKBROWFFOOX'
THEXEQUICKBROWFXFOOX
   dedouble^:_'THEEQUICKBROWFOOX'
THEXEQUICKBROWFOOX

This next example is a bit unlikely to occur,  but is this what's required?
   dedouble 'THEEQUICKBROWFOOOX'
THEXEQUICKBROWFOOOX

Raul's version doesn't agree with mine here!  Is this result prederred?
   rmdedouble 'THEEQUICKBROWFOOOX'
THEXEQUICKBROWFOOOX

Cheers,

Mike


On 04/02/2021 14:46, Raul Miller wrote:

Ah, I see it now -- I should have looked closer at your digraphs.

Here's a fixed version:

digra=: * 2 | i.@# + +/\
dedouble=: #!.'X'~ 1 j. [: digra #{.}.=}:

(I could not think of a good name for the "compress out splits of
non-digraphs" mechanism.)

The moral of the story here is that numeric calculations can often
replace simple recursive processes. (Because numbers can be defined
recursively.)

I hope this helps,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] 903-beta-d

2021-02-04 Thread 'Michael Day' via Programming

I always forget how to upgrade,  so I usually use my own update verb,
pretty sophisticated,  as you can see:

   update
3 : 0
   load'pacman'
   'upgrade' jpkg 'jengine'
)

This happened:

   update''
upgrade failed - ferase j.dll.old - exit all J sessions and try again

Any thoughts before I do what it says?

Thanks,

Mike


On 04/02/2021 15:31, Eric Iverson wrote:

Setting up a new win10 development/test machine led to an error in building
windows j903-beta-d. Some of the latest changes were not included.

The build has been redone and uploaded. The crash on the second load of
rubbish is fixed.

Get the latest with:

start J903
load'pacman'
'upgrade'jpkg'jengine'

***
Check JVERSION or 9!:14'' to verify that your windows j903-beta-d was built
on Feb 4 and not on Feb 3.


On Wed, Feb 3, 2021 at 6:33 PM 'Michael Day' via Programming <
programm...@jsoftware.com> wrote:


Thanks.

I've updated to beta-d.
Having had a bit of trouble with crashing on loading errors,  I find that

 load'noname'NB. just after firing up JQt

correctly reports 'not found: /noname' on the first attempt,

but crashes J903 beta-d on the second attempt.

OK in J902.

This is in Windows 10.

Cheers,

Mike


On 03/02/2021 22:34, Eric Iverson wrote:

903-beta-d is available for windows/linux/macos.

If you already run J903-beta, then upgrade is easy:
 load'pacman'
 'upgrade'jpkg'' NB. ensure base library and addons are current
 'upgrade'jpkg'jengine'

If you have not yet installed J903-beta, time to get started!
 https://code.jsoftware.com/wiki/System/Installation/J903

Release notes:
 https://code.jsoftware.com/wiki/System/ReleaseNotes/J903

Questions/bug reports/etc. should go to the beta forum.
--
For information about J forums see http://www.jsoftware.com/forums.htm


--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] 903-beta-d

2021-02-04 Thread &#x27;Michael Day&#x27; via Programming
Sorry, Eric.  I don't know if it's a feature of the previously faulty 
Windows version,  but
I tried deleting j.dll.old,  and was told it was in use by JQt, although 
Task Manager showed
no sign of JQt or j.dll!  BUT I was able to change its name (j.dll.older 
) , restarted J 903,

and ran update successfully !

Now I get -
CHECKING OLD DEFINITIONS

   JVERSION
Engine: j903/j64avx2/windows
Beta-d: commercial/2021-02-04T10:15:00
Library: 9.03.01
Qt IDE: 1.9.2/5.12.10(5.12.10)
Platform: Win 64
Installer: J903 install
InstallPath: c:/d/j903-beta
Contact: www.jsoftware.com
   load'rot'
not found: C:/users/mike_/rot
|file name error: script
|   0!:0 y[4!:55<'y'
   load'rot'
not found: C:/users/mike_/rot
|file name error: script
|   0!:0 y[4!:55<'y'
   load'rot'
not found: C:/users/mike_/rot
|file name error: script
|   0!:0 y[4!:55<'y'

so that's ok!

Thanks for the help,

Mike


On 04/02/2021 16:11, Eric Iverson wrote:

Sounds like another J session was in the way. Be sure all J's are closed
and then start j903 and try again.

On Thu, Feb 4, 2021 at 11:08 AM 'Michael Day' via Programming <
programm...@jsoftware.com> wrote:


I always forget how to upgrade,  so I usually use my own update verb,
pretty sophisticated,  as you can see:

 update
3 : 0
 load'pacman'
 'upgrade' jpkg 'jengine'
)

This happened:

 update''
upgrade failed - ferase j.dll.old - exit all J sessions and try again

Any thoughts before I do what it says?

Thanks,

Mike


On 04/02/2021 15:31, Eric Iverson wrote:

Setting up a new win10 development/test machine led to an error in

building

windows j903-beta-d. Some of the latest changes were not included.

The build has been redone and uploaded. The crash on the second load of
rubbish is fixed.

Get the latest with:

start J903
 load'pacman'
 'upgrade'jpkg'jengine'

***
Check JVERSION or 9!:14'' to verify that your windows j903-beta-d was

built

on Feb 4 and not on Feb 3.


On Wed, Feb 3, 2021 at 6:33 PM 'Michael Day' via Programming <
programm...@jsoftware.com> wrote:


Thanks.

I've updated to beta-d.
Having had a bit of trouble with crashing on loading errors,  I find

that

  load'noname'NB. just after firing up JQt

correctly reports 'not found: /noname' on the first attempt,

but crashes J903 beta-d on the second attempt.

OK in J902.

This is in Windows 10.

Cheers,

Mike


On 03/02/2021 22:34, Eric Iverson wrote:

903-beta-d is available for windows/linux/macos.

If you already run J903-beta, then upgrade is easy:
  load'pacman'
  'upgrade'jpkg'' NB. ensure base library and addons are current
  'upgrade'jpkg'jengine'

If you have not yet installed J903-beta, time to get started!
  https://code.jsoftware.com/wiki/System/Installation/J903

Release notes:
  https://code.jsoftware.com/wiki/System/ReleaseNotes/J903

Questions/bug reports/etc. should go to the beta forum.
--
For information about J forums see http://www.jsoftware.com/forums.htm

--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


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


--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


[Jprogramming] Error in addons/math/misc/fermat.ijs

2021-02-04 Thread &#x27;Michael Day&#x27; via Programming
Having a look at the scripts in ~addons/math/misc,  I've just noticed a 
slip in
fermat.ijs - I doubt if it's used much,  though,  which is probably why 
it hasn't
been reported.  Its fellow script,  pollard.ijs,  has a greatly superior 
factoring

algorithm or two.

The optional left argument of the verb fermatfactor specifies the maximum
number of iterations,  but on starting the dyad,  x is immediately 
replaced by

the ceiling of the square root of y.

These few lines will cure the problem,  with a variable name to taste;  
I'm using

X here.

fermatfactor=: 3 : 0
1 fermatfactor y
:
X=. >.@%: x: y   NB. perhaps call it rty for sqrt y
u=. >:+:X
v=. 1
r=. (*:X)-y
NB.  the rest is ok

The problem is there in J902 as well as J903 beta,  and presumably in 
earlier versions too.


Cheers,

Mike

--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Bug in Calculus

2021-02-07 Thread &#x27;Michael Day&#x27; via Programming

For interest,  I had a look at the changes in the script.

I tried both derivatives,  and both failed in different ways:
a)  polynomials using p. :
   (1 2 3 & p. ) deriv 1   NB. result should be 2 6&p.
0&p.
   (0 & p. ) deriv 1  NB. ok!
0&p.

b)   f() ^ h()
   (*: ^ *:) deriv 1
|domain error: deriv_jcalculus_
|   13!:8(3)

After some puzzlement,  I traced the difficulties with each:
a)  line 170
 if. coeffs=. -: '' do. '0&p.' return.
should of course be
 if. coeffs -: '' do. '0&p.' return.

b) I couldn't see what was wrong until I realised that fexp is undefined!
So adding a definition along the lines of the other fops removes the 
error condition.


fexp =: 4 : 0
'((',x,')^(',y,'))'
)

I wouldn't dare try altering the online source code!

Cheers,

Mike

On 05/02/2021 04:34, 'Jon Hough' via Programming wrote:

I wrote a bug report and fix in the source chat a couple of weeks ago. There 
was no response, so I guess I wrote in the wrong chat.

The calculus addon script has one glaring issue, and one small issue with an 
easy fix.

The glaring issue is the inability to differentiate the constant zero function

0&p.

that gives an error.

The fix is here: https://github.com/jsoftware/math_calculus/pull/2

I think this should be fixed asap, as it also causes an error on double 
differentiation of a linear polynomial.

1 2&p.

The other issue is differentiating a general f^g function, which currently 
gives an error, but is easily doable.

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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Error in comment in addons/math/misc/pollard.ijs

2021-02-11 Thread &#x27;Michael Day&#x27; via Programming
Further to my delve in the scripts in ~addons/math/misc,  I've just 
noticed a

misleading comment in pollard.ijs .

The script offers implementations of two Pollard factorisation algorhithms.

The relevant comments are (with a bit of context):
NB. examples:
NB.
NB.    ]x=. (,*/) x: p: 1e7 30101
NB. 179424691 351599 63085541930909
NB.    pollardpm1 {: x
NB. 351599 335

Well - when you actually run it,  this is the result:

  ]x=. (,*/) x: p: 1e7 30101
179424691 351599 63085541930909
  pollardpm1 {: x
179424691 2556

Initially,  I thought this might be a bug,   but no.  The result in the
comment arises from the other function which does pollard rho
factorisation:
   pollardrho {: x
351599 335

Indeed,  we see that x is defined as the product of the factors found by
the two methods.

No doubt this little slip has been around for some years.

I suggest the comments be amended to read:

NB. examples:
NB.
NB.    ]x=. (,*/) x: p: 1e7 30101
NB. 179424691 351599 63085541930909
NB.    pollardpm1 {: x
NB. 179424691 2556
   et seq... (no changes needed)

Cheers,

Mike

--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] k-mediods PAM algo, help with canonical form

2021-02-13 Thread &#x27;Michael Day&#x27; via Programming
I was having a look at the wiki description with a view to trying to do 
my own version
and then comparing with Emir U's code.  But I was stuck wondering about 
the lack of definition
of cost,  as well as what the greedy choice of k points is aiming to 
optimise at the start. The

algorithm is rather sparsely described there.

Anyway,  I thought it _might_ be worth considering using complex 
coordinates,

eg
   cdata =: j./"1 data

Euclidean distance is then eg
   | x1j1 - x0j0

Forgetting that magnitude was simply | ,  I discovered there's a mistake 
in the NuVoc:

this appears near the bottom of
https://code.jsoftware.com/wiki/Vocabulary/jdot#dyadic  :

Related primitives
Real/Imag (+. y), Signum (Unit Circle) (* y), Length/Angle (*. y), 
Magnitude (* y), .


Clearly,  it should read "  Magnitude  (| y), ..."

Faut de mieux,  I came up with this for build,  not knowing what 
greediness was trying

to achieve:
   build =: (3 $: ]) : (]{~ (?#))    NB. choose x of y at random,  x = 
3 by default...


Cheers,

Mike

On 13/02/2021 13:04, Clifford Reiter wrote:

I will take a stab at the euclidean distance matrix verb. I note that your
edist gives the square of the distance.

+/&.:*: 3 4 NB. euclidean length

5

ed=:+/&.:*:@:-"1 NB. euclidean distance

0 0 ed 3 4

5

1 2 ed 4 6

5

ed/~ 1 2,:4 6

0 5

5 0

edist 1 2,:4 6

0 25

25 0

edm=:ed/~ NB. euclidean dist matrix verb


./|,D-*: edm data

8.52651e_14

The same up to roundoff

On Sat, Feb 13, 2021 at 4:54 AM Emir U  wrote:


Hi guys, I'm very new to J (about 6-7 hours experience), I'm coding a
bunch of useful algos for clustering, optimisation and stats to give J a
proper go: this is my first. I (think) I've coded the k-mediods PAM algo as
described here: https://en.wikipedia.org/wiki/K-medoids

I'm trying to tune my intuition as to what this code should look like when
written properly. i.e. in canonical form. I'd be grateful for your
feedback. I've enclosed the code below which is basically the kM_step and
kM functions: the rest is testing code. If you run it it'll generate some
data, cluster it and plot it for you.


NB. UPDATE MEDIODS FROM DATA.
kM_step=: 4 : 0
d=. (x { "1 y)
s=. ([@> (i. <./) each (;/ d )) { x
idx=: I. & (= & s)
d=. { "1 ({ & y)
w=. (i. <./) & (+/%#) & d
; ((w { [) & idx) each x
)

NB. ITERATE UPDATE STEP TO CONVERGENCE.
choose=: 4 : '({~ x ? #) ,y'
kM=: 4 : '(kM_step & y) ^:_ x choose (i. #y)'

NB. CALCULATE PAIRWISE EUCLIDEAN DISTANCE MATRIX.
edist=: 3 : 0
x=. +/ |: y^2
a=. (,.x) +/ .+ (,:x)
b=. y +/ .* (|: y)
a - (2*b)
)

NB. TESTING: GENERATE DATA, FIT & PLOT.
load 'plot'

data=: ?(50 2$0)
data=: data,3+(3*?(50 2$0))
data=: data,5+(4*?(50 2$0))
D=: edist data
M=: (3 kM D) { data

pd 'reset'
pd 'type dot'
pd 'pensize 3.1'
pd 'color gray'
pd ;/ |: data
pd 'show'
pd 'color red'
pd 'pensize 4'
pd ;/ |: M

M

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


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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Strange result when calculating triangular number

2021-02-15 Thread &#x27;Michael Day&#x27; via Programming

Yes,  it does seem to misbehave.
I looked at what happens with @ rather than @:

   t0=: <.@ -:@ (* >:)
   t =: <.@:-:@:(* >:)

   (t0,:t1) 5928745 5928745  NB. compare @ with @:
17575011601885 17575011601885
17575011601886 17575011601886

I thought [: might fix it - but no:
   tbr0=: [: <. [: -: (* >:)"0
   tbr =: [: <. [: -: (* >:)

   (tbr,: t1) 5928745 5928745
17575011601886 17575011601886
17575011601886 17575011601886

They are all ok with scalar input:

   ~. (t, t0, tbr, tbr0) 5928745
17575011601885

Luckily, they're all ok with lists of small input values:

(t0, t, tbr,: t1) 5 5
15 15
15 15
15 15
15 15


So where does the problem arise?  A crude binary search reveals:


#@:~.@:,@:(t0, t, tbr,: t1)@(2&#) 5928744   NB. OK
1
   #@:~.@:,@:(t0, t, tbr,: t1)@(2&#) 5928745  NB. fails here!
2


#@:~.@:,@:(t0, t, tbr,: t1)@(2&#)"0 ] 5928745 + i:3  NB. not exhaustive...
1 1 1 2 2 2 2


   JVERSION
Engine: j903/j64avx2/windows
Beta-d: commercial/2021-02-04T10:15:00
Library: 9.03.01
Qt IDE: 1.9.2/5.12.10(5.12.10)
Platform: Win 64
Installer: J903 install
InstallPath: c:/d/j903-beta
Contact: www.jsoftware.com


BUT -  there's similar behaviour in J902.


A bit worrying - Thanks!


Mike






On 15/02/2021 09:59, Stefan Baumann wrote:

Dear all,
I had an issue when calculating the triangular number with the formula
<.@:-:@:(*

:) in list context. Starting from 5928745 the outcome in list context is

larger than the correct value (additionally calculated with the binomial
coefficient in the first box):

t=: <.@:-:@:(* >:)
((2&!)@:>:; t ;{.@:t@:,~) 5928744
+--+--+--+
|17575005673140|17575005673140|17575005673140|
+--+--+--+
((2&!)@:>:; t ;{.@:t@:,~) 5928745
+--+--+--+
|17575011601885|17575011601885|17575011601886|
+--+--+--+
JVERSION
Engine: j902/j64avx2/windows
Release-a: commercial/2020-12-05T13:36:01
Library: 9.02.08
Platform: Win 64
Installer: J902 install
InstallPath: c:/users/wzhbsn/_/opt/j
Contact: www.jsoftware.com

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




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Strange result when calculating triangular number

2021-02-15 Thread &#x27;Michael Day&#x27; via Programming

Sorry,  slightly careless in drafting - I'll correct the errors inline.
Please discard my earlier post.

On 15/02/2021 13:16, 'Michael Day' via Programming wrote:

Yes, it does seem to misbehave.
I looked at what happens with @ rather than @:

   t0=: <.@ -:@ (* >:)
   t1 =: <.@:-:@:(* >:)

   (t0,:t1) 5928745 5928745  NB. compare @ with @:
17575011601885 17575011601885
17575011601886 17575011601886

I thought [: might fix it - but no:
   tbr0=: [: <. [: -: (* >:)"0
   tbr1 =: [: <. [: -: (* >:)

   (tbr0,: tbr1) 5928745 5928745
17575011601886 17575011601886
17575011601886 17575011601886

They are all ok with scalar input:

   ~. (t0, t1, tbr0, tbr1) 5928745
17575011601885

Luckily, they're all ok with lists of small input values:

(t0, t1, tbr0,: tbr1) 5 5
15 15
15 15
15 15
15 15

So where does the problem arise?  A crude binary search reveals:


#@:~.@:,@:(t0, t1, tbr0,: tbr1)@(2&#) 5928744   NB. OK
1
   #@:~.@:,@:(t0, t1, tbr0,: tbr1)@(2&#) 5928745  NB. fails here!
2


#@:~.@:,@:(t0, t1, tbr0,: tbr1)@(2&#)"0 ] 5928745 + i:3  NB. not 
exhaustive...

1 1 1 2 2 2 2


   JVERSION
Engine: j903/j64avx2/windows
Beta-d: commercial/2021-02-04T10:15:00
Library: 9.03.01
Qt IDE: 1.9.2/5.12.10(5.12.10)
Platform: Win 64
Installer: J903 install
InstallPath: c:/d/j903-beta
Contact: www.jsoftware.com


BUT -  there's similar behaviour in J902.


A bit worrying - Thanks!


Mike






On 15/02/2021 09:59, Stefan Baumann wrote:

Dear all,
I had an issue when calculating the triangular number with the formula
<.@:-:@:(*
:) in list context. Starting from 5928745 the outcome in list 
context is

larger than the correct value (additionally calculated with the binomial
coefficient in the first box):

    t=: <.@:-:@:(* >:)
    ((2&!)@:>:; t ;{.@:t@:,~) 5928744
+--+--+--+
|17575005673140|17575005673140|17575005673140|
+--+--+--+
    ((2&!)@:>:; t ;{.@:t@:,~) 5928745
+--+--+--+
|17575011601885|17575011601885|17575011601886|
+--+--+--+
    JVERSION
Engine: j902/j64avx2/windows
Release-a: commercial/2020-12-05T13:36:01
Library: 9.02.08
Platform: Win 64
Installer: J902 install
InstallPath: c:/users/wzhbsn/_/opt/j
Contact: www.jsoftware.com

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







--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Strange result when calculating tringular number

2021-02-15 Thread &#x27;Michael Day&#x27; via Programming
"Fixed for the next beta" suggests you might have overlooked that this 
problem seems to occur in J9.02 as well.

Apologies if I'm wrong.

Cheers,

Mike

On 15/02/2021 17:16, Henry Rich wrote:

It comes down to this:

    <. 17575011601890. 0  NB. bug!
17575011601891 0
    <. 17575011601890.
17575011601890

When I rewrote >. to allow inplace operation, I forgot that comparison 
tolerance causes trouble when the numbers get big. Singletons follow a 
different path.


Fixed for next beta.  Thanks for the report.

NOTE that tolerant <. gives non-intuitive results on large float values:

   <. 20.6
21

You got a problem with that?  You asked for 'the largest integer 
tolerantly less than or equal to y', didn't you?


Henry Rich

On 2/15/2021 4:59 AM, Stefan Baumann wrote:

Dear all,
I had an issue when calculating the triangular number with the formula
<.@:-:@:(*
:) in list context. Starting from 5928745 the outcome in list 
context is

larger than the correct value (additionally calculated with the binomial
coefficient in the first box):

    t=: <.@:-:@:(* >:)
    ((2&!)@:>:; t ;{.@:t@:,~) 5928744
+--+--+--+
|17575005673140|17575005673140|17575005673140|
+--+--+--+
    ((2&!)@:>:; t ;{.@:t@:,~) 5928745
+--+--+--+
|17575011601885|17575011601885|17575011601886|
+--+--+--+
    JVERSION
Engine: j902/j64avx2/windows
Release-a: commercial/2020-12-05T13:36:01
Library: 9.02.08
Platform: Win 64
Installer: J902 install
InstallPath: c:/users/wzhbsn/_/opt/j
Contact: www.jsoftware.com

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






--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] k-mediods PAM algo, help with canonical form (xash)

2021-02-15 Thread &#x27;Michael Day&#x27; via Programming

Have you decided whether your code does implement the PAM algorithm?
xash suggested it might be doing the Voronoi method.

Thanks,

Mike

On 15/02/2021 18:16, Emir U wrote:

Hey again xash, I've improved the algo some following your example (especially 
the use of ./). It has reduced the algo (at least with random initialisation) 
to 3 lines ...

kM_step=: 4 : 0

vec=. (i. <./) each ;/ x {"1 y

argm=. 4 : '{ & x (i. <./) (+/ (<(
Subject: Re: k-mediods PAM algo, help with canonical form (xash)

Thanks for your comments xash. You're right about average not mattering. Did 
your kM2_step and kM functions run correctly for you? It doesn't look like it 
runs to me so far as I can see the group function seems to assume the data to 
be in the wrong shape for it to work. Can you confirm?
--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


[Jprogramming] Apparent Error in NuVoc

2021-02-16 Thread &#x27;Michael Day&#x27; via Programming
In connection with the recent correspondence on the PAM algorithm for 
k-medoids,

I thought it _might_ be worth considering using complex coordinates,
eg
   cdata =: j./"1 data
so that distance between points is just the magnitude of the difference 
of their complex

representations.

Forgetting that magnitude was simply | ,  I found an apparent mistake in 
the NuVoc:

this appears near the bottom of
*https://code.jsoftware.com/wiki/Vocabulary/jdot#dyadic  :**
**
*

   *Related primitives**
   **Real/Imag (+. y), Signum (Unit Circle) (* y), Length/Angle (*. y),
   Magnitude (* y), .**
   *

*
**Clearly,  it should read "  Magnitude  (| y), ..."**
*
I've just seen there's a page for reporting issues,  but I don't think I 
have an account and
don't intend to make a habit of spotting errors there,  so I hope this 
is ok!


Cheers,

Mike


--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Apparent Error in NuVoc

2021-02-16 Thread &#x27;Michael Day&#x27; via Programming
Point taken!   I looked again,  however, to find that Julian Fondren has 
done

the deed,  for which many thanks!

Next time...

Mike

On 16/02/2021 15:50, Henry Rich wrote:
It's a Wiki.  You should make the change. That is a much better use of 
everyone's time than composing a Forum message and hoping someone will 
pick up on it.


There are lots of errors; you will see them even if you don't plan to 
make a habit of it.  Since you are one of the few who will recognize 
an error when you see one, have an account ready for the occasion.


Henry Rich

On 2/16/2021 4:37 AM, 'Michael Day' via Programming wrote:
In connection with the recent correspondence on the PAM algorithm for 
k-medoids,

I thought it _might_ be worth considering using complex coordinates,
eg
   cdata =: j./"1 data
so that distance between points is just the magnitude of the 
difference of their complex

representations.

Forgetting that magnitude was simply | ,  I found an apparent mistake 
in the NuVoc:

this appears near the bottom of
*https://code.jsoftware.com/wiki/Vocabulary/jdot#dyadic  :**
**
*

   *Related primitives**
   **Real/Imag (+. y), Signum (Unit Circle) (* y), Length/Angle (*. y),
   Magnitude (* y), .**
   *

*
**Clearly,  it should read "  Magnitude  (| y), ..."**
*
I've just seen there's a page for reporting issues,  but I don't 
think I have an account and
don't intend to make a habit of spotting errors there,  so I hope 
this is ok!


Cheers,

Mike








--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] csvedit

2021-02-18 Thread &#x27;Michael Day&#x27; via Programming
I keep too many old versions of J - it turns out I have csvedit.ijs for 
J version 6.02.
It's accompanied by help.html,  and testX.csv,   where X e. ' ' cut '1 
1a 2 3 4 5 6'
as well as the manifest and history.  The script and txt files are dated 
3/Aug/2007,

the csv files 7/Jan/2007  .

I've no idea of dependencies on other scripts,  but am happy to send the 
folder in

a private message,  should you wish to have a look.

Cheers,

Mike

On 18/02/2021 11:07, R.E. Boss wrote:

That's what I'm doing right now.


R.E. Boss


-Original Message-
From: Programming  On Behalf Of bill 
lam
Sent: donderdag 18 februari 2021 11:59
To: Programming forum 
Subject: Re: [Jprogramming] csvedit

I think it is easier to read them as string and then do some post-processing in 
J.

On Thu, Feb 18, 2021 at 6:55 PM R.E. Boss  wrote:


Actually, my question is: I have a comma separated file which contains
numbers with a comma as thousands separator, enclosed between double
quotes (").
How can I read these, without doing a lot of tailor made pre-processing?


R.E. Boss


-Original Message-
From: Programming  On Behalf
Of bill lam
Sent: donderdag 18 februari 2021 11:31
To: Programming forum 
Subject: Re: [Jprogramming] csvedit

I think this addon depends on another grid addon which had been
decommited many years ago.

On Thu, Feb 18, 2021, 6:22 PM R.E. Boss  wrote:


Where has https://code.jsoftware.com/wiki/Addons/tables/csvedit  gone?
I could only find it in \j64-602\addons\tables\csvedit


R.E. Boss

-- 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
--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Interquartile range

2021-02-22 Thread &#x27;Michael Day&#x27; via Programming

Thanks for bringing this to attention.
In https://mathworld.wolfram.com/Quantile.html Eric Weisstein lists 9 
different quantile implementations.


Back in the 90s there was a project to establish a library of stats 
functions in APL. One result was a useful Maximum
Likelihood model workspace,  but it also produced a suite of APL 
functions for distributions,  summary statistics,
etc.  I think Norman Thomson was one of the participants, Adrian Smith, 
not a J-user as gr as I know,  another.


I've had a look at two relevant functions in the latter suite, 
ASL∆PCTILE and ASL∆SEMIIQR .

ASL stood for APL Statistics Library.
These two listings, stripped of header comments,  should be readable in 
some email handlers.


 RES←PCT ASL∆PCTILE DATA;T;B;∆elx;n
[8]    T←T-B←⌊T←0.5+0.01×PCT×n←⍴DATA←DATA[(⍋DATA)]
[9]    RES←(DATA[1⌈B]×1-T)+DATA[n⌊B+1]×T

 RES←ASL∆SEMIIQR DATA;T;B;IND;∆elx
[8]    B←⌊T←0.5+(0.75,0.25)×⍴DATA←DATA[(⍋DATA)]
[9]    RES←(-/(DATA[B]×1-T-B)+DATA[B+1]×T-B)÷2

These are my approximate renderings in a mixture of tacit and explicit J.
The remaining comment line is an attempt to render the result more like
the APL original.  Note that the APL functions used index origin = 1.

NB. larg is required percentile,  rarg is vector of data
aslpct =: 4 : 0
pct =. x
t   =. t - b =. <. t =. 0.5 + 0.01 * pct * n =. # data =. /:~ y
((,-.)t) +/ . * data{~<: (1>.b), n<.>:b
NB. (t, 1-t) +/ . * data{~ _1 + (1>.b), n <. 1 + b  NB. clearer?
)

asliqr =: 3 : 0
tmb =. t - b =. <. t =. 0.5 + 0.75 0.25 * # data =. /:~ y
((,:~-.)tmb) -/@:+/@:* data{~ (,:~<:) b
NB. -/ ((1 - tmb) * data{~ b-1) + tmb * data{~ b  NB. clearer?
)

With a data set, d, of 40 values using ? 10  , I get:

d =: 1 5 0 2 2 7 3 8 3 1 3 8 5 9 2 4 9 3 8 2 8 0 4 3 9 6 3 1 8 2 6 8 1 2 
5 9 4 0 5 0
   (q, q2, q3, iqr, asliqr) d NB. q,q2,q3,iqr from Emir U, xash, Brian 
Schott

5 5 5 5.5 5.5
   (q, q2, q3, iqr, asliqr) }.d  NB. different approaches differ for 
odd and even size.

6 6 6 6 5.75
   (q, q2, q3, iqr, asliqr) }:d
6 6 6 6 5.75

These discrepancies are not necessarily indications of error, bearing in 
mind

Weinsstein's observations.

I used to prefer percentiles which were stable under reversal of sign;  
ie,  I felt it
was useful for the negation of the 25th percentile of -d to be the same 
as the 75th
percentile of +d .   This is a nice property in certain circumstances,  
but not essential

for descriptive stats.

I've tweaked q to qq:
   qq=: 3 : ' (((1+ i. #y) % #y) I. 0.75 0.25) {/:~y'
and observe, fwiw,
   (qq; 25&aslpct, 75&aslpct) d
+---+-+
|7 2|2 7.5|
+---+-+
   -@|.each (qq; 25&aslpct, 75&aslpct) -d
+---+-+
|8 2|2 7.5|
+---+-+

If there's any interest,  I could have a shot at translating more of the 
APL stats library into J -
probably not necessary for distributions,  though some might be missing 
from addons/stats.
I can share lists of functions from both sub-projects,  but they're too 
long for this thread.


Mike


On 21/02/2021 21:19, Emir U wrote:

I couldn't find this in the archive so here is an attempt at a fairly simple 
interquartile range function for those who might be looking for it.

iqr=: 3 : 0

q=: 3 : '-/(((1+ i. #y) % #y) I. 0.75 0.25) {/:~y'

q "1 |: y

)

Pretty certain it can be written much more concisely: just not by me right now 🙂

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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Quora Problem

2021-03-21 Thread &#x27;Michael Day&#x27; via Programming

I see Raul & Bob have replied while I was abed.
SO,  before I look at their replies

Not brute force,  but quite neat:
   <.^(10%3)*^.10
14

For a smaller problem, check with 4^4:
    +/(=<.)^&(%3)>:i.4^4

6


<.^(4%3)*^.4

6


QED?


Cheers,


Mike






On 21/03/2021 02:57, Skip Cave wrote:

How do you solve this problem using J (brute force)
n =. >: i. 1000
p =. n^n
How many p are perfect cubes?




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Quora Problem

2021-03-21 Thread &#x27;Michael Day&#x27; via Programming

AH - neat but wrong problem!  Sorry.
Now for breakfast
M

On 21/03/2021 09:16, 'Michael Day' via Programming wrote:

I see Raul & Bob have replied while I was abed.
SO,  before I look at their replies

Not brute force,  but quite neat:
   <.^(10%3)*^.10
14

For a smaller problem, check with 4^4:
    +/(=<.)^&(%3)>:i.4^4

6


<.^(4%3)*^.4

6


QED?


Cheers,


Mike






On 21/03/2021 02:57, Skip Cave wrote:

How do you solve this problem using J (brute force)
n =. >: i. 1000
p =. n^n
How many p are perfect cubes?







--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Quora Problem

2021-03-21 Thread &#x27;Michael Day&#x27; via Programming
Back on the laptop,  running J903 rather than J701 which crashed on the 
less compendious iPad.
Here's a somewhat speedier version of Bob Theriault's approach.  (I 
wasn't seeking to speed it up,

but it wouldn't complete in reasonable time without a tweak or two.)

rt =: 3 : 0
N  =. y
n  =. >: i. N
NB. +/ @:(*./"1)@:(= <.)@:(3 %~ (* (0 -.~ _&q:))) n NB. RT's Original 
answer for the list up to n^n

+/ @:(3 (0*/"1@:=|) (*{:"2@:(__&q:))) n NB. more space-efficient equivalent
)

I'll repeat the definition of qprob here for convenience:
qprob =: 3 : 0
N   =. y
t1  =. N <.@% 3.   NB. Floor (N % 3)
t2  =. N <.@^ %3   NB. Floor (N ^ 1%3)
t3  =. 3 <.@%~ N <.@^ %3  NB. Floor ( (N ^ 1%3) % 3)
(;~ +/) t1, t2, -t3
)

And here are the comparisons:
   (<@rt, qprob)"0 ] 10 100 1 10 NB. Theriault's and my results
+-+-++
|5    |5    |3 2 0   |   NB. No type 3s <: 10 (added comment!)
+-+-++
|36   |36   |33 4 _1 |
+-+-++
|3347 |3347 | 21 _7  |
+-+-++
|33364|33364|3 46 _15|
+-+-++

Mike



On 21/03/2021 11:25, 'Mike Day' via Programming wrote:

OK...
here’s what I should have sent earlier:
1. The required number includes all nn = n raised to n for which n are 
multiples of 3.
2. It also includes all nn for which n are already powers of 3
3. But we need to avoid double-counting nn for which both 1 & 2 apply.

So:
qprob =: 3 : 0
N   =. y
t1  =. N <.@% 3.   NB. Floor (N % 3)
t2  =. N <.@^ %3  NB. Floor (N ^ 1%3)
t3  =. 3 <.@%~ N <.@^ %3  NB. Floor ( (N ^ 1%3) % 3)
(;~ +/) t1, t2, -t3
)

qprob 1000
+---+-+
|340|333 10 _3|
+---+-+
qprob 1
++--+
|3347| 21 _7|
++--+
qprob 10
+-++
|33364|3 46 _15|
+-++

Consistent with Bob’s results for 1000 and 1.  The iPad’s J session crashed 
checking
his method for 10;  not his fault!

Sorry, this looks crummy on the iPad.

Mike

Sent from my iPad


On 21 Mar 2021, at 08:41, 'robert therriault' via Programming 
 wrote:

n=. >: i. 1000 NB. set up list from 1 to 1000
   _&q: 1000   NB. returns the prime exponents of 1000
3 0 3
   (* _&q:) 1000 NB. returns the prime exponents of 1000^1000
3000 0 3000
   (= <.)@:(3 %~ (* _&q:)) 1000 NB. divides the exponents by 3 then returns 1 
for integer result
1 1 1
   (*./"1)@:(= <.)@:(3 %~ (* _&q:)) 1000 NB. if all exponents are divisible by 
3 then it is a cube
1
   +/ @:(*./"1)@:(= <.)@:(3 %~ (* _&q:)) 1000 NB. sum up the number of cubes - 
returns 1 since 1000^1000 is a cube
1
   +/ @:(*./"1)@:(= <.)@:(3 %~ (* _&q:)) n NB. answer for the list up to n^n
340

as it turns out the 340 are these

17 20 $ >: I. *./"1@:(= <.)@:(3 %~ (* _&q:)) n

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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] String prefixes and tabulation

2021-04-09 Thread &#x27;Michael Day&#x27; via Programming
Just in case it matters,  are you regarding Hello & Jello as distinct 
words here,  or is

space just another character?

If they're separate,  then we need only examine (;: s) or (cut s), 
brackets only to delimit

the J idioms.

Thanks,

Mike

On 09/04/2021 14:48, Emir U wrote:

s=: 'Hello Jello'

Given a string like the above, I need to tabulate the number of occurrences of 
every letter for every prefix of length >=k. I also need to know the length of 
the prefix. So:

   

As an example, prefix length=3, prefix=ell, letter=o, count=2

In my real use case k may be quite large (say 20) and the string may be very 
long. The final form needs to be something I can slice and dice thereafter 
(like perhaps a sparse array). I'd be grateful for any advice as to how to 
tackle this.

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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] String prefixes and tabulation

2021-04-09 Thread &#x27;Michael Day&#x27; via Programming

Thanks - so in this slightly longer,  repetitive string:
<<
    s,' ',s

Hello Jello Hello Jello

>>
'llo Jell' would be a prefix (among several others!) with a count of two?

(I see Julian has posted something which is probably useful...)

Cheers,

Mike

On 09/04/2021 15:12, Emir U wrote:

Hey Mike, many thanks for looking, its all just one string. There are no 
implicit delimiters in the string itself. Emir


Just in case it matters,  are you regarding Hello & Jello as distinct words 
here,  or is space just another character?
If they're separate,  then we need only examine (;: s) or (cut s), brackets 
only to delimit the J idioms.

Thanks,

Mike

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




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] [Jgeneral] interpolation (equidistant re-sampling)

2021-05-07 Thread &#x27;Michael Day&#x27; via Programming
I was pretty sure I'd done something with splines years back,  but 
CTRL-E I "spline" only in my user
folder revealed two relevant scripts.  One was my edited crib from 
~addons/demos/wdplot/plexam.ijs,
the other a copy of what Patrick Harrington posted to the J Forum way 
back in 2004.
The latter starts with triPGA,  "Solve tridiagonal matrix iteratively 
using the Parallel Gauss
Algorithm";  it has a preamble very similar to that for tridgl near the 
top of spline.ijs in the
link Scott gives,  just below here.  That link doesn't obviously 
indicate authorship.  Patrick might

wish to comment;  I see he's still corresponding about matters J.

But Ruda has since commented that he considers that "the data as a whole 
do not follow a
simple trend."  It seems to me that to use mere (my term!) linear 
interpolation is still to
impose some kind of mathematical model.  Anyway,  if the independent 
values are "even quite
random",  you might find that some values are repeated,  in which case I 
suppose you take
the average value at a repeated X value.  Also, what should happen if 
your data points are at,

say,  X =: 0 5 6 8 12 26 ?   (How) should Y(6) and Y(8) both be used?

Thanks,

Mike

On 07/05/2021 12:12, Scott Locklin wrote:

FWIIW there's a splines mini package here:

https://www.astro.umd.edu/~jph/J_page.html

-SL

On Fri, May 7, 2021 at 11:58 AM 'Rudolf Sykora' via Programming <
programm...@jsoftware.com> wrote:


Dear Raul,


thanks for your writing, and also for directing this from the general to
the programming forum, where I probably should have posted it.

On the topic. I am afraid you misunderstood what I meant. The data
as a whole do not follow a simple trend, like lying on a line. they can
be even quite random. The task is to go from

X: 05  6  26
Y: 10 _10 80 100

to, say:

U: 05 10 15 20 25  30NB. Equidistant mesh.
V: 10 _10 84 90 94 99 104NB. Linear interpolation and extrapolation
when needed.
  NB. The numbers with U>5 are rounded here for
readability.
  NB. If U=26 were, by chance, in the mesh,
  NB. the value would be (exactly) 100.

(This is not what the data look like in reality, but as an example it
could suffice.)

Thanks once more!


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


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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Mass amend

2021-05-15 Thread &#x27;Michael Day&#x27; via Programming

Depends what Harvey means by "values",  I suppose.
I assumed he meant scalars.    Otherwise my observation is pretty useless!

Cheers,

Mike


On 15/05/2021 19:01, Joey K Tuttle wrote:

I'm probably wrong, but when I first saw Harvey's request, I thought by amend 
he might be visualizing something like -

(],%:) &.> <"0 ]i. 2 5
+-+-+-+-+---+
|0 0  |1 1  |2 1.414213562|3 1.732050808|4 2|
+-+-+-+-+---+
|5 2.236067977|6 2.449489743|7 2.645751311|8 2.828427125|9 3|
+-+-+-+-+---+

- joey



On 2021May 15, at 02:16, 'Mike Day' via Programming  
wrote:

Sorry... another early send!

You’ve already had some helpful, constructive, replies.  All I’ve got to add is 
to wonder why you’re working with boxed data if your data are as regular as 
your example suggests.

If you really do have m rows of n boxed numeric values,  why not just open it up with 
>  ?   You can do a lot of processing on the whole array.  Box it all up again at the 
end if really necessary with <“0 (boxed scalars) or <“1 (boxed rows)

But perhaps I’ve misunderstood your requirements,

Cheers,

Mike

Sent from my iPad


On 15 May 2021, at 10:08, Mike Day  wrote:



Sent from my iPad


On 15 May 2021, at 04:13, HH PackRat  wrote:

Hello again!

I'm thinking, for example, of a table of boxed data in its transposed
horizontal position that has, say, 3 rows of, say, 1000 *boxed* values
each.  My goal is to amend *all* of the boxed values to their square
roots in one version of what I want to do and *all* of the original
boxed values to their logarithmic equivalents (maybe multiplied by a
constant, say, 100) in a second version .

Using what I know from past answers to my questions, I'm sure I could
use "for" loops with repeated amends to accomplish this, but that
seems to be working against J's efficiency in dealing with large
quantities of data at once.

How can I do such a mass "amend" of entire tables in one fell swoop in
J?  Please show EXPLICIT code rather than tacit code.

Thanks for any and all help!

Harvey
--
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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] possibly heretical proposal : .. as sentence separator ?

2021-07-26 Thread &#x27;Michael Day&#x27; via Programming
APL lives/d with the diamond separator,  which works from left to 
right,  in addition to
left tack and right tack (in Dyalog anyway) which are similar to J's [  
and  ]  .


So this modification might help recruit any APL-ers still averse to or 
unaware of J.


Cheers,

Mike

On 26/07/2021 14:47, Eric Iverson wrote:

Michal,
I slightly favor having a statement separator. Others are violently
opposed. You have started an interesting discussion that might take a while
to pick up steam. Don't give up yet!

There are some complicating issues, such as debug.

On Mon, Jul 26, 2021 at 4:57 AM Michal Wallace 
wrote:


Come on... :) Obviously I know how to write the code I wrote. :D
Yes, I can write the whole thing like this:

puts@']' fgc@9 puts 4 {. s=.1|.s [ fgc@15 puts@'[' goxy xy [ bgc 4 [ fgc 9

I'm just saying it looks backwards and awkward to me.

This thing draws a string on the screen that looks like   [.oOo] in
various colors, and the .oOo part is extracted from a larger string
so it looks like a little indicator that the machine is still doing
something
or waiting for you to do something. (Or rather, this draws one frame of the
animation)

If I were putting that string together without setting the colors and
moving the cursor, i'd write:

echo '[', (s=.1|.s), ']'

But with the color and cursor stuff, I seem to have to break it into
multiple lines, or write it backwards.

In this particular case, what I plan to do instead is write a little
language that lets me set colors
and move the cursor in the natural order, so it's not a big deal... (Maybe
for J, i'll just make a
"left-to-right" verb that operates on gerunds or something...)

But... lately, I've also been working on some parser combinators, and a
small virtual machine.
In all these cases, I have bits and pieces of the code which are more
naturally expressed as
sequences of imperative operations, rather than function compositions, and
I find myself
wanting this same statement separator.

I use K every day at work, and it uses the semicolon for this purpose. I
often find myself wishing K
had forks, and J had statement separators. (and native dictionaries, and a
literal syntax for symbols.. :))

Anyway, I noticed '..' was free now and it seems to have a nice symmetry
with '{{' and '}}'
and I thought it might be a good notation for this.

I don't really expect this proposal to make it into the language (for one
thing, it's not clear to me that
there's an actual process by which language decisions get made), but... I
also didn't expect we'd
ever get anything like {{ and }} (which I've also wanted forever), so I'm
asking.



On Sun, Jul 25, 2021 at 9:45 PM 'robert therriault' via Programming <
programm...@jsoftware.com> wrote:


Hi Michal,

In your first line you are already doing what I would do, which is to use
[ to separate the different results.

goxy xy [ bgc 4 [ fgc 9

You can continue to do that as long as you get the order right and lower
things vertically would precede the upper ones

fgc 15 [ puts '[' [ goxy xy [ bgc 4 [ fgc 9

or perhaps I am misunderstanding what you are trying to do.

Cheers, bob




On Jul 25, 2021, at 17:00, Michal Wallace 

wrote:

I love the new '{{' and '}}' ...

what are the chances we could bring '..' back as a statement separator,

at

least inside these new double curly braces?

Often I have a bunch of really short lines that I would love to just

stick

on one line, like this demo code from the terminal library I'm working

on:

  while. -. keyp'' do.
goxy xy [ bgc 4 [ fgc 9
puts '['
fgc 15
puts 4{. s=.1|.s
fgc 9
puts']'
sleep 150
  end.

I can easily stick these on one line with @ or [: but the code winds up
feeling very backward, so I find myself just using newlines and

wasting a

lot of vertical space on my screen.

One answer here is to make a mini-language for terminal operations

that I

can just pass as a string, but there are other places where I find

myself

wishing I could just write a sequence of expressions (evaluated
right-to-left as usual) but all on one line, and sequence them from

left

to

right... (I use K at work, and this is a pretty natural style)
--
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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] initial version of tangentstorm/j-kvm

2021-07-26 Thread &#x27;Michael Day&#x27; via Programming

Thanks.

Your "readme" file says:
*    Note:*on windows, you need the stock|jconsole.exe|that comes with 
J,/and/you need to run it through the"new" Windows terminal 
.


The ' "new" Windows terminal ' is indeed news to me.  I realise you 
provide a link to " https://github.com/microsoft/terminal ",
but what does that do, how do we use it,  is there a downside?  - is all 
this common knowledge?


Cheers,

Mike

On 26/07/2021 16:38, Michal Wallace wrote:

The initial version of the 'j-kvm' terminal driver is here:

 https://github.com/tangentstorm/j-kvm

It provides keyboard, video, and mouse support for console mode
applications on windows and linux, (and maybe OSX, if anyone with a mac
cares to test it...)

It kind of does what ncurses does (let you make interactive console
applications),
but the API is closer to the old "turbo vision" style from turbo pascal.

There is also a submodule for working with video buffers as arrays and then
rendering them with terminal escape codes, as well as a little framework
for mapping each keypress to its own verb in an event loop.

It's still kind of a work in progress, so suggestions/patches/bug reports
are very welcome.
--
For information about J forums see http://www.jsoftware.com/forums.htm




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] initial version of tangentstorm/j-kvm

2021-07-28 Thread &#x27;Michael Day&#x27; via Programming

Thanks.  I had a look - downloading and installing the "App"

Normally, as you know,  we invoke J-console in Windows by running the 
standard terminal from the shortcut on the Windows desktop.


I don't yet see how to make a shortcut in Windows' desktop to run 
j-console in "WindowsTerminal" :
I've discovered that this command can be used to invoke WindowsTerminal 
in a batch file or  a shortcut:
    explorer.exe 
shell:AppsFolder\Microsoft.WindowsTerminal_8wekyb3d8bbwe!App

but it would be useful to have jconsole start up within WindowsTerminal.
I hope there might be a way of adding C:\\j903-beta\jconsole.cmd as 
an argument to the shell command above.


Meanwhile,  doing it the slow way:  ie
   start WindowsTerminal,  change directory to the J installation, run 
jconsole.cmd,
your first demo worked fine;  however,  the mandelbrot graphic was not 
complete;  the lower half

was corrupted:  I think some lines were lost.

Cheers,

Mike

On 26/07/2021 20:42, Michal Wallace wrote:

Microsoft's console has traditionally been limited to 16 colors. Some time
ago they decided to support a wider range of features that make it work
more like xterm on Linux. It also gives you 24 bit color and multiple
console tabs on the same window.

You can get it for free from the Microsoft store. I believe it requires at
least windows 10:

https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701?rtc=1#activetab=pivot:overviewtab

On Mon, Jul 26, 2021, 2:30 PM 'Michael Day' via Programming <
programm...@jsoftware.com> wrote:


Thanks.

Your "readme" file says:
*Note:*on windows, you need the stock|jconsole.exe|that comes with
J,/and/you need to run it through the"new" Windows terminal
<https://github.com/microsoft/terminal>.

The ' "new" Windows terminal ' is indeed news to me.  I realise you
provide a link to " https://github.com/microsoft/terminal ",
but what does that do, how do we use it,  is there a downside?  - is all
this common knowledge?

Cheers,

Mike

On 26/07/2021 16:38, Michal Wallace wrote:

The initial version of the 'j-kvm' terminal driver is here:

  https://github.com/tangentstorm/j-kvm

It provides keyboard, video, and mouse support for console mode
applications on windows and linux, (and maybe OSX, if anyone with a mac
cares to test it...)

It kind of does what ncurses does (let you make interactive console
applications),
but the API is closer to the old "turbo vision" style from turbo pascal.

There is also a submodule for working with video buffers as arrays and

then

rendering them with terminal escape codes, as well as a little framework
for mapping each keypress to its own verb in an event loop.

It's still kind of a work in progress, so suggestions/patches/bug reports
are very welcome.
--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] initial version of tangentstorm/j-kvm

2021-07-29 Thread &#x27;Michael Day&#x27; via Programming

I agree,  but don't see how to do it.

What I had in mind is creating another J-shortcut, or a batch file, on 
the Windows desktop similar to
the existing one for Jconsole,  the only difference being that it would 
open J-console under
WindowsTerminal rather than the normal terminal window.  But I don't 
know enough about W/T to

see how to do this.

Please forgive me if this is common knowledge!

Thanks,

Mike

On 29/07/2021 02:53, esa.li...@gmail.com wrote:

Hi Mike,

How about making a shortcut for Windows Terminal and making a profile for 
jconsole  there and setting it as default. You can even set a J icon of your 
choice.

Best Regards,

Esa

-Original Message-
From: Programming  On Behalf Of 
'Michael Day' via Programming
Sent: torstai 29. heinäkuuta 2021 0.54
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] initial version of tangentstorm/j-kvm

Thanks.  I had a look - downloading and installing the "App"

Normally, as you know,  we invoke J-console in Windows by running the standard 
terminal from the shortcut on the Windows desktop.

I don't yet see how to make a shortcut in Windows' desktop to run j-console in 
"WindowsTerminal" :
I've discovered that this command can be used to invoke WindowsTerminal in a 
batch file or  a shortcut:
  explorer.exe
shell:AppsFolder\Microsoft.WindowsTerminal_8wekyb3d8bbwe!App
but it would be useful to have jconsole start up within WindowsTerminal.
I hope there might be a way of adding C:\\j903-beta\jconsole.cmd as an 
argument to the shell command above.

Meanwhile,  doing it the slow way:  ie
 start WindowsTerminal,  change directory to the J installation, run 
jconsole.cmd, your first demo worked fine;  however,  the mandelbrot graphic 
was not complete;  the lower half was corrupted:  I think some lines were lost.

Cheers,

Mike

On 26/07/2021 20:42, Michal Wallace wrote:

Microsoft's console has traditionally been limited to 16 colors. Some
time ago they decided to support a wider range of features that make
it work more like xterm on Linux. It also gives you 24 bit color and
multiple console tabs on the same window.

You can get it for free from the Microsoft store. I believe it
requires at least windows 10:

https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701?rtc=1#
activetab=pivot:overviewtab

On Mon, Jul 26, 2021, 2:30 PM 'Michael Day' via Programming <
programm...@jsoftware.com> wrote:


Thanks.

Your "readme" file says:
*Note:*on windows, you need the stock|jconsole.exe|that comes with
J,/and/you need to run it through the"new" Windows terminal
<https://github.com/microsoft/terminal>.

The ' "new" Windows terminal ' is indeed news to me.  I realise you
provide a link to " https://github.com/microsoft/terminal ", but what
does that do, how do we use it,  is there a downside?  - is all this
common knowledge?

Cheers,

Mike

On 26/07/2021 16:38, Michal Wallace wrote:

The initial version of the 'j-kvm' terminal driver is here:

   https://github.com/tangentstorm/j-kvm

It provides keyboard, video, and mouse support for console mode
applications on windows and linux, (and maybe OSX, if anyone with a
mac cares to test it...)

It kind of does what ncurses does (let you make interactive console
applications), but the API is closer to the old "turbo vision" style
from turbo pascal.

There is also a submodule for working with video buffers as arrays
and

then

rendering them with terminal escape codes, as well as a little
framework for mapping each keypress to its own verb in an event loop.

It's still kind of a work in progress, so suggestions/patches/bug
reports are very welcome.

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


--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
-
- For information about J forums see
http://www.jsoftware.com/forums.htm


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


--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
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


Re: [Jprogramming] initial version of tangentstorm/j-kvm

2021-07-29 Thread &#x27;Michael Day&#x27; via Programming
Raul - Many thanks for the insight;  this gives me an idea what the 
gurus are talking about!

It works.
Cheers,
Mike

On 29/07/2021 22:50, Raul Miller wrote:

To make a profile for the current version of windows terminal:

(1) Start Windows Terminal
(2) In the title bar, to the immediate right of the + which will let
you add a new tab is a faint grey V like icon which will give you a
dropdown menu. From that dropdown, select Settings.
(3) On the left side of the Settings window, near the bottom, select
Add a new profile
(4) On the right, select New empty profile

In this profile, I gave

Name: jconsole
Command line: (browse to jconsole.exe for j903)
Starting directory:  (j903 directory)
Icon: ...j903\bin\icons\jgreen.png
Tab title: J

Then save it.

With this, you can start a jconsole session in windows terminal using
right click on the terminal icon.

But you can also go back to the Settings window, and in the Startup
pane at the top is a drop down which lets you select the Default
Profile, if you want that to be J.

I do not know if there's a way to create icons which let you start
windows terminal with anything other than its default behavior.

I hope this helps,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Tacit hook

2021-08-01 Thread &#x27;Michael Day&#x27; via Programming

Thanks,  Bo.

This variation on comb works pretty well,  except it doesn't test for the
empty case, ie x = 0:

NB. these boolean verbs are quicker than multiply and add for this case
twice =: 1 & (32 b.)
or    =: 23 b.

Smpscomb =: 4 : 0
 k=. 2^i.>:d=.y-x
 z=. <"0 k
 for. i.<: x do.
   z=. k or &.> ,&.>/\. twice&.> z
 end.
 #:/:~;z
)

   ts
6!:2 , 7!:2@]
   ts'3 Smps 20'
0.6071034 2.873121e8
   ts'3 Smpscomb 20'
0.0001229 66976
   3 (Smps -: Smpscomb) 20
1

The sort adds a little time and space;  it is only necessary if you 
require the same

ordering as your original example.

Cheers,

Mike

On 01/08/2021 18:31, 'Bo Jacoby' via Programming wrote:

  Thanks to Mike!

comb=: 4 : 0

NB.*comb v combinations of size x from i.y

comb=: 3 : 0

comb~ y

:

k=. i.>:d=. y-x

z=. (d$ ,&.>/\. >:&.> z end.
    3 comb 6



I need to study in order to make it do what I want. I am aware that my 
programming is embarassingly inefficient.
Thanks to Raul!
    2 (((= +/"1) # ]) f) 6 NB. fork, not hook!

I wonder why it is hard to code the hook. It is not important, but it is 
strange.
I am studying the bessel correction. I turns out that the mean of the bessel 
corrected variances of all samples is equal to the bessel corrected variance of 
the population.

    E   =. +/%# NB. mean

    Va =. E@:*:-*:@:E NB. Variance

    Bc =. -.&.:%@#*Va NB. Bessel corrected variance

    S =. =+/"1)#])#&2#:[:i.2&^) #)#] NB. samples

    Bc n=.i.8


6

    E Bc |:4 S n
6

    E Bc |:5 S n
6

    E Bc |:6 S n
6

    E Bc |:7 S n
6

    E Bc |:8 S n
6




 Den søndag den 1. august 2021 16.06.21 CEST skrev 'Mike Day' via Programming 
:
  
  Nice work,  especially persuading 13 : to return a tacit version.

I had reached the same solution as Pascal Jasmin’s,  so not worth a comment in 
itself.

However, it is just about worth pointing out that the filtering approach gets 
expensive for larger values of y;  eg 3 Smps 20 would entail filtering 2^20 
rows to obtain 1140. In that case,  I reckon it’s better to use the 1s indices 
provided by, eg, 3 comb 20 .
comb is in addons/stats/base/combinatorial .

In case it matters!

Mike

Sent from my iPad


On 31 Jul 2021, at 20:48, Raul Miller  wrote:

That's a bit tricky in this case, but it can be done:

First off, the problem:

       13 : '(#~x=+/"1)f y' NB. select row
4 : '(#~x=+/"1)f y'

But we can work around this by giving 13 : a variant expression:

     13 : 't#~x=+/"1 t=.f y'
[ (] #~ [ = [: +/"1 ]) [: f ]

And, in this example, we can turn this into a hook through inspection:
   Smps=: (] #~ [ = [: +/"1 ]) f

This could be simplified further, of course:
   2 ((] #~ (= +/"1)) f) 6
and
   2 (((= +/"1) # ]) f) 6

do the same computation.

I hope this helps,

--
Raul


On Sat, Jul 31, 2021 at 12:43 PM Srdjan Stipic  wrote:

You can use “13 : ‘…’” construct to get tacit verb.

On Sat 31. Jul 2021 at 18:00, 'Pascal Jasmin' via Programming <
programm...@jsoftware.com> wrote:


2 ([ (] #~ [ = +/"1@:]) f@]) 6






On Saturday, July 31, 2021, 11:52:10 a.m. EDT, 'Bo Jacoby' via Programming
 wrote:





Consider this code

   f=.#&2#:[:i.2&^ NB. 0-1 rows




   Smps=. 4 : '(#~x=+/"1)f y' NB. select rows

   2 Smps 6 NB. for example
0 0 0 0 1 1

0 0 0 1 0 1

0 0 0 1 1 0

0 0 1 0 0 1

0 0 1 0 1 0

0 0 1 1 0 0

0 1 0 0 0 1

0 1 0 0 1 0

0 1 0 1 0 0

0 1 1 0 0 0

1 0 0 0 0 1

1 0 0 0 1 0

1 0 0 1 0 0

1 0 1 0 0 0

1 1 0 0 0 0



I want to rewrite it tacit
   Smps=.((=+/)"1 f)#f@]
This works but is without the hook, so "f" is repeated.
How to write the hook tacitly?
I believe that this is easy, but I am stuck.
Thank you!
Bo.




--
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

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

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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] break from loading a script with 'load'

2021-08-31 Thread &#x27;Michael Day&#x27; via Programming
I sometimes need this too.  If so,  and if you're JQt,  it's easy to 
select all the unwanted
lines and switch on comments with ctrl-/ .  You can later uncomment all 
those lines with

another ctrl-/ on the same selection.

However,  that can be a bit awkward,  and thanks to your message I've 
just written
this fairly verbose and none-too elegant if not disgraceful function, 
loadtomark,  to do what

I often need,  and which might fit your requirement.

The idea is to place one or more marker/s in your script,  starting in 
the first column.  I've tried )))

but that raises an error if/when you load the whole script;
"NB. )))" would be ok,  but you'd need to specify that exact string as 
I've written it, ie with the NB. .
Alternatively,  plant a number of markers,  eg 0001,  0002 ... 1234 
etc;  the search string would be

whichever marker you wish to stop at.  The load doesn't include the marker.

It can be tedious to type the script's name in full,  but it's easy 
enough to first do a load

of the whole script using ctrl-L,  and capture the terminal message
   load ''   ,
then copy and modify it in the terminal session to read
   search-string loadtomark  ''

As I've only just written this in response to your enquiry,  it's hardly 
tested;  no doubt some problems
will arise with experience!  I'll embed it in my startup script, and try 
to remember to use it when I

need to do a partial load.

NB. 
NB. selective script load from y - up to but not including a left 
justified marker in x
NB. not as convenient as ctrl-L etc,  but needs minimal modification in 
script


loadtomark =: 3 : 0
load y   NB. nothing to look for - just load script as is
:
assert. fexist y
require'files'
NB. look for first string x at beginning of lines of script
mark=. x
q   =. fread y
iq  =. mark {.@:I.@E. q, mark

if. iq >: # q do.  NB. mark not found,  so load script as is
   echo mark,' not found;  loading script as is'
   echo 'load ', y
   load y
   return.
end.

q   =. iq {. q
NB. string found;  create temporary script; should work!!!
while. fexist rsc =. '~user/temp/', '.ijs',~ a.{~ 97 + 26?26 do.
end.
try.  NB. if something goes wrong,  keeps the temporary script
q fwrite rsc
scr =. 'load''', rsc, 
echo scr    NB.  not very useful as temp script will be erased!
". scr
ferase rsc  NB.  should be ok unless script is extremely long
catch.
   echo 'failed... scratch file = ',rsc
end.
)
NB. ==
Any use?

Mike


On 31/08/2021 13:27, 'Rudolf Sykora' via Programming wrote:

Dear list,


if I load a (longer) script, I sometimes want to ignore a part of it
beyond a certain line. Is there a way to achieve that gracefully? (I
sometimes just add something syntactically wrong to stop there, on an
error).


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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Hello, new programmer here!

2021-09-05 Thread &#x27;Michael Day&#x27; via Programming

Hello Joseph,

Unfortunately,  >.  is not defined as (greater than or equal to)

It's very important to realise that
>  >.    and   >:   are three different, albeit related,  primitives.
and even more important that (nearly?) all symbols or letters
used for J primitives can be monographs,  or digraphs with a
trailing . or :
Some have other modifications;  there are even some trigraphs.
That's why the vocabularies have 3 columns.
(And many/most verbs can be monadic or dyadic.  eg,  * can be
sign (monad) as well as multiply (dyad))

Here,
>  is   (greater than)
   3 4 5 > 2 4 6   NB. for example,  is 3 > 2,  is 4 > 4, and is 5 > 6 ?
1 0 0
>. is  (maximum)  NB. what are max(3,2), max(4,4), max(5,6) ?
   3 4 5 >. 2 4  6
3 4 6
>: is (greater than or equal to)
   3 4 5 > 2 4 6   NB. for example,  is 3 >= 2,  is 4 >= 4, and is 5 >= 6 ?
1 1 0

Perhaps it's instructive,  or possibly confusing to examine all three
dyads at once:

   3 4 5 (>, >. ,: >:) 2 4 6   NB. three rows, one for each verb!
1 0 0
3 4 6
1 1 0

Any help?

Mike

On 05/09/2021 22:21, joseph turco wrote:

Hey Raul,

I was speaking in context to the book 'arithmetic' not in general. In the
exercises for the first chapter for example, it says to use two user
defined verbs that the book has you define earlier in the chapter, but the
problem is, is that you never do that ( i used the search function, not
just scrolling up and down, there is no sign of these verbs). Another
problem was that the following was a exercise and was asked by the book to
write these out before computing it. i liked that idea. but the following
never explained:

d =: 0 1 2 3 4

d >. d. is greater or equal to, why is 2's being printed across the chart?

why with <., are true and false values being printed than the nouns in the
vector like the >. shows?

maybe the book really isn't for the level of novice i am, or the book just
isn't laid out correctly. As i said

i am reading the J primer and that has been much better so far. If i
misread something in the 'arithmetic' book

id like to be proven wrong. In regards to study time, ive been using most
of my spare time learning to program as i

find it fascinating, and it also doesn't cost me a dime (well, other than
the hydro).


regards,


Joseph Turco


The book

On Sun, Sep 5, 2021 at 4:36 PM Raul Miller  wrote:


You might also want to try some of the J labs.

Also... my experience was that I needed to circle back and re-read
things after learning parts of the language. While I suppose it's
technically true that "all you need to know is how to count", that's
true in the sense that calculus is just another method for counting.
You still need to be able to work through the examples and understand
what you are seeing...

But be sure to pace yourself. A half hour a day is better than 4 hours
once a week.

Thanks,

--
Raul

On Sun, Sep 5, 2021 at 1:41 PM joseph turco 
wrote:

Hello R.E.Boss

I Do not have any post-secondary education, and am solely programming

just

out of recreation is the best way i can put it. Ive only dabbled in other
programming languages and didn't find them interesting. I actually Found

J

after having issues getting Dyalog APL running on my 64-bit ARM computer,
and J worked perfectly. I also appreciate the fact it uses ASCII

characters

and not a special character set. I am an italian-canadian, and only know
the language from being raised around it, so its what i know other than
english, that's not saying i hate it. I actually dumped the arithmetic

book

as it doesn't make much sense of explaining things (the book says all you
need to know is how to count) and its missing things that are referred in
some sections. Im giving the J Primer a crack too see if helps me.

regards,

Joseph Turco

On Sun, Sep 5, 2021 at 11:51 AM R.E. Boss  wrote:


Can you tell us a bit about your background? Did you program before?

Which

languages? Why was Italian not a language to learn for fun?

Welcome anyhow!
One can have worse reasons to learn a language.


R. E. Boss


-Original Message-
From: Programming  On

Behalf Of

joseph turco
Sent: zaterdag 4 september 2021 17:01
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Hello, new programmer here!

Thanks Bo,

I am actually following the 'Learning J' book that is on the J website.
its been good so far, but i've been getting a bit confused with the '&'
verb and '@:' verb and what makes them different (they are verbs

right?).

Its funny because i was bored of math class in high school and was one

of

those kids who "skipped" a lot, but using a language like J has made me
fascinated with what is possible.

regards,

Joseph Turco

On Sat, Sep 4, 2021 at 7:06 AM 'Bo Jacoby' via Programming <
programm...@jsoftware.com> wrote:


  Welcome Joseph!
Being an old programmer I became fascinated by J.
There is a lot to learn, but some of it is unnecessary to the

beginner.

The 3 operations, addition (+), multiplication (*), and

exponentiation

(^), are sufficien

Re: [Jprogramming] cross product

2021-09-23 Thread &#x27;Michael Day&#x27; via Programming
I thought this should perform similarly to Igor's proposal,  but 
evidently not:


NB. input:
   $bigmap
3000 4000
   (+/%#) ,bigmap
0.030052333
   10{.bigm
abcabcabca
   10{.bign
ABCDABCDAB

NB. fns:
    ts  NB. timestamp

6!:2 , 7!:2@]


    acp   NB. IZ

1 : (':'; '; (<"0 x) ,"0 L: 0 m <@#"1 y')


   ix   NB. MD - index of ones in boolean
$ #: I.@,
   doix MD.  using the index
4 : 0
'mm nn' =. y
map =. x
'ixl ixr' =. |: ix map
l   =. ixl { mm
r   =. ixr { nn
l,. r
)


   ts'#bigmap ((#L:0"1{:),.&;~+/"1@[ #L:0 {.@]) bigm;bign' NB. RE Boss
0.0317587 14097792
   ts'bigm bigmap acp bign'  NB. Igor Zhuravlov
0.016309 3645696
   ts'bigmap doix bigm;bign' NB. Mike Day
0.0395122 16780064


It's clear I should learn how L: works;   it apparently outclasses I. 
for this problem,


but why is its application by Igor so much quicker and slimmer than REB's?


Cheers,


Mike



On 23/09/2021 14:12, R.E. Boss wrote:

map ((#L:0"1{:),.&;~+/"1@[ #L:0 {.@]) 'abc';'ABCD'
aA
aD
bB
bC

My 2 cts.


R.E. Boss


-Original Message-
From: Programming  On Behalf Of bill 
lam
Sent: dinsdag 21 september 2021 11:38
To: Programming forum 
Subject: [Jprogramming] cross product

Say I have a boolean matrix
] map=. 3 4 $ 1 0 0 1 0 1 1 0 0 0 0 0
1 0 0 1
0 1 1 0
0 0 0 0

and 2 vectors of dimension equal to the 2 sides of the matrix
m=. 'abc' [ n=. 'ABCD'
  I want a cross product for those 1 in the matrix, with result like this
_2 ]\ 'aAaDbBbC'
aA
aD
bB
bC

Is it possible to do it without explicit loops? The dimension of the matrix can 
be very large so that generating all cross products then eliminating is not an 
option.
--
For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] cross product

2021-09-23 Thread &#x27;Michael Day&#x27; via Programming
Henry's comment just now explains the difference in performance,   I 
should think.


Bill hasn't yet told us the ones-density or matrix-size.

Anyway,
Engine: j903/j64avx2/windows
Beta-q: commercial/2021-09-14T15:38:42
Library: 9.03.06
Qt IDE: 1.9.3/5.15.2(5.15.2)
Platform: Win 64
Installer: J903 install
InstallPath: c:/d/j903-beta
Contact: www.jsoftware.com

Cheers,

Mike


On 23/09/2021 15:53, Raul Miller wrote:

Possibly special code. Which version of J were you using?

(I haven't benchmarked any of this myself. I probably should...)

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] cross product

2021-09-23 Thread &#x27;Michael Day&#x27; via Programming
If these values for size and density are typical,  then it appears that 
Ric's

suggestion,  and mine,  come out a bit better.

Presumably if you're using a sparse representation,  you may assume you've
already got an index array.

   $bigmap
3000 4000
   +/,bigmap    NB. ~ 0.004% density
500
   bigix =: 4$.$. bigmap    NB. or big ix =: ix bigmap NB.  preset the 
index array


   ts'({&bigm@:{."1,. {&bign@:{:"1)bigix' NB. MD -slower but thinner
0.0001388 5888

   ts'|:(bigm,:bign) {~"1 |: bigix' NB. Ric - 10x quicker but 5x fatter
1.06e_5 25504

... so perhaps Ric was right all along!

I haven't tried Bill's 20 x 2 though.

Cheers,

Mike



On 23/09/2021 16:22, bill lam wrote:

I encountered a case in which
$map = 20 2
Density of map is 0.004%

map is already sparse otherwise it will run into out-of-memory error
readily.


On Thu, Sep 23, 2021, 11:07 PM 'Michael Day' via Programming <
programm...@jsoftware.com> wrote:


Henry's comment just now explains the difference in performance,   I
should think.

Bill hasn't yet told us the ones-density or matrix-size.

Anyway,
Engine: j903/j64avx2/windows
Beta-q: commercial/2021-09-14T15:38:42
Library: 9.03.06
Qt IDE: 1.9.3/5.15.2(5.15.2)
Platform: Win 64
Installer: J903 install
InstallPath: c:/d/j903-beta
Contact: www.jsoftware.com

Cheers,

Mike


On 23/09/2021 15:53, Raul Miller wrote:

Possibly special code. Which version of J were you using?

(I haven't benchmarked any of this myself. I probably should...)

Thanks,



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] irregular tillings

2021-09-26 Thread &#x27;Michael Day&#x27; via Programming

Still trying to understand L: - it looks so useful,
but meanwhile,  how do you get an even more irregular tiling such as:

+---+-+
| 1  2  3  4| 4  5|
| 8  9 10 11|11 12|
|15 16 17 18|18 19|
+---+-+
|29 30 31 32|32 33|
+---+-+
|15 16 17 18|18 19|
|22 23 24 25|25 26|
+---+-+

NB. ie a 3 x 2 tiling ?

This almost does the job:
   [t1 =. <@,:"1/ ,"0"0 1"1/ >(0 3,.4 1,. 2 2);1 4,:4 2
+---+---+---+
|0 1|0 4|0 0|
|3 4|3 2|3 0|
+---+---+---+
|4 1|4 4|4 0|
|1 4|1 2|1 0|
+---+---+---+
|2 1|2 4|2 0|
|2 4|2 2|2 0|
+---+---+---+
NB. or use Raul's latest posting as for t
NB. ?

   T ];.0~L:0 t1
+---+-++
| 1  2  3  4| 4  5||
| 8  9 10 11|11 12||
|15 16 17 18|18 19||
+---+-++
|29 30 31 32|32 33||
+---+-++
|15 16 17 18|18 19||
|22 23 24 25|25 26||
+---+-++

So the current approach is fine for equal numbers of across and down 
tiles,  less good
for unequal ones.  I suppose we can prune t1 to remove columns and/or 
rows having
all zero lengths,  or remove all empty tiles.  In this case, the fact 
that there are 3
columns and two columns in the specification might be used to filter the 
result.


Cheers,

Mike

On 24/09/2021 17:54, R.E. Boss wrote:

This is the way to go for even very irregular tiling.
Let the starting points and their lengths be given per axis, like in
(0 4,:3 1);1 4,:4 2
+---+---+
|0 4|1 4|
|3 1|4 2|
+---+---+
and
  [ T=.i.7 7
  0  1  2  3  4  5  6
  7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 32 33 34
35 36 37 38 39 40 41
42 43 44 45 46 47 48

First make de tiling by indices
t=.<@,:"1/ ,"0"0 1"1/ >(0 4,:3 1);1 4,:4 2
+---+---+
|0 1|0 4|
|3 4|3 2|
+---+---+
|4 1|4 4|
|1 4|1 2|
+---+---+
then
T ];.0~L:0 t
+---+-+
| 1  2  3  4| 4  5|
| 8  9 10 11|11 12|
|15 16 17 18|18 19|
+---+-+
|29 30 31 32|32 33|
+---+-+

All credits to Miller.


R.E. Boss


-Original Message-
From: Programming  On Behalf Of R.E. 
Boss
Sent: vrijdag 24 september 2021 16:02
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] irregular tillings

This is probably the closest one could get, building the irregular tiling first 
in indices and then applying ;.0 Thanks.


R.E. Boss


-Original Message-
From: Programming 
mailto:programming-boun...@forums.jsoftware.com>>
 On Behalf Of Raul Miller
Sent: vrijdag 24 september 2021 11:36
To: Programming forum 
mailto:programm...@jsoftware.com>>
Subject: Re: [Jprogramming] irregular tillings

Not easily (you could produce a larger result and discard the unwanted content).

However, you could do this:

t=: 0 2 5 e.~i.7
T=: i.7 7
T];.0~L:0<@,."1/~(}:,.2-~/\])I.t,1
+-++-+
|0 1  |2  3  4 | 5  6|
|7 8  |9 10 11 |12 13|
+-++-+
|14 15|16 17 18|19 20|
|21 22|23 24 25|26 27|
|28 29|30 31 32|33 34|
+-++-+
|35 36|37 38 39|40 41|
|42 43|44 45 46|47 48|
+-++-+

I hope this helps,

--
Raul

On Fri, Sep 24, 2021 at 4:32 AM R.E. Boss 
mailto:r.e.b...@outlook.com>> wrote:

see https://code.jsoftware.com/wiki/Vocabulary/semidot3#dyadic

Let
[t=.;2 3 2<@{."(0)1
1 0 1 0 0 1 0
T=:i.7 7

then what I want is produced with

>,.&,.&.>/('';~t)<;.1 L:_ 0 ('';t)<;.1 T
+-++-+
|0 1  |2  3  4 | 5  6|
|7 8  |9 10 11 |12 13|
+-++-+
|14 15|16 17 18|19 20|
|21 22|23 24 25|26 27|
|28 29|30 31 32|33 34|
+-++-+
|35 36|37 38 39|40 41|
|42 43|44 45 46|47 48|
+-++-+

Is this (also) possible with <;.3  ?


R.E. Boss
--
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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] irregular tillings

2021-09-26 Thread &#x27;Michael Day&#x27; via Programming

Yes,  thanks - that seems to be the way to do it.

I liked Raul's specification, in his reply earlier, of diagonals, 
essentially, but it suffers from

needing more input.

Also,  specifying starts and lengths is a bit more convenient for 
extension to higher

dimensions,  should you want 3+ dimensional tilings (blocks?)!

Cheers,

Mike

On 26/09/2021 15:29, R.E. Boss wrote:

Code the tiles by giving per axis the boxed starting points and their lengths.
In your case that is
(0 4 2,: 3 1 2) ; 1 4,: 4 2

Now, with a small adaptation you produce the index tiling

 t=:<@,:"1/ >,."0 1 L:0/(0 4 2,: 3 1 2) ; 1 4,: 4 2 NB. the open (>) is moved to the 
left, so ,."0 1 needs a L:0 (or &.>).
+---+---+
|0 1|0 4|
|3 4|3 2|
+---+---+
|4 1|4 4|
|1 4|1 2|
+---+---+
|2 1|2 4|
|2 4|2 2|
+---+---+
And we are done
T ];.0~L:0 t
+---+-+
| 1  2  3  4| 4  5|
| 8  9 10 11|11 12|
|15 16 17 18|18 19|
+---+-+
|29 30 31 32|32 33|
+---+-+
|15 16 17 18|18 19|
|22 23 24 25|25 26|
+---+-+

The next level of irregularity is that you have different number of columns per 
row, or different number of rows per column.


R.E. Boss


-Original Message-
From: Programming  On Behalf Of 
'Michael Day' via Programming
Sent: zondag 26 september 2021 13:04
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] irregular tillings

Still trying to understand L: - it looks so useful, but meanwhile,  how do you 
get an even more irregular tiling such as:

+---+-+
| 1  2  3  4| 4  5|
| 8  9 10 11|11 12|
|15 16 17 18|18 19|
+---+-+
|29 30 31 32|32 33|
+---+-+
|15 16 17 18|18 19|
|22 23 24 25|25 26|
+---+-+

NB. ie a 3 x 2 tiling ?

This almost does the job:
     [t1 =. <@,:"1/ ,"0"0 1"1/ >(0 3,.4 1,. 2 2);1 4,:4 2
+---+---+---+
|0 1|0 4|0 0|
|3 4|3 2|3 0|
+---+---+---+
|4 1|4 4|4 0|
|1 4|1 2|1 0|
+---+---+---+
|2 1|2 4|2 0|
|2 4|2 2|2 0|
+---+---+---+
NB. or use Raul's latest posting as for t NB. ?

     T ];.0~L:0 t1
+---+-++
| 1  2  3  4| 4  5||
| 8  9 10 11|11 12||
|15 16 17 18|18 19||
+---+-++
|29 30 31 32|32 33||
+---+-++
|15 16 17 18|18 19||
|22 23 24 25|25 26||
+---+-++

So the current approach is fine for equal numbers of across and down tiles,  
less good for unequal ones.  I suppose we can prune t1 to remove columns and/or 
rows having all zero lengths,  or remove all empty tiles.  In this case, the 
fact that there are 3 columns and two columns in the specification might be 
used to filter the result.

Cheers,

Mike

On 24/09/2021 17:54, R.E. Boss wrote:

This is the way to go for even very irregular tiling.
Let the starting points and their lengths be given per axis, like in
 (0 4,:3 1);1 4,:4 2
+---+---+
|0 4|1 4|
|3 1|4 2|
+---+---+
and
   [ T=.i.7 7
   0  1  2  3  4  5  6
   7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 32 33 34
35 36 37 38 39 40 41
42 43 44 45 46 47 48

First make de tiling by indices
 t=.<@,:"1/ ,"0"0 1"1/ >(0 4,:3 1);1 4,:4 2
+---+---+
|0 1|0 4|
|3 4|3 2|
+---+---+
|4 1|4 4|
|1 4|1 2|
+---+---+
then
 T ];.0~L:0 t
+---+-+
| 1  2  3  4| 4  5|
| 8  9 10 11|11 12|
|15 16 17 18|18 19|
+---+-+
|29 30 31 32|32 33|
+---+-+

All credits to Miller.


R.E. Boss


-Original Message-
From: Programming  On Behalf
Of R.E. Boss
Sent: vrijdag 24 september 2021 16:02
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] irregular tillings

This is probably the closest one could get, building the irregular tiling first 
in indices and then applying ;.0 Thanks.


R.E. Boss


-Original Message-
From: Programming
mailto:programming-bounces@f
orums.jsoftware.com>> On Behalf Of Raul Miller
Sent: vrijdag 24 september 2021 11:36
To: Programming forum
mailto:programm...@jsoftware.com>>
Subject: Re: [Jprogramming] irregular tillings

Not easily (you could produce a larger result and discard the unwanted content).

However, you could do this:

 t=: 0 2 5 e.~i.7
 T=: i.7 7
 T];.0~L:0<@,."1/~(}:,.2-~/\])I.t,1
+-++-+
|0 1  |2  3  4 | 5  6|
|7 8  |9 10 11 |12 13|
+-++-+
|14 15|16 17 18|19 20|
|21 22|23 24 25|26 27|
|28 29|30 31 32|33 34|
+-++-+
|35 36|37 38 39|40 41|
|42 43|44 45 46|47 48|
+-++-+

I hope this helps,

--
Raul

On Fri, Sep 24, 2021 at 4:32 AM R.E. Boss 
mailto:r.e.b...@outlook.com>> wrote:

see https://code.jsoftware.com/wiki/Vocabulary/semidot3#dyadic

Let
 [t=.;2 3 2<@{."(0)1
1 0 1 0 0 1 0
 T=:i.7 7

then what I want is produced with

 >,.&,.&.>/('';~t)<;.1 L:_ 0 ('';t)<;.1 T
+-++-+
|0 1  |2  3  4 | 5  6|
|7 8  |9 10 11 |12 13|
+-++-+
|14 15|16 17 18|19 20|
|21 22|23 

Re: [Jprogramming] j901 (actually 903-beta-k) available from app store for iPhone/iPad

2021-10-20 Thread &#x27;Michael Day&#x27; via Programming

Congratulations to Ian!

As he knows,  my iPad is "ancient",  ie 4-5 years old,  and is stuck at 
around iOS 12.1  He/we tried to
get it to work in that OS,  but it just wouldn't fit.  Luckily, like 
several others,  I was able to try a number
of Beta versions on a later iPad,  in my case,  my wife's more recent 
model.


Ian has dealt very patiently with my mostly minor quibbles,   mostly 
arising from my own ignorance.


Thanks, Ian - Great work!

Mike


On 19/10/2021 01:52, Eric Iverson wrote:

WOW!

It is with great pleasure that I announce that Ian Clark has released his
new version of J for iOS!

It is at the app store now. Search for j901, install, and enjoy.

There are undoubtedly rough edges, but it is a huge improvement over the
previous j701.

One rough edge is that the search is for j901, but the app 9!:14'' says
j903-beta-k.

Now that there is a clean base, and Ian has overcome the apple obstacles,
it should be possible to keep this important product current and relevant.

Three cheers for Ian!!!
--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] JHS update

2021-11-29 Thread &#x27;Michael Day&#x27; via Programming

Thanks Eric.

I've noticed your msg,  just before bedtime,  so, briefly,  here's what 
happened when
I tried firing up tour>overview,  after running Package Manager from Jqt 
to install all

selected updates:

overview tour

*** event handler error
ev_overview_click 0
|assertion failure: spf
|   fexist r['must exist'
jdo   jev_jijx_ 0
jtype click
jmid  overview
jsid
jdata
jwid  jijx

Here's the JVERSION info:

Engine: j903/j64avx2/windows
Beta-v: commercial/2021-11-16T21:47:12
Library: 9.03.07
Qt IDE: 1.9.4/5.15.2(5.15.2)
Platform: Win 64
Installer: J903 install
InstallPath: c:/d/j903-beta
Contact: www.jsoftware.com

And so to bed,

Cheers,

Mike


On 29/11/2021 21:51, Eric Iverson wrote:

JHS update available.

jijx menu>tour>overview is a new lab that is an overview for new users that
covers basic mechanics of J programming with the JHS front end.

App facilities for apps without requiring any javascript programming have
been improved. See:
rundemo_jhs_ 16
--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] JHS update

2021-11-29 Thread &#x27;Michael Day&#x27; via Programming

Devon's note reminds me to mention that I'm using the Avast Secure Browser
Mike

On 30/11/2021 00:11, 'Michael Day' via Programming wrote:

Thanks Eric.

I've noticed your msg,  just before bedtime,  so, briefly,  here's 
what happened when
I tried firing up tour>overview,  after running Package Manager from 
Jqt to install all

selected updates:

overview tour

*** event handler error
ev_overview_click 0
|assertion failure: spf
|   fexist r['must exist'
jdo   jev_jijx_ 0
jtype click
jmid  overview
jsid
jdata
jwid  jijx

Here's the JVERSION info:

Engine: j903/j64avx2/windows
Beta-v: commercial/2021-11-16T21:47:12
Library: 9.03.07
Qt IDE: 1.9.4/5.15.2(5.15.2)
Platform: Win 64
Installer: J903 install
InstallPath: c:/d/j903-beta
Contact: www.jsoftware.com

And so to bed,

Cheers,

Mike


On 29/11/2021 21:51, Eric Iverson wrote:

JHS update available.

jijx menu>tour>overview is a new lab that is an overview for new 
users that

covers basic mechanics of J programming with the JHS front end.

App facilities for apps without requiring any javascript programming 
have

been improved. See:
    rundemo_jhs_ 16
--
For information about J forums see http://www.jsoftware.com/forums.htm






--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Advent of Code day 2 + comment on day 18

2021-12-22 Thread &#x27;Michael Day&#x27; via Programming
Apologies - more chat than programming,  but: fwiw,  for part 1,  I just 
defined simple
one-liner functions "forward" etc which worked ok.  For part 2, they 
needed redefining,  and,

yes, I used direct defs;  nothing as sophisticated as fold!

I've done days 1-17,  mostly straightforward,  some very fiddly.

But I'm stuck at 18,  which is v complicated in its explanation.  I 
started with boxes in J,
but found navigation hard - I haven't used nested structures much in J - 
so resorted to
working on the untranslated rows,  using ;: to separate the symbols & 
numbers,  but
couldn't get all the examples to reproduce the stated results!    So 
I've wasted yet more time
learning - or relearning - how to deal with nested arrays in Dyalog APL 
and remembering how
to use John Scholes' dfns.  Managed to "reduce" the "addition" of the 
first pair of snailnumbers,
but reducing the "addition" of the third line defeats me.  I suppose I'm 
sometimes inserting

some result at the wrong depth.

I've spent so much time on that that I'll probably give up the rest!

Cheers,

Mike


On 22/12/2021 14:59, Raul Miller wrote:

(responding to 
http://jsoftware.com/pipermail/programming/2021-December/059436.html#)

I am not sure that I thought this example out well enough for it to be
good on an examples page.

For instance, after thinking about it for just a few minutes, I realized that

b2fold=: 0 0 0&(}.F..{{
   'dH0 dA0 N'=. x
   'A H D'=. y
   dA=: N*dA0
   dH=: N*dH0
   dD=: A*dH
   y+dA,dH,dD
}})

b2=: {{*/b2fold y}}

would have been clearer.

(Originally I was using ]F.. and commenting that I needed to drop the
first item of the result. But isn't it clearer to include that drop
mechanism with the fold implementation?)

But (and this is worse): this particular example lacks utility, which
means that it's not going to be very interesting for anyone.

Other opportunities will arise, though. And I think that your concept
of linked example pages is a good one and worth following up on.

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Advent of Code day 2 + comment on day 18

2021-12-22 Thread &#x27;Michael Day&#x27; via Programming

Thanks, Raul

I've checked what "use" does with an example.  I won't study its 
details,  though,  not wanting
to crib.  I will say though that the output is similar to my interim 
results in processing the data.
My mistake appears to have been to keep the verbose format and try to 
reproduce it,  ie with
lots of indexing locations of brackets and so on and generally getting 
in a muddle.   As usual,

the key seems to be to find a decent data structure.

Nice to know it can be done,  and can be understood! Congratulations!

Cheers,

Mike

On 22/12/2021 21:27, Raul Miller wrote:

use=: {{
depth=. +/\-/'[]'=/y
sel=. _1|.' .'E.' .'{~mask=.-.y e. '[,]'
vals=.".mask #inv mask#y
assert. (+/sel)=#vals
(sel#depth),:vals
}}



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Advent of Code Day 6

2021-12-27 Thread &#x27;Michael Day&#x27; via Programming
Yes, a nice insight,  I suppose,  but only nice,  and by no means 
necessary!

Many Project Euler problems require this sort of thing in the tool-box!
Also,  some sort of counting of cases is often nearly essential for PE.

One of my finite arithmetic routines,  written pre-{{ ... }}
NB. Matrix x to high power y modulo m
NB. (adapted from Roger Hui,  perhaps...)
mMpower =: 1 : 0
:
M  =. = i.# M0 =. x
b  =. #:y
mm =. <.@:(m| +/ . *)
while.#b do.
  if. {:b do. M =. M0 mm M end.
  M0 =. mm~ M0   NB. square it
  b  =. }:b
end.
M
)

Set the modulus to 0 here:

   count 3 4 3 2 1
0 1 1 2 1 0 0 0 0
   +/(count 3 4 3 2 1) +/ . * (mat1(0 mMpower) 80)   NB. mat1 as Raul's 
9x9 matrix

5934
   +/(count 3 4 3 2 1) +/ . * (mat1(0 mMpower) 256)
26984457539

Advent of Code problems are, mostly,  nothing like as demanding of
computer resources as PE.  The time improvement is pretty irrelevant
here:

   ts'+/(+/ . *)&mat1^:256 ct' [ ct =: count 3 4 3 1 2
5.5e_5 3008

   ts'+/ct +/ . * mat1(0 mMpower) 256'
2.17e_5 8512

(Once we've counted the different classes of fish,  it's also pretty 
irrelevant

how many are in the 300 samples.)

But it's good to practise for when we DO need the technique.

Cheers,

Mike


On 27/12/2021 14:39, Raul Miller wrote:

That's a really good insight.

Conceptually, this would be
1 (<0 6)}(=/1|.])i.9
0 0 0 0 0 0 1 0 1
1 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1 0

But we want to multiply on the right (for ^:) instead of on the left.
So, instead
M=: |:1 (<0 6)}(=/1|.])i.9
or
M=: 1 (<6 0)}(=/~1|.])i.9

+/M+/ .*^:256 <:#/.~(i.9),3,4,3,1,2
26984457539

Or, squaring M, 8 times:
+/(+/ .*~^:8 M)+/ .*<:#/.~(i.9),3,4,3,1,2
26984457539

Actually, the squaring technique would have allowed us to left
multiply our representation of the updates:

+/(<:#/.~(i.9),3,4,3,1,2)+/ .*+/ .*~^:8]1(<0 6)}(=/1|.])i.9
26984457539

Pretty concepts.

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Advent of Code Day 10

2021-12-31 Thread &#x27;Michael Day&#x27; via Programming
I _think_ I used a somewhat different approach.  I'll only deal with 
part 1 as

part 2 doesn't add much complexity.

This approach is simple -  remove adjacent pairs of opening and closing
brackets of the same kind until there are none.  The function is called
reduce:

I've added echo lines only for this email.

reduce =: 3 : 0
a    =. 1 _1 ,2 _2,3 _3,:4 _4
nums =. +/+/"2 a *"2 3 bkts =/ y -.' '
NB. this would have been much better! :
NB. nums =. (,a){~ (,bkts) i.' '-.~{.ex
while. +/ msk =. +/(E.& nums)"1 a do.
  msk =. -. msk + 0, }: msk NB. matching adjacent pair gives 0 0
  nums=. msk#nums
end.
if. 0 > <./ nums do.  NB. "corrupted"
   r =. +/ 3 57 1197 25137 {~ <: |{.(#~ <&0  ) nums
echo 'corrupted'; r
else. NB. "incomplete"
echo 'ignore';   ,|.(}."1 bkts){~<: nums
   r =. 0
end.
r
)

We know if a line is corrupted if we can't reduce it any more AND it 
still contains

some close brackets.

I called the example data "ex" - I held it as a 2-d character array.

Here it goes,  with the echo's firing:

   +/reduce"1 ex
+--++
|ignore|}}]])})]|
+--++
+--+--+
|ignore|)}>]})|
+--+--+
+-++
|corrupted|1197|
+-++
+--+-+
|ignore|}}>}>|
+--+-+
+-+-+
|corrupted|3|
+-+-+
+-+--+
|corrupted|57|
+-+--+
+--+-+
|ignore|]]}}]}]}>|
+--+-+
+-+-+
|corrupted|3|
+-+-+
+-+-+
|corrupted|25137|
+-+-+
+--++
|ignore|])}>|
+--++
26397

Cheers,

Mike



On 31/12/2021 02:41, Raul Miller wrote:

https://adventofcode.com/2021/day/10

For day 10's puzzle, the first part was determining whether
collections of braces and brackets were properly formed.  The
allowable pairs were '()', '[]', '{}', and '<>', and the sample data
looked like this:

sample=:{{)n
[({(<(())[]>[[{[]{<()<>>
[(()[<>])]({[<{<<[]>>(
{([(<{}[<>[]}>{[]{[(<()>
{<>}<{<{<>}{[]{[]{}
[[<[([]))<([[{}[[()]]]
[{[{({}]{}}([{[{{{}}([]
{<[[]]>}<{[{[{[]{()[[[]
[<(<(<(<{}))><([]([]()
<{([([[(<>()){}]>(<<{{
<{([{{}}[<[[[<>{}]]]>[]]
}}

Specifically, for the first part, we were to find the first illegal
character on each line, each of which were assigned a score, and sum
those scores.

   So the result line for that part would look something like this:

+/ 3 57 1197 25137 {~ ')]}>' i. bad

So I built a brute force lexical analyzer which returned empty for
legal lines and the first bad character and its index for illegal
lines:

scanline=:{{
   next=.''
   for_ch. y do.
  select. ch
case.'(' do. next=. next,')'
case.'[' do. next=. next,']'
case.'{' do. next=. next,'}'
case.'<' do. next=. next,'>'
case.')';']';'}';'>' do.
  if. ch={: next do.
next=.}: next
  else.
ch;ch_index return.
  end.
case. do. echo 'unexpected';ch;ch_index throw.
  end.
   end.
   ''
}}

The basic approach here is to have an intermediate result which is a
stack of the expected terminating characters and to report on failed
matches.

I left the character index in the result to help me debug my code if I
had done something horribly wrong.

Since I was returning boxed characters from that routine for the error
cases, I decided my lookup should normalize both the left and right
arguments to i. to be boxed strings:

aoc10a=:{{
   err=. {."1>(<@scanline;._2 y)-.a:
   +/((;:')]}>')i.&:(,each) err){3 57 1197 25137
}}

For part b, we instead were to report on the lines without illegal
characters and score based on the missing terminating
brackets/braces/...

Here, the scoring was 1 + the index into ')]}>', multiplied by 5 ^
index into that particular string.

So I took the above code and tweaked it to return the unfinished
stacks on "good lines":

scan2=:{{
   next=.''
   for_ch. y do.
  select. ch
case.'(' do. next=. next,')'
case.'[' do. next=. next,']'
case.'{' do. next=. next,'}'
case.'<' do. next=. next,'>'
case.')';']';'}';'>' do.
  if. ch={: next do.
next=.}: next
  else.
'' return.
  end.
case. do. echo 'unexpected';ch;ch_index throw.
  end.
   end.
   |.next
}}

My initial implementation of the scoring mechanism was a bit messy,
but there's no point burdening you with that. Instead:

score=:5 #. 1 + ')]}>' i. ]

Though I could have used

score=:5 p.~ 1 + ')]}>' i. |.

To actually complete the second part, we needed to find the median score:

aoc10b=:{{
   compl=. (<@scan2;._2 y)-.a:
   ({~ <.@-:@#)/:~ score every compl
}}

And that was it for day 10.




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Advent of Code Day 10

2021-12-31 Thread &#x27;Michael Day&#x27; via Programming

Sorry - always forget something - bkts ???

    bkts =: 4 2 $'()[]{}<>'

I hope the rest is self-contained,  but apologies for the ungraceful
character non-alignment.  I'd avoided graphic boxing characters and
had sent in fixed-width font where it mattered!

Mike



On 31/12/2021 15:58, 'Michael Day' via Programming wrote:
I _think_ I used a somewhat different approach.  I'll only deal with 
part 1 as

part 2 doesn't add much complexity.

This approach is simple -  remove adjacent pairs of opening and closing
brackets of the same kind until there are none.  The function is called
reduce:

I've added echo lines only for this email.

reduce =: 3 : 0
a    =. 1 _1 ,2 _2,3 _3,:4 _4
nums =. +/+/"2 a *"2 3 bkts =/ y -.' '
NB. this would have been much better! :
NB. nums =. (,a){~ (,bkts) i.' '-.~{.ex
while. +/ msk =. +/(E.& nums)"1 a do.
  msk =. -. msk + 0, }: msk NB. matching adjacent pair gives 0 0
  nums=. msk#nums
end.
if. 0 > <./ nums do.  NB. "corrupted"
   r =. +/ 3 57 1197 25137 {~ <: |{.(#~ <&0  ) nums
echo 'corrupted'; r
else. NB. "incomplete"
echo 'ignore';   ,|.(}."1 bkts){~<: nums
   r =. 0
end.
r
)

We know if a line is corrupted if we can't reduce it any more AND it 
still contains

some close brackets.

I called the example data "ex" - I held it as a 2-d character array.

Here it goes,  with the echo's firing:

   +/reduce"1 ex
+--++
|ignore|}}]])})]|
+--++
+--+--+
|ignore|)}>]})|
+--+--+
+-++
|corrupted|1197|
+-++
+--+-+
|ignore|}}>}>|
+--+-+
+-+-+
|corrupted|3|
+-+-+
+-+--+
|corrupted|57|
+-+--+
+--+-+
|ignore|]]}}]}]}>|
+--+-+
+-+-+
|corrupted|3|
+-+-+
+-+-+
|corrupted|25137|
+-+-+
+--++
|ignore|])}>|
+--++
26397

Cheers,

Mike



On 31/12/2021 02:41, Raul Miller wrote:

https://adventofcode.com/2021/day/10

For day 10's puzzle, the first part was determining whether
collections of braces and brackets were properly formed.  The
allowable pairs were '()', '[]', '{}', and '<>', and the sample data
looked like this:

sample=:{{)n
[({(<(())[]>[[{[]{<()<>>
[(()[<>])]({[<{<<[]>>(
{([(<{}[<>[]}>{[]{[(<()>
{<>}<{<{<>}{[]{[]{}
[[<[([]))<([[{}[[()]]]
[{[{({}]{}}([{[{{{}}([]
{<[[]]>}<{[{[{[]{()[[[]
[<(<(<(<{}))><([]([]()
<{([([[(<>()){}]>(<<{{
<{([{{}}[<[[[<>{}]]]>[]]
}}

Specifically, for the first part, we were to find the first illegal
character on each line, each of which were assigned a score, and sum
those scores.

   So the result line for that part would look something like this:

    +/ 3 57 1197 25137 {~ ')]}>' i. bad

So I built a brute force lexical analyzer which returned empty for
legal lines and the first bad character and its index for illegal
lines:

scanline=:{{
   next=.''
   for_ch. y do.
  select. ch
    case.'(' do. next=. next,')'
    case.'[' do. next=. next,']'
    case.'{' do. next=. next,'}'
    case.'<' do. next=. next,'>'
    case.')';']';'}';'>' do.
  if. ch={: next do.
    next=.}: next
  else.
    ch;ch_index return.
  end.
    case. do. echo 'unexpected';ch;ch_index throw.
  end.
   end.
   ''
}}

The basic approach here is to have an intermediate result which is a
stack of the expected terminating characters and to report on failed
matches.

I left the character index in the result to help me debug my code if I
had done something horribly wrong.

Since I was returning boxed characters from that routine for the error
cases, I decided my lookup should normalize both the left and right
arguments to i. to be boxed strings:

aoc10a=:{{
   err=. {."1>(<@scanline;._2 y)-.a:
   +/((;:')]}>')i.&:(,each) err){3 57 1197 25137
}}

For part b, we instead were to report on the lines without illegal
characters and score based on the missing terminating
brackets/braces/...

Here, the scoring was 1 + the index into ')]}>', multiplied by 5 ^
index into that particular string.

So I took the above code and tweaked it to return the unfinished
stacks on "good lines":

scan2=:{{
   next=.''
   for_ch. y do.
  select. ch
    case.'(' do. next=. next,')'
    case.'[' do. next=. next,']'
    case.'{' do. next=. next,'}'
 

Re: [Jprogramming] Advent of Code Day 10

2021-12-31 Thread &#x27;Michael Day&#x27; via Programming

Neater!

Cheers,

Mike

On 31/12/2021 19:19, Raul Miller wrote:

That is a different approach.

I had avoided even thinking about that approach, because of speed
concerns. But, testing a simple implementation on the large aoc
"puzzle input", I see that this approach completes in less than 17
milliseconds, Plus it makes reasoning about the problem really simple.

Here's my implementation of your approach:

pairs=: '()','[]','{}',:'<>'
reduce=: rplc&(pairs;"1'')

timespacex 'reduce^:_;._2 input'
0.016612 29920

And, playing with this (extending a working example until I got to the
point I wanted), part 1 looks like this:

red=: reduce^:_;._2 sample
'L R'=:|:pairs
R
)]}>

bad=: red <./@i."1 R
cost=: 3 57 1197 25137 0 {~ R i. bad {"_1 red,.' '
+/cost
26397

And, the second part becomes:

require'stats'
median 5 p.~ 5|1+L i."1 (0=cost)#red
288957

I wish I had thought of that!

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Advent of Code Day 11

2022-01-01 Thread &#x27;Michael Day&#x27; via Programming
Yes,  the second part was again pretty trivial,  at least when, as in 
J,  you can

use the power operation.

I seem to have solved it on my iPad, running iOS 12.5.5,  which is too 
obsolete to
support Ian Clark's new J902 version,  so it's stuck in J701,  so not up 
to {{ }} and

lots more.

I can never remember the tessellation idiom when I need it,  so I 
ravelled the
octopuses,  there are exactly 100,  and set up a global array of 
neighbours.

Here are some:

   7 {. nbrs  NB. I've removed the horizontal box chars, as alignment fails
|1 10 11|0 2 10 11 12|1 3 11 12 13|2 4 12 13 14|3 5 13 14 15|4 6 14 15 
16|5 7 15 16 17|


   (20 + i.4) { nbrs
|10 11 21 30 31|10 11 12 20 22 30 31 32|11 12 13 21 23 31 32 33|12 13 14 
22 24 32 33 34|


I won't bore you with their derivation,  but I suppose this is the main 
difference between my
approach and Raul's - I don't need a "propagate" function,  at the 
expense of a global boxed

list of coordinates.

Here's the step function much as I wrote it - the name was all my own 
work! - there was no

need to soup it up for speed or space given the small size of the problem.

step =: 3 : 0
if. */ 0 = y do.
   y
   return.
end.
d   =. >: y    NB. Initial increment to "energy"
done=. ''
while. 10 e. d do.
   j10 =. I. 10 = d   NB. indices of flashers
   i10 =. j10 -.~ ; j10 { nbrs NB. indices of their neighbours
   done=. ~. done, j10
   c10  =. #/.~ i10  NB. count up flashes seen by those nbrs
   i10 =. ~. i10
   d10 =. 10 <. c10 + i10 { d
   d   =. d10 i10 } d    NB. could be cleaner!
   d   =. 0  done } d
end.
d
)

I didn't wrap the application of step for part 1.  Here's the example 
result:


   $ex   NB. the data is ravelled...
100
   +/0=,step^:(i.11) ex
204

As I said,  part 2 is trivial for J-users:
   <:#step^:a: ex   NB. on the sample data again
195


On 01/01/2022 00:17, Raul Miller wrote:

https://adventofcode.com/2021/day/11

The story for the day 11 puzzle is that we have 100 octopuses (10
rows, 10 columns) which are flashing, each with an intensity level
which is a single digit number:

sample=:".@>;._2{{)n
5483143223
2745854711
5264556173
6141336146
6357385478
4167524645
2176841721
6882881134
4846848554
5283751526
}}

The 'flashing' algorithm being applied here is:

(1) increment every octopus's intensity by 1.
(2) every octopus flashes when its intensity increases past 9.
(3) every flash increases the intensity of the eight adjacent
octopuses by 1. Adjacent, here, means horizontally adjacent or
vertically adjacent or diagonally adjacent.
(4) Iterate steps 2 and 3 until no more octopuses increase their
intensity past 9.
(5) Every octopus which flashed has its intensity set to zero.

This algorithm is a single "step" in a time sequence.

The problem for part A was to count the total number of flashes in the
first 100 steps.

My initial implementation was rather messy. Here's a cleaned up version:

First, I needed a way of propagating those 1s from adjacent flashes.
Note that we can simplify here, because we do not care about the exact
intensity of an octopus which has already flashed.

propagate=: [:+/"1 (1,:3 3) ,;._3 pad
pad=: 0,0,.0,~0,.~]

With that, I could build my step function:

step=: {{
   mask=.1"0 y
   next=. 1+y
   while. 1 e.,extra=. 9


--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


[Jprogramming] AOC Day 22 - was Re: Advent of Code Day 14

2022-01-05 Thread &#x27;Michael Day&#x27; via Programming

I don't think there are any spoilers here.

Well,  I have at last managed to do part 2 of day 22,  one of those 
"days" when part 2 is considerably harder
than part 1.  (I've found day 22 the hardest so far:  day 21 part2's 
Dirac Die was tricky,  because I'd forgotten every go
had 3 throws,  but not really hard;  day 19 was quite hard,  needing 
working out how to reconcile "scanners";
I spent ages on day 18's snailfish having gone down a cul-de-sac with a 
nested array approach!)


It managed to run within a RAM of ~ 14GB usable at the expense of taking 
70 seconds!  My data-structure
wasn't ideal to say the least,  though the initial set of 420 "ops" 
generated only ~ 43000 small objects.

The space actually used appears fo be ~9GB:

    7!:2@] 'reboot2 data'

8721760


There must be a better way,  but at least this slow-coach method didn't 
need a super-computer!


I might inspect the efficiency,  but probably not - it's taken too long 
to find a working solution!


Looking forward to Raul's posting next week!

Cheers,

Mike

On 04/01/2022 13:49, 'Mike Day' via Programming wrote:

As I recall, a killer question until one realises there’s no need to preserve 
the order;  then it’s just a matter of maintaining counts, as you observe.

I’m currently wondering how to acquire the tera- or peta-bytes of storage to 
deal with day 22 part 2.  Part 1 is easy, of course.  No spoilers,  though.  I 
haven’t given up yet!

Cheers,

Mike

Sent from my iPad


On 4 Jan 2022, at 03:06, Raul Miller  wrote:

https://adventofcode.com/2021/day/14

For day 14, we were supposed to run a "polymerization sequence" for N
steps, and then find the difference in the quantity between the most
common and least common elements of the sequence.

For part A, we were supposed to run 10 steps. For part B, we were
supposed to run 40 steps.

The sample data looked like this:


.. [truncated]

--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Advent of Code Day 16

2022-01-06 Thread &#x27;Michael Day&#x27; via Programming

So your parse is akin to my unpack.

I was going to say that my "operator" and "literal" were both dyadic 
too,  but checked,
and now find I'm wrong.  But "unpack" itself is indeed dyadic;  irs 
input is initially 0 _ ,
holding the required part 1 total,  and the number of sub-packets where 
relevant.


I didn't know about apply, 128!:2 . Live and learn!

I find that both our unpacks run in ~ 0.005 seconds,   but mine uses 
~ten times as
much space,  a comparison much as in day 22, discussed earlier. Maybe 
that's because
you have globals,  pos,  packet,  whereas I'm recursively applying 
operator and unpack

to "tail"  which is of course a partial packet.

Mike

On 06/01/2022 11:42, Raul Miller wrote:

Mine is recursive: parse calls operator, and operator calls parse.

That's why I added a trace mechanism (an echo statement showing the
string I used to represent what would happen to the value, along with
the value itself, for each packet) -- so that I could visualize what
was happening.

By the way, re-reading this, I see that my naming convention might
have been confusing -- 'operator' was a dyadic verb. I passed in a
string showing the operation which would be applied to the result.
Also, I could have instead used 128!:2 to implement the operation
itself. So I should also have added a "this could have been done
better" disclaimer.

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] AOC Day 22 - was Re: Advent of Code Day 14

2022-01-06 Thread &#x27;Michael Day&#x27; via Programming
I have gone back and improved the code a bit for day 22 part 2 - well,  
quite a lot.


Part 2 is now solved in ~1 second in ~ 6.5 MB ! (It was 30-60x slower 
and perhaps

1500x more space-consuming.)

Will comment more when Raul presents his comments next week.

Mike


On 06/01/2022 09:19, 'Mike Day' via Programming wrote:

ca 1/3 & 1/8 on time & space - quite an improvement!  Well done!

Mike

Sent from my iPad


On 6 Jan 2022, at 05:42, Raul Miller  wrote:

Mine isn't a whole lot better than that, but I guess it's a little better.

   timespacex 'b22 input'
24.2392 1.15927e9

FYI,

--
Raul

On Wed, Jan 5, 2022 at 7:08 PM 'Michael Day' via Programming
 wrote:

I don't think there are any spoilers here.

Well,  I have at last managed to do part 2 of day 22,  one of those
"days" when part 2 is considerably harder
than part 1.  (I've found day 22 the hardest so far:  day 21 part2's
Dirac Die was tricky,  because I'd forgotten every go
had 3 throws,  but not really hard;  day 19 was quite hard,  needing
working out how to reconcile "scanners";
I spent ages on day 18's snailfish having gone down a cul-de-sac with a
nested array approach!)

It managed to run within a RAM of ~ 14GB usable at the expense of taking
70 seconds!  My data-structure
wasn't ideal to say the least,  though the initial set of 420 "ops"
generated only ~ 43000 small objects.
The space actually used appears fo be ~9GB:

 7!:2@] 'reboot2 data'

8721760


There must be a better way,  but at least this slow-coach method didn't
need a super-computer!

I might inspect the efficiency,  but probably not - it's taken too long
to find a working solution!

Looking forward to Raul's posting next week!

Cheers,

Mike


On 04/01/2022 13:49, 'Mike Day' via Programming wrote:
As I recall, a killer question until one realises there’s no need to preserve 
the order;  then it’s just a matter of maintaining counts, as you observe.

I’m currently wondering how to acquire the tera- or peta-bytes of storage to 
deal with day 22 part 2.  Part 1 is easy, of course.  No spoilers,  though.  I 
haven’t given up yet!

Cheers,

Mike

Sent from my iPad


On 4 Jan 2022, at 03:06, Raul Miller  wrote:

https://adventofcode.com/2021/day/14

For day 14, we were supposed to run a "polymerization sequence" for N
steps, and then find the difference in the quantity between the most
common and least common elements of the sequence.

For part A, we were supposed to run 10 steps. For part B, we were
supposed to run 40 steps.

The sample data looked like this:


.. [truncated]

--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
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


Re: [Jprogramming] Advent of Code Day 19

2022-01-09 Thread &#x27;Michael Day&#x27; via Programming
Raul,  would you mind defining cross?  I've tried */ and (+/  .  *) but 
neither seem to

work for me,  and I'm not sure what you mean.

As I said a few days ago,  I gave up wondering why I'd found 48 
rotations when they
asked for 24,  couldn't grasp what the meant by facing" and resorted to 
matrix divide

with rounding to yield the orientation matrix in each case.

Still stuck on day23 part 1!!!

Cheers,

Mike

On 09/01/2022 02:14, Raul Miller wrote:

https://adventofcode.com/2021/day/19

Like a variety of my work on previous days, my code here is rather
bulky. Did I mention that Advent of Code was something of a bad habit
for me?

Anyways, here, not only is the code bulky, even the sample data is bulky.

Basically, for this puzzle, we were given a bunch of coordinates
beacons reported by a small set of scanners. These coordinates
contained three "flaws":

(1) They used a coordinate system which was centered on the scanner --
not a universal coordinate system.

(2) Each scanner had limited range, so no single scan had locations
for all beacons.

(3) Each scanner had an undetermined orientation.

Luckily for us, each probe "originally" had the same coordinate
system, and each probe's rotations were multiples of 90 degrees along
each axis. So there were only 24 possible orientations for each
scanner.

And, sample data looked like this:

sample=:{{)n
--- scanner 0 ---
404,-588,-901
528,-643,409
-838,591,734
390,-675,-793
-537,-823,-458
-485,-357,347
-345,-311,381
-661,-816,-575
-876,649,763
-618,-824,-621
553,345,-567
474,580,667
-447,-329,318
-584,868,-557
544,-627,-890
564,392,-477
455,729,728
-892,524,684
-689,845,-530
423,-701,434
7,-33,-71
630,319,-379
443,580,662
-789,900,-551
459,-707,401

--- scanner 1 ---
686,422,578
605,423,415
515,917,-361
-336,658,858
95,138,22
-476,619,847
-340,-569,-846
567,-361,727
-460,603,-452
669,-402,600
729,430,532
-500,-761,534
-322,571,750
-466,-666,-811
-429,-592,574
-355,545,-477
703,-491,-529
-328,-685,520
413,935,-424
-391,539,-444
586,-435,557
-364,-763,-893
807,-499,-711
755,-354,-619
553,889,-390

--- scanner 2 ---
649,640,665
682,-795,504
-784,533,-524
-644,584,-595
-588,-843,648
-30,6,44
-674,560,763
500,723,-460
609,671,-379
-555,-800,653
-675,-892,-343
697,-426,-610
578,704,681
493,664,-388
-671,-858,530
-667,343,800
571,-461,-707
-138,-166,112
-889,563,-600
646,-828,498
640,759,510
-630,509,768
-681,-892,-333
673,-379,-804
-742,-814,-386
577,-820,562

--- scanner 3 ---
-589,542,597
605,-692,669
-500,565,-823
-660,373,557
-458,-679,-417
-488,449,543
-626,468,-788
338,-750,-386
528,-832,-391
562,-778,733
-938,-730,414
543,643,-506
-524,371,-870
407,773,750
-104,29,83
378,-903,-323
-778,-728,485
426,699,580
-438,-605,-362
-469,-447,-387
509,732,623
647,635,-688
-868,-804,481
614,-800,639
595,780,-596

--- scanner 4 ---
727,592,562
-293,-554,779
441,611,-461
-714,465,-776
-743,427,-804
-660,-479,-426
832,-632,460
927,-485,-438
408,393,-506
466,436,-512
110,16,151
-258,-428,682
-393,719,612
-211,-452,876
808,-476,-593
-575,615,604
-485,667,467
-680,325,-822
-627,-443,-432
872,-547,-609
833,512,582
807,604,487
839,-516,451
891,-625,532
-652,-548,-490
30,-46,-14
}}

There will be a quiz later.  (Ok, maybe not...)

So, first thing we need here is a mechanism to parse this into
something J can handle. And, it's not obvious here, but the number of
beacons reported by each scanner was not the same. This means we need
to put the scans in boxes so they are not padded.

I decided I also wanted my parsing routine (which I named 'get') to be
idempotent. This would let me use parsed or unparsed data on the
command line -- if it was parsed already, 'get' would leave it alone.

get=: {{
if. -.'literal'-:datatype y do. y return. end.
s=. getscan;._2 rplc&(',';' ';(LF,'---');LF,'!---') y,'!'
{:"1 s   assert. (i.#s) -: ;{."1 s
}}

digits=: ".@([ -. -.)&(~.":i.10)

getscan=: {{
   (id=. digits 0{::lines); coords=. __&".@>@}. lines=. (<;._2 y)-.a:
}}

I could have made get and getscan a little simpler, by ignoring the
reported scan number. But I was working on this puzzle late at night
and it was easy for me to make mistakes.

The next problem was to piece scans together to form the complete list
of beacons (using the coordinate system of the scanner #0).

There's a variety of approaches which could have been used here. Mine was this:

(a) I would measure the distance between each pair of *beacons*
reported by each scanner. The distance between any beacon pair was
guaranteed to be fixed for every scanner which included both of those
beacons.

(b) For each pair of *scanners*, I would find and count the beacon
distance lists which they had in common. Scanners which were closer
together should have more beacons in common with each other than
scanners which were farther apart.

Looking at the data, I saw that most scanners had at least one other
scanner which reported 67 or 68 of the same beacon distances, the next
most frequent commonality was 17 or 18 of the same beacon

Re: [Jprogramming] Advent of Code Day 19

2022-01-09 Thread &#x27;Michael Day&#x27; via Programming


Chat really,  but I think it still belongs here.

I've just had another look at the performance stats for day 19. The numbers
solving parts 1 & 2 are 15420 and 236, respectively., at the time of 
typing.
Weird - once you've done part 1,  there's hardly anything further to do 
in part 2 !

Perhaps it was so obvious that nobody bothered.

Still wondering how "cross" is defined.

Meanwhile,  I've only just got unstuck on day 23 part 1 - horribly 
inefficient,  but it
eventually worked  - only to discover that all the bespoke hard-wired 
code fitting
that peculiar layout is rendered pretty useless as they've changed it 
for part 2.
Hopefully,  there might be fewer degrees of freedom since the hall still 
has only 11
positions,  but there'll be many more moves to a solution.  Part 1 
already needed 31
"moves" (either shifting one or two cells) and over 1.5 million 
states.   (I didn't spot

any heuristic for filtering.)

I'll go back to the Listener Crossword, piano and or TV for the rest of 
this evening!


Cheers,

Mike

On 09/01/2022 10:45, Raul Miller wrote:

Here's a better 'relori', in my opinion:

NB. y: scans from two scanners
relori=: {{
   sigs=: signature each y
   upsigs=: 0-.~(~. #~ 2 = #/.~) ;~.@,each sigs
   masks=: (*  wrote:

https://adventofcode.com/2021/day/19

Like a variety of my work on previous days, my code here is rather
bulky. Did I mention that Advent of Code was something of a bad habit
for me?

Anyways, here, not only is the code bulky, even the sample data is bulky.

Basically, for this puzzle, we were given a bunch of coordinates
beacons reported by a small set of scanners. These coordinates
contained three "flaws":

(1) They used a coordinate system which was centered on the scanner --
not a universal coordinate system.

(2) Each scanner had limited range, so no single scan had locations
for all beacons.

(3) Each scanner had an undetermined orientation.

Luckily for us, each probe "originally" had the same coordinate
system, and each probe's rotations were multiples of 90 degrees along
each axis. So there were only 24 possible orientations for each
scanner.

And, sample data looked like this:

sample=:{{)n
--- scanner 0 ---
404,-588,-901
528,-643,409
-838,591,734
390,-675,-793
-537,-823,-458
-485,-357,347
-345,-311,381
-661,-816,-575
-876,649,763
-618,-824,-621
553,345,-567
474,580,667
-447,-329,318
-584,868,-557
544,-627,-890
564,392,-477
455,729,728
-892,524,684
-689,845,-530
423,-701,434
7,-33,-71
630,319,-379
443,580,662
-789,900,-551
459,-707,401

--- scanner 1 ---
686,422,578
605,423,415
515,917,-361
-336,658,858
95,138,22
-476,619,847
-340,-569,-846
567,-361,727
-460,603,-452
669,-402,600
729,430,532
-500,-761,534
-322,571,750
-466,-666,-811
-429,-592,574
-355,545,-477
703,-491,-529
-328,-685,520
413,935,-424
-391,539,-444
586,-435,557
-364,-763,-893
807,-499,-711
755,-354,-619
553,889,-390

--- scanner 2 ---
649,640,665
682,-795,504
-784,533,-524
-644,584,-595
-588,-843,648
-30,6,44
-674,560,763
500,723,-460
609,671,-379
-555,-800,653
-675,-892,-343
697,-426,-610
578,704,681
493,664,-388
-671,-858,530
-667,343,800
571,-461,-707
-138,-166,112
-889,563,-600
646,-828,498
640,759,510
-630,509,768
-681,-892,-333
673,-379,-804
-742,-814,-386
577,-820,562

--- scanner 3 ---
-589,542,597
605,-692,669
-500,565,-823
-660,373,557
-458,-679,-417
-488,449,543
-626,468,-788
338,-750,-386
528,-832,-391
562,-778,733
-938,-730,414
543,643,-506
-524,371,-870
407,773,750
-104,29,83
378,-903,-323
-778,-728,485
426,699,580
-438,-605,-362
-469,-447,-387
509,732,623
647,635,-688
-868,-804,481
614,-800,639
595,780,-596

--- scanner 4 ---
727,592,562
-293,-554,779
441,611,-461
-714,465,-776
-743,427,-804
-660,-479,-426
832,-632,460
927,-485,-438
408,393,-506
466,436,-512
110,16,151
-258,-428,682
-393,719,612
-211,-452,876
808,-476,-593
-575,615,604
-485,667,467
-680,325,-822
-627,-443,-432
872,-547,-609
833,512,582
807,604,487
839,-516,451
891,-625,532
-652,-548,-490
30,-46,-14
}}

There will be a quiz later.  (Ok, maybe not...)

So, first thing we need here is a mechanism to parse this into
something J can handle. And, it's not obvious here, but the number of
beacons reported by each scanner was not the same. This means we need
to put the scans in boxes so they are not padded.

I decided I also wanted my parsing routine (which I named 'get') to be
idempotent. This would let me use parsed or unparsed data on the
command line -- if it was parsed already, 'get' would leave it alone.

get=: {{
if. -.'literal'-:datatype y do. y return. end.
s=. getscan;._2 rplc&(',';' ';(LF,'---');LF,'!---') y,'!'
{:"1 s   assert. (i.#s) -: ;{."1 s
}}

digits=: ".@([ -. -.)&(~.":i.10)

getscan=: {{
   (id=. digits 0{::lines); coords=. __&".@>@}. lines=. (<;._2 y)-.a:
}}

I could have made get and getscan a little simpler, by ignoring the
reported scan number. But I was working on this puzzle late at night
and it was easy for me to make mistakes.

The next problem was to piece scans together to form the

Re: [Jprogramming] Advent of Code Day 19

2022-01-10 Thread &#x27;Michael Day&#x27; via Programming

Thanks for this and for the previously undefined "cross" in another post.
I now see why I got 48 rotations rather than 24 - I hadn't taken on board
that all scanners used the "same" coord system,  which others have 
interpreted

as all using the same parity.

You mentioned looking for 67 or 68 of the same beacon distances.  My 
criterion
was >: 66,  iirc,  since 12 matching distinct points would have 66 = 
11.12%2 pairs of

non-zero distances.

My routine ("newexam" - exam for "examine",  and new because the old one 
didn't work)
was slightly faster than yours with the earlier "relori";  changing to 
this revised one,
just below,  halves the time of a19,  and slightly reduces the space 
used.  Both of your

versions use somewhat less space:

ts =:   6!:2 , 7!:2@]   NB.time & space

   100 ts'#~.newexam scdata'   NB. MD
0.054425904 303264
   100 ts'a19 scdata'   NB. RM - earlier vn of relori
0.063075894 271488
   100 ts'a19 scdata'   NB. RM - revised vn of relori
0.036779334 245376

Mike

On 09/01/2022 10:45, Raul Miller wrote:

Here's a better 'relori', in my opinion:

NB. y: scans from two scanners
relori=: {{
   sigs=: signature each y
   upsigs=: 0-.~(~. #~ 2 = #/.~) ;~.@,each sigs
   masks=: (*  wrote:

https://adventofcode.com/2021/day/19

Like a variety of my work on previous days, my code here is rather
bulky. Did I mention that Advent of Code was something of a bad habit
for me?

Anyways, here, not only is the code bulky, even the sample data is bulky.

Basically, for this puzzle, we were given a bunch of coordinates
beacons reported by a small set of scanners. These coordinates
contained three "flaws":

(1) They used a coordinate system which was centered on the scanner --
not a universal coordinate system.

(2) Each scanner had limited range, so no single scan had locations
for all beacons.

(3) Each scanner had an undetermined orientation.

Luckily for us, each probe "originally" had the same coordinate
system, and each probe's rotations were multiples of 90 degrees along
each axis. So there were only 24 possible orientations for each
scanner.

And, sample data looked like this:

sample=:{{)n
--- scanner 0 ---
404,-588,-901
528,-643,409
-838,591,734
390,-675,-793
-537,-823,-458
-485,-357,347
-345,-311,381
-661,-816,-575
-876,649,763
-618,-824,-621
553,345,-567
474,580,667
-447,-329,318
-584,868,-557
544,-627,-890
564,392,-477
455,729,728
-892,524,684
-689,845,-530
423,-701,434
7,-33,-71
630,319,-379
443,580,662
-789,900,-551
459,-707,401

--- scanner 1 ---
686,422,578
605,423,415
515,917,-361
-336,658,858
95,138,22
-476,619,847
-340,-569,-846
567,-361,727
-460,603,-452
669,-402,600
729,430,532
-500,-761,534
-322,571,750
-466,-666,-811
-429,-592,574
-355,545,-477
703,-491,-529
-328,-685,520
413,935,-424
-391,539,-444
586,-435,557
-364,-763,-893
807,-499,-711
755,-354,-619
553,889,-390

--- scanner 2 ---
649,640,665
682,-795,504
-784,533,-524
-644,584,-595
-588,-843,648
-30,6,44
-674,560,763
500,723,-460
609,671,-379
-555,-800,653
-675,-892,-343
697,-426,-610
578,704,681
493,664,-388
-671,-858,530
-667,343,800
571,-461,-707
-138,-166,112
-889,563,-600
646,-828,498
640,759,510
-630,509,768
-681,-892,-333
673,-379,-804
-742,-814,-386
577,-820,562

--- scanner 3 ---
-589,542,597
605,-692,669
-500,565,-823
-660,373,557
-458,-679,-417
-488,449,543
-626,468,-788
338,-750,-386
528,-832,-391
562,-778,733
-938,-730,414
543,643,-506
-524,371,-870
407,773,750
-104,29,83
378,-903,-323
-778,-728,485
426,699,580
-438,-605,-362
-469,-447,-387
509,732,623
647,635,-688
-868,-804,481
614,-800,639
595,780,-596

--- scanner 4 ---
727,592,562
-293,-554,779
441,611,-461
-714,465,-776
-743,427,-804
-660,-479,-426
832,-632,460
927,-485,-438
408,393,-506
466,436,-512
110,16,151
-258,-428,682
-393,719,612
-211,-452,876
808,-476,-593
-575,615,604
-485,667,467
-680,325,-822
-627,-443,-432
872,-547,-609
833,512,582
807,604,487
839,-516,451
891,-625,532
-652,-548,-490
30,-46,-14
}}

There will be a quiz later.  (Ok, maybe not...)

So, first thing we need here is a mechanism to parse this into
something J can handle. And, it's not obvious here, but the number of
beacons reported by each scanner was not the same. This means we need
to put the scans in boxes so they are not padded.

I decided I also wanted my parsing routine (which I named 'get') to be
idempotent. This would let me use parsed or unparsed data on the
command line -- if it was parsed already, 'get' would leave it alone.

get=: {{
if. -.'literal'-:datatype y do. y return. end.
s=. getscan;._2 rplc&(',';' ';(LF,'---');LF,'!---') y,'!'
{:"1 s   assert. (i.#s) -: ;{."1 s
}}

digits=: ".@([ -. -.)&(~.":i.10)

getscan=: {{
   (id=. digits 0{::lines); coords=. __&".@>@}. lines=. (<;._2 y)-.a:
}}

I could have made get and getscan a little simpler, by ignoring the
reported scan number. But I was working on this puzzle late at night
and it was easy for me to make mistakes.

The next problem was to piece scans together to form the

Re: [Jprogramming] Advent of Code Day 21

2022-01-11 Thread &#x27;Michael Day&#x27; via Programming

I think it's easier to post my code than to try answering your question.
I've run successfully this in a new session, so I think it's 
self-contained.


Apologies for the verbose code - it's as I wrote it,  and I haven't 
attempted

to polish it for presentation here.  The function "part2" , not shown here,
was the one I wrote before I remembered there were three throws for
each turn!   I would have preferred to deal with both players in a double-
go,  but gave up.  I do of course realise that there's a lot of 
reduplicated

code for player 2 - it would have been neater to move the code to an
ecternal function,  but I didn't!

Here it is - I hope it's not too opaque.

m10 =: 10&|&.<:   NB. modulo function for origin 1

die3   =:    ~. /:~,(1 2 3 +/])^:2 ]1 2 3
ctdie3 =:    #/.~/:~,(1 2 3 +/])^:2 ]1 2 3

part2a =: 3 : 0
21 part2a y
:
cts =. 1   $ 1
'pos1 pos2' =. 2 1 $ y
'scr1 scr2' =. 2 1 $ 0
tgt  =. x
wins =. 0 0
turns=. 0
ndie3=. # die3
while. #cts do.
   NB. player 1
   turns =. >: turns
   pos1  =. m10 , pos1 +/ die3
   cts   =. ,cts <.@*/ ctdie3
   scr1  =. pos1 + ndie3 # scr1
   pscr  =. pos1,. scr1,. ndie3#pos2,. scr2
   cts   =. pscr +//. cts
   'pos1 scr1 pos2 scr2' =. |: pscr =. ~. pscr
   if. +/ win1=. tgt <: scr1 do.
  i1   =. I. win1
  wins =. wins + 2 {. +/ i1{cts
echo 'new 1 wins at turn '; turns; wins
  cts  =. cts#~ -. win1
  pscr =. pscr#~-. win1
  'pos1 scr1 pos2 scr2' =. |: ~. pscr
   end.
   NB. player 2
   turns =. >: turns
   pos2  =. m10 , pos2 +/ die3
   cts   =. ,cts <.@*/ ctdie3
   scr2  =. pos2 + ndie3 # scr2
   pscr  =. (pos2,. scr2),.~ ndie3#pos1,. scr1
   cts   =. pscr +//. cts
   'pos1 scr1 pos2 scr2' =. |: pscr =. ~. pscr
   if. +/ win2=. tgt <: scr2 do.
  i2   =. I. win2
  wins =. wins + _2 {. +/ i2{cts
echo 'new 2 wins at turn '; turns; wins
  cts  =. cts#~ -. win2
  pscr =. pscr#~-. win2
  'pos1 scr1 pos2 scr2' =. |: ~. pscr
   end.
end.
turns; wins
)

Cheers,

Mike

On 11/01/2022 00:17, Raul Miller wrote:

Your 10&|&.<: is probably more comprehensible than my 11 |&.<:

But for part B, how did you handle the smearing of scores that
resulted from those new positions and counts?

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Parsing {{ }}

2022-01-11 Thread &#x27;Michael Day&#x27; via Programming
Thanks, Bob - yes,  I do know.  Ian gave up hoping to keep J901 
compatible with my iOS 11,  later iOS 12.
My iPad is too old to support the later versions of iOS which support 
his J901 app. Liz (my email
address's other half!)  does have it on her iPad,  but I don't want to 
take over her tablet!


(Sorry - my first post had "J902" in Ian's J app;  should have been J901.)

So - I'll keep on not taking the tablets.

Cheers,

Mike

On 11/01/2022 16:23, 'robert therriault' via Programming wrote:

Hi Mike,

You may not know, but there is a new J app that Ian Clark has developed called 
J901 (although it is running a version of J903 I believe) that supports {{ }}

You can find it in the app store for the iPad or the iPhone. The interface is 
slightly different, but it is really good.

Cheers, bob


On Jan 11, 2022, at 07:34, 'Mike Day' via Programming 
 wrote:

Oh well.  I thought you might have test-bedded these forms in J before moving 
to C, Henry, in which case there might have been a readymade J script!

As for Raul’s suggestion,  that’s fine,  but, in as far as I have copied across 
to J701,  just typing the verb’s name in the session reveals the n : 0 ... ) 
form.  Essentially,  this leads to amending the J903 script,  which rather 
defeats the purpose.  I haven’t use nested ddefs.

Anyway,  I’ve got a little way into writing a basic parser which will suffice.

Thanks,

Mike

Sent from my iPad


On 11 Jan 2022, at 14:42, Henry Rich  wrote:

There is nothing I know of that does what {{ }} does.  But Raul's idea is pretty 
close.  As he notes, it fails for nested {{ }} (there is much code that expects 
the result of 5!:5 <'explicitname' to have the form m : string, but nested {{ 
}} seemed OK).

Henry Rich


On 1/11/2022 9:19 AM, Raul Miller wrote:
If you avoid nested {{ }} blocks, 5!:5 would do this.

In other words, this works:

   mean=: {{ (+/ % #) y}}
   5!:5<'mean'
3 : '(+/ % #) y'

But this would be useless for your purposes:

   mean=: {{ {{x + y}} {{u/}} {{x % y}} {{#y}} }}
   5!:5<'mean'
3 : '{{ x + y }}  {{ u/ }}  {{ x % y }}  {{ #y }}  '

FYI,


--
Raul

On Tue, Jan 11, 2022 at 4:25 AM 'Mike Day' via Programming
 wrote:

For Henry I expect: as I share code between J903 on the laptop and J701 on this 
iPad,  I’ve been avoiding the use of {{ }} objects.  (My iPad can’t support 
Ian’s new J902.)

But I was just wondering about adding a routine to the J701 start.ijs script to 
parse a J903 script translating direct definitions to their earlier 
equivalents.  And then I thought there might already be native J code to do 
this.

So: do I need to invent this wheel?

Thanks,

Mike

Sent from my iPad
--
For information about J forums see http://www.jsoftware.com/forums.htm

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


--
This email has been checked for viruses by AVG.
https://www.avg.com

--
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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Advent of Code Day 22

2022-01-12 Thread &#x27;Michael Day&#x27; via Programming
I thought I'd try running this code,  but it failed on parse.  Must have 
been my data, I thought,

so I tried parse sample,  which is defined in the following script.

   parse sample
|assertion failure
|   7=#t-._ __

I'm running J903-a,  same as Raul, I think,  under Windows 11, which is 
different,  but shouldn't

be relevant:

   JVERSION
Engine: j903/j64avx2/windows
Release-a: commercial/2021-12-16T15:15:09
Library: 9.03.08
Qt IDE: 1.9.5/5.15.2(5.15.2)
Platform: Win 64
Installer: J903 install
InstallPath: c:/d/j903
Contact: www.jsoftware.com

It's at the end of my own script for day 22,  so I doubt any of my 
definitions get in the way.


Weird

Mike




On 11/01/2022 22:21, Raul Miller wrote:

https://adventofcode.com/2021/day/22

The day 22 puzzle was about "rebooting the reactor".

Here, we have a sequence of steps which consist of turning on, or off,
a rectangular cuboid in our coordinate system. In this puzzle each
x,y,z coordinate value was referred to as a cube.

s=: sample=:{{)n
on x=-20..26,y=-36..17,z=-47..7
on x=-20..33,y=-21..23,z=-26..28
on x=-22..28,y=-29..23,z=-38..16
on x=-46..7,y=-6..46,z=-50..-1
on x=-49..1,y=-3..46,z=-24..28
on x=2..47,y=-22..22,z=-23..27
on x=-27..23,y=-28..26,z=-21..29
on x=-39..5,y=-6..47,z=-3..44
on x=-30..21,y=-8..43,z=-13..34
on x=-22..26,y=-27..20,z=-29..19
off x=-48..-32,y=26..41,z=-47..-37
on x=-12..35,y=6..50,z=-50..-2
off x=-48..-32,y=-32..-16,z=-15..-5
on x=-18..26,y=-33..15,z=-7..46
off x=-40..-22,y=-38..-28,z=23..41
on x=-16..35,y=-41..10,z=-47..6
off x=-32..-23,y=11..30,z=-14..3
on x=-49..-5,y=-3..45,z=-29..18
off x=18..30,y=-20..-8,z=-3..13
on x=-41..9,y=-7..43,z=-33..15
on x=-54112..-39298,y=-85059..-49293,z=-27449..7877
on x=967..23432,y=45373..81175,z=27513..53682
}}

At the start of this process, every cube in the reactor is off.

Our part A puzzle asked us how many cubes would be on with values _50
.. 50 for x, y and z.

Simple enough:

use=: parse;._2

parse=:{{
   f=. 'on'-:2{.y
   good=. y e.'-',":i.10
   t=. f,__ ". good #inv good # y
   assert. 7=#t-._ __
   assert. 1e9 >>./t
   assert. _1e9 <<./t
}}

thru=: [ ~.@, <. + i.@(+*)@-~

a22=:{{
Y=. _51 >. 51 <. use y
r=. 101 101 101 $0
for_op. Y do.
  'f x0 x1 y0 y1 z0 z1'=. op
  I=. >,{(x0 thru x1);(y0 thru y1);z0 thru z1
  I=. 50+(#~ 51 -.@e."1 |) I
  r=. f I} r
   end.
   +/,r
}}

Here, I clipped coordinate values to the range _51 .. 51, found all
values inside the possibly clipped coordinates, stripped out any
references to cubes with a coordinate magnitude of 51 and set or reset
a bit for each remaining cube reference. Simple, straightforward, and
totally inadequate for part B.

Part B removes the constraint on range, and with the puzzle data
requires us to count a number of cubes in the vicinity of 1e15.

For part B, my approach was to track cuboid regions that were 'on',
and split them into smaller cuboids when this intersected with an
'off' cuboid. Conceptually, this might result in up to 26 new cuboids
(for example on -30..30,-30..30,-30..30 followed by off
-10..10,-10..10,-10..10). But, usually, we had partial overlaps which
created fewer fragments.

I could not think of a quick way of identifying arbitrary overlaps
when computing the sum I needed for the result here, so I decided I
should also split cuboids when 'on' regions overlapped.

Anyways, this meant I was storing the locations of the corners of the
cubes, and lead me to this implementation:

b22=:{{
   Y=. use y
   r=. i.0 3 2
   for_op. Y do.
 'f x0 x1 y0 y1 z0 z1'=. op
  t=. r I."1"2 (x0,x1),(y0,y1),:z0,z1
  F=.i.0
  ok=. (0 0 e."2 t)+.2 2 e."2 t
  if. 0 e. ok do.
splits=.((-.ok)#r) split((<:x0),x1),((<:y0),y1),:(<:z0),z1
assert. 3=#$splits
assert. 3 2-:}.$splits
r=.(ok#r),splits
  end.
  if. f do.
r=.r,((<:x0),x1),((<:y0),y1),:(<:z0),z1
  end.
   end.
   cubesum r
}}

NB. sum the volumes of all cuboids
cubesum=: {{
   +/*/"1-~/"1 x:y
}}

NB. split cubes in x based on cube y
split=: {{
   ;x <@split2"2 y
}}

NB. split a cube by splitting coordinates
NB. discard split cubes where all coordinates are discarded
split2=: {{
   (([: +./"1 {."1) # }."1) >>,{x <@ahand"1 y
}}

NB. coordinate range x into pieces which exclude y
NB. retain the part of y within x
NB. prefix each segment with 1 (keep) or 0 (discard)
ahand=:{{
   'LO HI'=. x
   'lo hi'=. y
   assert. hi >: LO
   assert. HI >: lo
   lo=. lo >. LO
   hi=. h i<. HI
   ((lo~:LO),LO,lo);(0,lo,hi);(hi~:HI),hi,HI
}}

I do not remember what 'ahand' meant.

Is there a better way?

If I had assigned to each statement a "sequence order" such that
statements with a higher order would override statements with a lower
order, and constructed a conflict map for each statement, I might have
been able to sum expanding subregions 'directly' based on a
topological sort (or perhaps using some variant on graph traversal)
which put minimum complexity items first. I say this because of the
hint Mike Day pro

Re: [Jprogramming] Advent of Code Day 22

2022-01-12 Thread &#x27;Michael Day&#x27; via Programming

Whoa!  I've just tried
   use sample
which did work ok.

Mea Culpa

Mike

On 12/01/2022 13:24, 'Michael Day' via Programming wrote:
I thought I'd try running this code,  but it failed on parse.  Must 
have been my data, I thought,

so I tried parse sample,  which is defined in the following script.

   parse sample
|assertion failure
|   7=#t-._ __

I'm running J903-a,  same as Raul, I think,  under Windows 11, which 
is different,  but shouldn't

be relevant:

   JVERSION
Engine: j903/j64avx2/windows
Release-a: commercial/2021-12-16T15:15:09
Library: 9.03.08
Qt IDE: 1.9.5/5.15.2(5.15.2)
Platform: Win 64
Installer: J903 install
InstallPath: c:/d/j903
Contact: www.jsoftware.com

It's at the end of my own script for day 22,  so I doubt any of my 
definitions get in the way.


Weird

Mike




On 11/01/2022 22:21, Raul Miller wrote:

https://adventofcode.com/2021/day/22

The day 22 puzzle was about "rebooting the reactor".

Here, we have a sequence of steps which consist of turning on, or off,
a rectangular cuboid in our coordinate system. In this puzzle each
x,y,z coordinate value was referred to as a cube.

s=: sample=:{{)n
on x=-20..26,y=-36..17,z=-47..7
on x=-20..33,y=-21..23,z=-26..28
on x=-22..28,y=-29..23,z=-38..16
on x=-46..7,y=-6..46,z=-50..-1
on x=-49..1,y=-3..46,z=-24..28
on x=2..47,y=-22..22,z=-23..27
on x=-27..23,y=-28..26,z=-21..29
on x=-39..5,y=-6..47,z=-3..44
on x=-30..21,y=-8..43,z=-13..34
on x=-22..26,y=-27..20,z=-29..19
off x=-48..-32,y=26..41,z=-47..-37
on x=-12..35,y=6..50,z=-50..-2
off x=-48..-32,y=-32..-16,z=-15..-5
on x=-18..26,y=-33..15,z=-7..46
off x=-40..-22,y=-38..-28,z=23..41
on x=-16..35,y=-41..10,z=-47..6
off x=-32..-23,y=11..30,z=-14..3
on x=-49..-5,y=-3..45,z=-29..18
off x=18..30,y=-20..-8,z=-3..13
on x=-41..9,y=-7..43,z=-33..15
on x=-54112..-39298,y=-85059..-49293,z=-27449..7877
on x=967..23432,y=45373..81175,z=27513..53682
}}

At the start of this process, every cube in the reactor is off.

Our part A puzzle asked us how many cubes would be on with values _50
.. 50 for x, y and z.

Simple enough:

use=: parse;._2

parse=:{{
   f=. 'on'-:2{.y
   good=. y e.'-',":i.10
   t=. f,__ ". good #inv good # y
   assert. 7=#t-._ __
   assert. 1e9 >>./t
   assert. _1e9 <<./t
}}

thru=: [ ~.@, <. + i.@(+*)@-~

a22=:{{
    Y=. _51 >. 51 <. use y
    r=. 101 101 101 $0
    for_op. Y do.
  'f x0 x1 y0 y1 z0 z1'=. op
  I=. >,{(x0 thru x1);(y0 thru y1);z0 thru z1
  I=. 50+(#~ 51 -.@e."1 |) I
  r=. f I} r
   end.
   +/,r
}}

Here, I clipped coordinate values to the range _51 .. 51, found all
values inside the possibly clipped coordinates, stripped out any
references to cubes with a coordinate magnitude of 51 and set or reset
a bit for each remaining cube reference. Simple, straightforward, and
totally inadequate for part B.

Part B removes the constraint on range, and with the puzzle data
requires us to count a number of cubes in the vicinity of 1e15.

For part B, my approach was to track cuboid regions that were 'on',
and split them into smaller cuboids when this intersected with an
'off' cuboid. Conceptually, this might result in up to 26 new cuboids
(for example on -30..30,-30..30,-30..30 followed by off
-10..10,-10..10,-10..10). But, usually, we had partial overlaps which
created fewer fragments.

I could not think of a quick way of identifying arbitrary overlaps
when computing the sum I needed for the result here, so I decided I
should also split cuboids when 'on' regions overlapped.

Anyways, this meant I was storing the locations of the corners of the
cubes, and lead me to this implementation:

b22=:{{
   Y=. use y
   r=. i.0 3 2
   for_op. Y do.
 'f x0 x1 y0 y1 z0 z1'=. op
  t=. r I."1"2 (x0,x1),(y0,y1),:z0,z1
  F=.i.0
  ok=. (0 0 e."2 t)+.2 2 e."2 t
  if. 0 e. ok do.
    splits=.((-.ok)#r) split((<:x0),x1),((<:y0),y1),:(<:z0),z1
assert. 3=#$splits
assert. 3 2-:}.$splits
    r=.(ok#r),splits
  end.
  if. f do.
    r=.r,((<:x0),x1),((<:y0),y1),:(<:z0),z1
  end.
   end.
   cubesum r
}}

NB. sum the volumes of all cuboids
cubesum=: {{
   +/*/"1-~/"1 x:y
}}

NB. split cubes in x based on cube y
split=: {{
   ;x <@split2"2 y
}}

NB. split a cube by splitting coordinates
NB. discard split cubes where all coordinates are discarded
split2=: {{
   (([: +./"1 {."1) # }."1) >>,{x <@ahand"1 y
}}

NB. coordinate range x into pieces which exclude y
NB. retain the part of y within x
NB. prefix each segment with 1 (keep) or 0 (discard)
ahand=:{{
   'LO HI'=. x
   'lo hi'=. y
   assert. hi >: LO
   assert. HI >: lo
   lo=. lo >. LO
   hi=. h i<. HI
   ((lo~:LO),LO,lo);(0,lo,hi);(hi~:HI),hi,HI
}}

I do not remember what 'ahand' meant.

Is there a better way?

I

Re: [Jprogramming] Advent of Code Day 22

2022-01-12 Thread &#x27;Michael Day&#x27; via Programming

OK, sorry about the alarm just now.  I'd misunderstood how to apply parse.

FWIW,  I ran b22 and my "reboota" on "sample" which I'd called 
"bigexsteps" (big example steps)
and on my bespoke data set,  called "data" for some reason. "reboot2a" 
is a much slimmer version
of "reboot2".  reboot2 performs similarly to b22,  while reboot2a 
outperforms both.


NB. "timer" just reports the uncorrected runtime.

   timer'b22 bigexsteps'    NB. I've removed the top and bottom lines 
of boxing here

│0.2990036│39769202357779│

   timer'<.reboot2 bigexsteps'
│0.43900299│39769202357779│

   timer'reboot2a bigexsteps'
│0.11200714│39769202357779│

   ts
6!:2 , 7!:2@]

   ts'reboot2a bigexsteps'
0.1109503 3138464

   ts'reboot2 bigexsteps'
0.412317 3038368

   ts'b22 bigexsteps'
0.3132198 19483040

   ts'reboot2a data'
1.8453615 612

   timer'reboot2 data'    NB. 69... seconds - too slow for ts
│1 9.0530014│1.2372642e15│

   ts'b22 data'
|attention interrupt: b22  NB. I gave up waiting
|   b22 data

   timer'b22 data'   NB. 62.6... seconds
│1 2.6440048│1237264238382479│

I've just spotted that the 43325 intermediate cuboids produced for my 
data have only 6954
unique members,  which suggests I could have worked with counts and ~.  
, perhaps reducing

the time and space further.

Cheers,

Mike


On 11/01/2022 22:21, Raul Miller wrote:

https://adventofcode.com/2021/day/22

The day 22 puzzle was about "rebooting the reactor".

Here, we have a sequence of steps which consist of turning on, or off,
a rectangular cuboid in our coordinate system. In this puzzle each
x,y,z coordinate value was referred to as a cube.

s=: sample=:{{)n
on x=-20..26,y=-36..17,z=-47..7
on x=-20..33,y=-21..23,z=-26..28
on x=-22..28,y=-29..23,z=-38..16
on x=-46..7,y=-6..46,z=-50..-1
on x=-49..1,y=-3..46,z=-24..28
on x=2..47,y=-22..22,z=-23..27
on x=-27..23,y=-28..26,z=-21..29
on x=-39..5,y=-6..47,z=-3..44
on x=-30..21,y=-8..43,z=-13..34
on x=-22..26,y=-27..20,z=-29..19
off x=-48..-32,y=26..41,z=-47..-37
on x=-12..35,y=6..50,z=-50..-2
off x=-48..-32,y=-32..-16,z=-15..-5
on x=-18..26,y=-33..15,z=-7..46
off x=-40..-22,y=-38..-28,z=23..41
on x=-16..35,y=-41..10,z=-47..6
off x=-32..-23,y=11..30,z=-14..3
on x=-49..-5,y=-3..45,z=-29..18
off x=18..30,y=-20..-8,z=-3..13
on x=-41..9,y=-7..43,z=-33..15
on x=-54112..-39298,y=-85059..-49293,z=-27449..7877
on x=967..23432,y=45373..81175,z=27513..53682
}}

At the start of this process, every cube in the reactor is off.

Our part A puzzle asked us how many cubes would be on with values _50
.. 50 for x, y and z.

Simple enough:

use=: parse;._2

parse=:{{
   f=. 'on'-:2{.y
   good=. y e.'-',":i.10
   t=. f,__ ". good #inv good # y
   assert. 7=#t-._ __
   assert. 1e9 >>./t
   assert. _1e9 <<./t
}}

thru=: [ ~.@, <. + i.@(+*)@-~

a22=:{{
Y=. _51 >. 51 <. use y
r=. 101 101 101 $0
for_op. Y do.
  'f x0 x1 y0 y1 z0 z1'=. op
  I=. >,{(x0 thru x1);(y0 thru y1);z0 thru z1
  I=. 50+(#~ 51 -.@e."1 |) I
  r=. f I} r
   end.
   +/,r
}}

Here, I clipped coordinate values to the range _51 .. 51, found all
values inside the possibly clipped coordinates, stripped out any
references to cubes with a coordinate magnitude of 51 and set or reset
a bit for each remaining cube reference. Simple, straightforward, and
totally inadequate for part B.

Part B removes the constraint on range, and with the puzzle data
requires us to count a number of cubes in the vicinity of 1e15.

For part B, my approach was to track cuboid regions that were 'on',
and split them into smaller cuboids when this intersected with an
'off' cuboid. Conceptually, this might result in up to 26 new cuboids
(for example on -30..30,-30..30,-30..30 followed by off
-10..10,-10..10,-10..10). But, usually, we had partial overlaps which
created fewer fragments.

I could not think of a quick way of identifying arbitrary overlaps
when computing the sum I needed for the result here, so I decided I
should also split cuboids when 'on' regions overlapped.

Anyways, this meant I was storing the locations of the corners of the
cubes, and lead me to this implementation:

b22=:{{
   Y=. use y
   r=. i.0 3 2
   for_op. Y do.
 'f x0 x1 y0 y1 z0 z1'=. op
  t=. r I."1"2 (x0,x1),(y0,y1),:z0,z1
  F=.i.0
  ok=. (0 0 e."2 t)+.2 2 e."2 t
  if. 0 e. ok do.
splits=.((-.ok)#r) split((<:x0),x1),((<:y0),y1),:(<:z0),z1
assert. 3=#$splits
assert. 3 2-:}.$splits
r=.(ok#r),splits
  end.
  if. f do.
r=.r,((<:x0),x1),((<:y0),y1),:(<:z0),z1
  end.
   end.
   cubesum r
}}

NB. sum the volumes of all cuboids
cubesum=: {{
   +/*/"1-~/"1 x:y
}}

NB. split cubes in x based on cube y
split=: {{
   ;x <@split2"2 y
}}

NB. split a cube by splitting coordinates
NB. discard split cubes where all coordinates are discarded
split2=: {{
   (([: +./"1 {."1) # }."1) >>,{x <@ahand"1 y
}}

NB. coordinate range x into pieces which exclude y
NB. retain the part of y within x
NB. prefix each segment with 1 (keep) or 0 (dis

Re: [Jprogramming] Advent of Code Day 22

2022-01-12 Thread &#x27;Michael Day&#x27; via Programming
I've now modified reboot2a - it's now reboot2b (!) - to accumulate 
volumes of repeated intersection cuboids.
It performs significantly better than reboot2a,  whose time & space I 
reported earlier,  in the msg below this one:



    ts'reboot2b data'    NB. ~6x faster, ~5x smaller

0.229044 1.25469e6


ts'reboot2a data'

1.87207 6.1e6


Perhaps the code is worth sharing given its better performance;  I think 
it's self-contained apart from


the reference to the data filename.  It's reasonably aligned given a 
fixed-width font:



NB. start of script

load 'strings'
load'files'

readsteps =: ". 
@:(-.&'xyz=')@:(rplc&('-';'_'))@:(rplc&('..';','))@:(rplc&('off';'0'))@:(rplc&('on';'1')) 
every


NB. The input format with on/off x X y Y z Z is a pain - on reflection,  
it might have been better to

NB.   reorder to on/off x y z X Y Z ,  but I didn't .

data =: readsteps dtb each rawdata =: LF cut raw =: fread 
'~user/aoc2122.txt'

rawdata =: >rawdata

NB. The input is a numeric array with 7 columns output by readsteps
reboot2b =: 3 : 0
ops    =. y
NB. Initialise with first cuboid and its volume
cubs   =. ,: }. {.ops  NB. I assume first step is an "on" - no 
sense otherwise

vols   =. ,volop1 {.ops
size   =: 1    NB. count of number of intersection cuboids
'onoffs ops' =. (}.@:({."1);}."1) ops
for_op. }. ops do. NB. work on next operation
   'onoff onoffs' =. ({.;}.)onoffs
   ok =. op&doescuboidisx cubs NB. boolean array of 
existing cuboids intersecting with current one
   newcubs    =. op&cuboidisx6  ok#cubs    NB. For those that do,  
find those intersections, also cuboids
   newvols    =. -(*ok#vols)*volop1 newcubs    NB. assign opposite sign 
to next generation of cuboids
   if. onoff do.   NB. Only need to add the 
current cuboid if it's "on"

  newcubs    =. op, newcubs
  newvols    =. newvols,~ volop1 op
   end.
   cubs   =. cubs, newcubs NB. add new cuboids to 
the saved list

   vols   =. cubs +//. vols, newvols   NB. }
   cubs   =. ~. cubs   NB. }These two lines 
accumulate the volumes of identical cuboids
   NB. } ... This saves 
time and space


   size =: size >. # vols  NB. diagnostic
end.
CUBSB =: cubs  NB. diagnostic
+/vols NB. answer
)

NB. volumes of an m x 6 or m x 7 array of coords {on or off} xX yY zZ
volop1 =: 3 : '(_2 */@:>:@(-~/\) ])"1  ] _6{."1 y'

NB.   Function returns boolean answering: does cuboid x intersect with 
list of cuboids y,

NB.  x & y in {on/off} xX yY zZ format
doescuboidisx =: 3 : 0
:
pqr =. x{~ -6 4 2 NB. negative indices allow the on/off boolean to 
be present or absent

PQR =. x{~ -5 3 1
A   =. pqr >."1 y{~"1 ] -6 4 2
B   =. PQR <."1 y{~"1 ] -5 3 1
A */"1 @: <: B
)

NB.   Reasonably efficient function to return diagonal bounds of 
intersection

NB. of cuboids x & y which are in {on/off} xX yY zZ format
cuboidisx6 =: 3 : 0
:

pqr =. x{~ -6 4 2 NB. negative indices allow the on/off boolean to be 
present or absent

PQR =. x{~ -5 3 1
A   =. pqr >."1 y{~"1 ] -6 4 2
B   =. PQR <."1 y{~"1 ] -5 3 1
0 3 1 4 2 5{"1 A,.B
)

NB. end of script

My earlier remarks about the signs of intersections of different levels 
or generations still apply,
but it wasn't necessary to break up a contributing cuboid into 3 
sub-cuboids;  we only need to

keep the intersections which are always cuboids.

I'm still clueless on day 23, part 2.  I'm going to have to ignore 
Raul's next post on that one!


Mike

On 12/01/2022 14:02, 'Michael Day' via Programming wrote:
OK, sorry about the alarm just now.  I'd misunderstood how to apply 
parse.


FWIW,  I ran b22 and my "reboota" on "sample" which I'd called 
"bigexsteps" (big example steps)
and on my bespoke data set,  called "data" for some reason. "reboot2a" 
is a much slimmer version
of "reboot2".  reboot2 performs similarly to b22,  while reboot2a 
outperforms both.


NB. "timer" just reports the uncorrected runtime.

   timer'b22 bigexsteps'    NB. I've removed the top and bottom lines 
of boxing here

│0.2990036│39769202357779│

   timer'<.reboot2 bigexsteps'
│0.43900299│39769202357779│

   timer'reboot2a bigexsteps'
│0.11200714│39769202357779│

   ts
6!:2 , 7!:2@]

   ts'reboot2a bigexsteps'
0.1109503 3138464

   ts'reboot2 bigexs

Re: [Jprogramming] Advent of Code Day 22

2022-01-13 Thread &#x27;Michael Day&#x27; via Programming
This seems not to have appeared in the forum,  so I'm sending again. 
Apologies if it turns out to be a duplicate.


I've now modified reboot2a - it's now reboot2b (!) - to accumulate 
volumes of repeated intersection cuboids.
It performs significantly better than reboot2a,  whose time & space I 
reported earlier,  in the msg below this one:



    ts'reboot2b data'    NB. ~6x faster, ~5x smaller

0.229044 1.25469e6


ts'reboot2a data'

1.87207 6.1e6


Perhaps the code is worth sharing given its better performance;  I think 
it's self-contained apart from


the reference to the data filename.  It's reasonably aligned given a 
fixed-width font:



NB. start of script

load 'strings'
load'files'

readsteps =: ". 
@:(-.&'xyz=')@:(rplc&('-';'_'))@:(rplc&('..';','))@:(rplc&('off';'0'))@:(rplc&('on';'1')) 
every


NB. The input format with on/off x X y Y z Z is a pain - on reflection,  
it might have been better to

NB.   reorder to on/off x y z X Y Z ,  but I didn't .

data =: readsteps dtb each rawdata =: LF cut raw =: fread 
'~user/aoc2122.txt'

rawdata =: >rawdata

NB. The input is a numeric array with 7 columns output by readsteps
reboot2b =: 3 : 0
ops    =. y
NB. Initialise with first cuboid and its volume
cubs   =. ,: }. {.ops  NB. I assume first step is an "on" - no 
sense otherwise

vols   =. ,volop1 {.ops
size   =: 1    NB. count of number of intersection cuboids
'onoffs ops' =. (}.@:({."1);}."1) ops
for_op. }. ops do. NB. work on next operation
   'onoff onoffs' =. ({.;}.)onoffs
   ok =. op&doescuboidisx cubs NB. boolean array of 
existing cuboids intersecting with current one
   newcubs    =. op&cuboidisx6  ok#cubs    NB. For those that do,  
find those intersections, also cuboids
   newvols    =. -(*ok#vols)*volop1 newcubs    NB. assign opposite sign 
to next generation of cuboids
   if. onoff do.   NB. Only need to add the 
current cuboid if it's "on"

  newcubs    =. op, newcubs
  newvols    =. newvols,~ volop1 op
   end.
   cubs   =. cubs, newcubs NB. add new cuboids to 
the saved list

   vols   =. cubs +//. vols, newvols   NB. }
   cubs   =. ~. cubs   NB. }These two lines 
accumulate the volumes of identical cuboids
   NB. } ... This saves 
time and space


   size =: size >. # vols  NB. diagnostic
end.
CUBSB =: cubs  NB. diagnostic
+/vols NB. answer
)

NB. volumes of an m x 6 or m x 7 array of coords {on or off} xX yY zZ
volop1 =: 3 : '(_2 */@:>:@(-~/\) ])"1  ] _6{."1 y'

NB.   Function returns boolean answering: does cuboid x intersect with 
list of cuboids y,

NB.  x & y in {on/off} xX yY zZ format
doescuboidisx =: 3 : 0
:
pqr =. x{~ -6 4 2 NB. negative indices allow the on/off boolean to 
be present or absent

PQR =. x{~ -5 3 1
A   =. pqr >."1 y{~"1 ] -6 4 2
B   =. PQR <."1 y{~"1 ] -5 3 1
A */"1 @: <: B
)

NB.   Reasonably efficient function to return diagonal bounds of 
intersection

NB. of cuboids x & y which are in {on/off} xX yY zZ format
cuboidisx6 =: 3 : 0
:

pqr =. x{~ -6 4 2 NB. negative indices allow the on/off boolean to be 
present or absent

PQR =. x{~ -5 3 1
A   =. pqr >."1 y{~"1 ] -6 4 2
B   =. PQR <."1 y{~"1 ] -5 3 1
0 3 1 4 2 5{"1 A,.B
)

NB. end of script

My earlier remarks about the signs of intersections of different levels 
or generations still apply,
but it wasn't necessary to break up a contributing cuboid into 3 
sub-cuboids;  we only need to

keep the intersections which are always cuboids.

I'm still clueless on day 23, part 2.  I'm going to have to ignore 
Raul's next post on that one!


Mike

On 12/01/2022 14:02, 'Michael Day' via Programming wrote:
OK, sorry about the alarm just now.  I'd misunderstood how to apply 
parse.


FWIW,  I ran b22 and my "reboota" on "sample" which I'd called 
"bigexsteps" (big example steps)
and on my bespoke data set,  called "data" for some reason. "reboot2a" 
is a much slimmer version
of "reboot2".  reboot2 performs similarly to b22,  while reboot2a 
outperforms both.


NB. "timer" just reports the uncorrected runtime.

   timer'b22 bigexsteps'    NB. I've removed the top and bottom lines 
of boxing here

│0.2990036│39769202357779│

   timer'<.reboot2 bigexsteps'
│0.43900299│39769202357779│

   timer'reboot2a bigexsteps'

Re: [Jprogramming] Advent of Code Day 24

2022-01-14 Thread &#x27;Michael Day&#x27; via Programming
We haven't seen part 2 yet,  of course... there could be another sting 
in the tail,

judging by the number of part 2 finishers in the stats!

Mike

On 14/01/2022 14:01, Raul Miller wrote:

On Fri, Jan 14, 2022 at 4:15 AM 'Mike Day' via Programming
 wrote:

My data has, of course, 14 inp ops; to my surprise these were ops 0
18 36 ...  Tabulating the data as 14 boxes of 18 ops, the ops and
first arguments were identical in each box; I think this applies to
all those second arguments which were registers.  The only
differences were between corresponding integer constants.

Hmm... yes.

#~._18 <@((<<<4 5 _3)&{)\ ];._2 input
1

This will allow me to scrap a lot of useless code.

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Advent of Code Day 24

2022-01-14 Thread &#x27;Michael Day&#x27; via Programming
Apologies to Eugene Nonko - I'd overlooked your remarks about the great 
similarity between the

14 segments.  Plagiarism rules!

Mike

On 13/01/2022 23:34, Eugene Nonko wrote:

I did solve it, but I didn't use J for that one.

I wrote a translator in Perl that converted their assembly into C. C,
because it's easier to read, plus I thought that some brute forcing might
be required and compiled C will run faster than interpreting their assembly.

While studying that generated C code I discovered that there are 14 very
similar segments, each segment belonging to one of two types. Segments of
one type increased the value of z and segments of another type decreased
the value of z given some condition. That allowed me to reduce the size of
search space from 9^14 (too large) to 9^7 (very manageable).

-- Eugene

On Thu, Jan 13, 2022 at 2:17 PM Raul Miller  wrote:


https://adventofcode.com/2021/day/24

I have not completed the day 24 puzzle.

The day 24 puzzle has a sequence of instructions representing a
calculation to verify a model number (and conceptually enable features
based on that model number -- though part A of the puzzle does not
provide any details about that).

The processing unit performs integer calculations, and has four
registers: W, X, Y and Z.

There are six instructions, one which inputs a digit of the model
number, an add instruction, a multiply instruction, an integer
division instruction, a modulo instruction and an equals instruction.

The input instruction always inputs to register W (and is the only
instruction used to update W). The div instruction always divides by 1
or 26. The modulo instruction is always used to find a remainder
modulo 26 (and always only operates on positive values, or 0 for the
numerator). The multiply instruction seems to always multiply by 0 or
powers of 26. (To load a value into a register, the register is first
multiplied by 0 and then has another value added to it.)

A certain amount of simplifications are possible using math identities
and range constraints. But I do not have much more that's useful to
say until I've found a way of solving the puzzle.

Here's a snapshot of where I'm at, trying to work through these issues
(looks sloppy with a proportionally spaced font):

...
digit13NB. W234=: W216 inp 13   [ 1 thru 9
0  NB. X235=: X223 mul 0[ 0
add Z228 Y232  NB. X236=: X235 add Z233 [ 9 thru 5520918021
mod 26|Z233 26 NB. X237=: X236 mod 26   [ 0 thru 25
mul <.Z210%26 X223 NB. Z238=: Z233 div 26   [ 0 thru 212343000
add X237 _4NB. X239=: X237 add -4   [ _4 thru 21
eql X239 digit13   NB. X240=: X239 eql W234 [ 0 thru 1
eql X240 0 NB. X241=: X240 eql 0[ 0 thru 1
0  NB. Y242=: Y232 mul 0[ 0
25 NB. Y243=: Y242 add 25   [ 25
mul 25 X241NB. Y244=: Y243 mul X241 [ 0 thru 25
add Y244 1 NB. Y245=: Y244 add 1[ 1 thru 26
mul <.Z228%26 Y245 NB. Z246=: Z238 mul Y245 [ 0 thru 5520918000
0  NB. Y247=: Y245 mul 0[ 0
digit13NB. Y248=: Y247 add W234 [ 1 thru 9
add digit13 7  NB. Y249=: Y248 add 7[ 8 thru 16
mul Y249 X241  NB. Y250=: Y249 mul X241 [ 0 thru 16
add Z246 Y250  NB. Z251=: Z246 add Y250 [ 0 thru 5520918016

I am currently working on some tree unification mechanisms (maximum
common subtree elimination to let me better inspect the partially
resolved calculations).

I believe Eugene Nonko has solved this one, though I do not know if he
found J useful in his approach.

FYI,

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


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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Advent of Code Day 24

2022-01-15 Thread &#x27;Michael Day&#x27; via Programming
Yes, that's my guess.  I called them p q & r,  and found that p = 1 or 
26 as q is positive or negative.


So: having got one machine to run 14 times on different values of p q r 
and the previous Z, I worked back
from Z = 0 output on the 14th machine,  saving which W & Zs gave rise to 
0,  then using those Zs on the

13th machine 

But that gave me potentially a lot of Zs - I haven't counted - so I then 
worked forward from the first machine
finding only 1452 14-ples giving rise to a final zero.  Very messy - I 
didn't really code it - but it worked!


Haven't got round to part 2 yet.

Mike

On 15/01/2022 18:12, Raul Miller wrote:

Actually, another caution here: it might be that other people's puzzle
inputs used a different block structure from my block structure.

Probably not -- it's probably the case that only my A, B and C values
differed for different people. But .. that's just "probably" because I
haven't looked at other people's puzzle input.

FYI,



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Advent of Code Day 24

2022-01-15 Thread &#x27;Michael Day&#x27; via Programming
... and it's one of those "days" that part 2 is ridiculously easy cf 
part 1 !!!


Mike

On 15/01/2022 21:15, 'Michael Day' via Programming wrote:
Yes, that's my guess.  I called them p q & r,  and found that p = 1 or 
26 as q is positive or negative.


So: having got one machine to run 14 times on different values of p q 
r and the previous Z, I worked back
from Z = 0 output on the 14th machine,  saving which W & Zs gave rise 
to 0,  then using those Zs on the

13th machine 

But that gave me potentially a lot of Zs - I haven't counted - so I 
then worked forward from the first machine
finding only 1452 14-ples giving rise to a final zero.  Very messy - I 
didn't really code it - but it worked!


Haven't got round to part 2 yet.

Mike

On 15/01/2022 18:12, Raul Miller wrote:

Actually, another caution here: it might be that other people's puzzle
inputs used a different block structure from my block structure.

Probably not -- it's probably the case that only my A, B and C values
differed for different people. But .. that's just "probably" because I
haven't looked at other people's puzzle input.

FYI,






--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Advent of Code Day 24

2022-01-16 Thread &#x27;Michael Day&#x27; via Programming
OK - your approach is far more efficient than mine!  I suspect you did 
what I had in mind, but

couldn't quite get that mind to produce.

I see that you (Raul) didn't bother with truncating divide towards 
zero.  In testing,  I fell foul of this,

and used
   divt =: {{ s * y <.@%~ | x   [ s =. * x }}
... but I think you're ok in the actual "program" as div only has 
positive input as far as I can see!


I've eventually turned my type-a-line-at-a-time procedure into a 
J-function,  with this result

in elapsed time:

   timer' 10#.(>./,:<./) program 14 '
   done forwards creating q
   done backwards creating r
   ++-+
   |32.4|9292891491 91811211611981|
   ++-+

A glance at Windows' Task Manager revealed usage of 3~ GB ,  while space 
(7!:2@])

showed 6.7!

(I'm still pleased with the performance of my solution to day 22, though!)

The slow forward search produces q,  a boxed array of all possible 
outcomes (Z values), at each of

the 14 steps:
   ({.~5<.#)each 3 {.q NB. everything aligns in fixed font
+-+-+---+
|0|5 6 7 8 9|142 168 194 220 246|
+-+-+---+
   3{.each _3 {.q
+--+--+--+
|64953057 76834433 88715809|64953048 76834424 88715800|64953058 76834434 
88715810|

+--+--+--+

In the quite slow backward sweep, from 14 to 1,  using q,  and the fact 
that 0 is the only required
value of the final set of q, we derive r,  a boxed array of possible W Z 
pairs:


   ({.~5<.#) each _5 {.}:r    NB. fixed font!  r has an extra empty 
element

+--++--+-++
|1 9110|1 236863|9 9110|8 350|1 13|
|1 9136|1 237539|9 9136|9 351|    |
|2 9110|2 236864|  | |    |
|2 9136|2 237540|  | |    |
|3 9110|3 236865|  | |    |
+--++--+-++

   ({.~5<.#) each 5 {.r
+---++-+--+-+
|9 0|1 13|8 350|1 9115|1 350|
|   |2 13|8 351|1 9141|1 351|
|   |    |9 350|2 9116|2 350|
|   |    |9 351|2 9142|2 351|
|   |    | |  |3 350|
+---++-+--+-+

Not quite done - we need to get those combinations of Ws at each stage 
which achieve Z=0 at
the last stage.  It works forward again.  Here,  it would examine W 
pairs 9 1 and 9 2 to find both
can produce values in 350 351,  then those triples 9 1 8, 9 1 9, ... 9 2 
9 compatible with 9115 ... 9142

and so on.  That step runs quite fast and in smallish space.

   ts' 10#.(>./,:<./) (,&< r) program 14 '   NB. running with r 
provided as input;  q not needed

q & r already done
q & r already done
1.25349 2.3815e6

Here's my J-version of the alu for one input-step:
   dodata18r1 =: 3 : 0
0 dodata18r1 y
:
'p q r' =. x    NB. W X Y aren't re-used
'W Z'   =. |: 2 {."1 y  NB. Z is possibly the output of a previous run
X =. W ~: q + 26 | Z    NB. q e. [_14 15] ... _14 _12 _10 _7 _4 _2 _1 10 
11 12 13 15

    NB. X is 0 or 1
Z =. Z divt p   NB. p is 1 or 26  ... 1 <==> q > 0, 26 <==> q < 0
Z + X * r + W + Z * 25  NB. r e. [2 13]   ...   2   3   4  6  7  9 11 12 13
)

I couldn't see quite what it was doing,  though the business with 26 
does strongly hint

at something to do with the Roman alphabet.

That's not too bad,  but "program" is pretty ugly stuff.  I won't share 
that code unless

begged to do so!

Cheers,

Mike




On 15/01/2022 18:10, Raul Miller wrote:

I've got this solved now,

Eugene Nonko put me on the right path here.

The trick, from my perspective, was to convert the machine code into
executable J.  And, to ensure that I could use J's dimensionality to
manage multiple tests at the same time.

Specifically, I parameterized the three "block specific" values as C,
B and A (I initially used D for digits, but later spelled that out).

parse=: {{
   blks=: _18]\];._2 input
   C=: ". 6}."1]4 {"_1 blks
   B=: ". 6}."1]5 {"_1 blks
   A=: ". 6}."1]_3{"_1 blks
}}

digits=:14#<1+i.9

BLOCK=: {{
   W=: x{::digits
   X7=: W~:/(x{B)+26|y
   if.X7 -:&$ y do.
 ((W+x{A)*X7)+(1+25*X7)*<.y%x{C
   else.
 ((W+x{A)*X7)+(1+25*X7)*"_1 _<.y%x{C
   end.
}}

Here, x indicated the digit number (0 for the leftmost digit, 13 for
the right most digit), and y indicated the result from the previous
block (0 initially).

The if statement was because I could not figure out how to build a
rank statement that worked consistently for all of my example cases.
I'm not sure if this was due to my limited imagination, or if it's an
artifact of J's rank conjunction. Maybe I'll circle back on that
later...

With this in place, the ALU became:

ALU=: BLOCK/@((i.-14),0)

Except, of course, my laptop is not powerful enough to handle this
expression because there's too many possible digits.

But it's rather quick to run through all the possibilities to
constrain the search space:

plausible=: {{
   hist=:#need assert.0

Re: [Jprogramming] Advent of Code Day 25

2022-01-16 Thread &#x27;Michael Day&#x27; via Programming

Also pretty crude,  in one self-contained routine,  "move" .
It was fast and slim enough for its purpose!

   $data
137 139
   ts'move data'
0.0623268 1.69075e6
   timer'move data'
+-+---+
|0.0669937|412|
+-+---+

move =: 3 : 0 NB. long-winded but never mind
_ move y  NB. default to running until no moves available
:
'm n' =. mn =. $ c   =. y -."1 ' '
ixc   =. i. mn NB. work on indices
enbs  =. ,1 |."1 ixc   NB. ravel all east neighbours
snbs  =. ,1 |.   ixc   NB.   and all south
ie    =. I. e  =. ,c = '>' NB. ie holds all east indices
is    =. I. s  =. ,c = 'v' NB. and is all south ...
iall  =. ie, is    NB. list of all occupied slots
old   =. /:~iall   NB. for checking end condition
ct    =. 1 NB. counter - could have used x
while. 0 <: x =. <: x do.
   emvok =. iall -.@e.~ newie =. ie { enbs   NB. check occupancy of all 
of easts' neighbours
   ie    =. (ie#~ -.emvok) , newie#~ emvok   NB. crude derivation of 
the new east positions

   iall  =. ie, is   NB. reset list of all posns

NB.   similar steps for south facing set
   smvok =. iall -.@e.~ newis =. is { snbs
   is    =. (is#~ -.smvok) , newis#~ smvok
   iall  =. /:~ ie, is   NB. only needs sort for 
quick comparison with old


   if. iall -: old do. break. end.

   ct    =. >: ct  NB.  ready for next loop
   old   =. iall
end.
NB. c =. mn $ 'v' is } '>' ie } , mn$'.' NB. not needed, but 
reformat from indices to graphic

ct NB. return the count
)

For part 2,  I was a bit miffed to be told I needed another star,  the 
one I missed for day 23 part 2.

<<  NB. my NB.s  ...
NB. The experimental antenna control console lights up again:
NB. Energy source detected.
NB. Integrating energy source from device "sleigh keys"...done.
NB. Installing device drivers...done.
NB. Recalibrating experimental antenna...done.
NB. Boost strength due to matching signal phase: 1 star
NB. Only 49 stars to go.
NB. You don't have enough stars to boost the signal, though. You need 1 
more.

>>

Ah well.  Cheers,

Mike

On 15/01/2022 18:24, Raul Miller wrote:

https://adventofcode.com/2021/day/25

This is the end of the advent of code series for last year. It was a
quick wrap up.

Here, the puzzle was about waiting for sea cucumbers to get out of the
way so you could land your submarine and launch santa's sleigh (which
makes about as much sense as santa, but whatever...).

sample=:];._2 {{)n
v...>>.vv>
.vv>>.vv..

.>v>...v
v>>.>.v.

v>v.vv.v..

.>>..v...

.vv..>.>v.
v.v..>>v.v
v..v.>
}}

For this, I just built a quick step function, ran it until it stopped
and counted the steps:

stepEast=: {{
   '>' stepHalf y
}}

stepSouth=: {{
   |:'v' stepHalf|:y
}}

stepHalf=: {{
   b=. }:"1 (x,'.') E."1 y,.{."1 y
   I=. I.,b
   I2=. I.,_1 |."1 b
   ($y)$ '.' I} x I2} ,y
}}

step=: {{
   N=:N+1
   chk=. #/.~,'.>v',,y
   r=.stepSouth r0=.stepEast y
   assert. chk-:#/.~,'.>v',,r0
   assert. chk-:#/.~,'.>v',,r
}}

a25=: {{
   N=:0
   step^:_ y
   N
}}

Crude, of course, but perhaps appropriately silly?

Anyways... that wraps it up. The second part of the puzzle was to
finish up all the other days and then remotely start the sleigh.

FYI,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Advent of Code Day 23

2022-01-23 Thread &#x27;Michael Day&#x27; via Programming

Chat really - sorry!

An update on my progress on this so-far elusive problem for me, part2 at 
least.


I _nearly_ got the right answer - tweaking the code resulted in being 
able to reach
a termination of the tree-search - too high! - another tweak - too low! 
further

tweaks - explosion of search space.

Then I noticed: NB. I MISSED THIS POINT!

NB. Once an amphipod stops moving in the hallway, it will stay in that 
spot until it can move into a room. (That


NB. is, once any amphipod starts moving, any other amphipods currently 
in the hallway are locked in place and


NB. will not move again until they can move fully into a room.)


I'd completely overlooked this restriction - my amphipods could all move 
in the hallway ...



Back to the J-board.


I'm avoiding looking at Raul's solution,  still hoping to find one for 
myself!



READ THE PAPER BEFORE TACKLING THE QUESTIONS!



Cheers,


Mike



On 13/01/2022 01:19, Raul Miller wrote:

https://adventofcode.com/2021/day/23

For day 23, we needed to solve a lazy shrimp problem.

We had a room and hallway setup (view in monospace font):

sample=:];._2 {{)n
#
#...#
###B#C#B#D###
   #A#D#C#A#
   #
}}

Ignore spaces and '#' (wall) characters. The important locations are
marked with . or letters ABCD.

Actually, also we partially ignore the '.' characters which align
vertically here with a letter -- those locations are significant but
must always be left open.

The horizontal section of dots was the 'hallway' and the sections
initially containing letters were 'rooms'.

The task involved moving each of the letters (the shrimp) into the
rooms so that the shrimp would be arranged in alphabetical order, left
to right with these constraints (stated slightly differently in the
puzzle):

(1) Each shrimp could only move twice
(2) each move must change the shrimp's horizontal position
(3) no shrimp could pass through another shrimp
(4) shrimp cannot break through the walls

also each move cost of distance * 10^'ABCD' i. shrimpId (we use
manhattan distance here, because of rule 4).

So the task was to to do all this while minimizing the total energy
cost expended by the shrimp.

For part B, the task description was the same except that the rooms
were extended with this for the middle of each room (with these
additional shrimp):

   #D#C#B#A#
   #D#B#A#C#

My initial approach here was to solve the puzzle by hand and write
some code to tally the costs. That got me part A, but part B was too
complicated for me to see the solution. It was not until a few days
ago that I managed to solve part B (but I did use my initial solution
to help debug my part B implementation (running the solver against the
part A data set)).

To actually solve this, I wound up using an A* algorithm. For part B
this still took about half an hour (and part A took significantly
longer, ironically).

A* is a highly serial approach, but has the advantage of eliminating
significant parts of some search spaces. Instead of doing a breadth
first or depth first search (which could be parallelized), A* uses a
queue of partial results which are sorted in lowest cost order.

I also maintained a "lowest cost" array for each visited state, and
when revisiting such a state I only proceed if my new cost is lower
than my old cost.

Also,

(a) I precalculated for each shrimp, a characterization of its two
moves (a coordinate pair, with a 0 marking the undetermined part of
each move), and

(b) I assigned the total cost of a shrimp's moves to the move into the
hallway (this meant that the second move was always cheaper than any
first move, which reflects the issue that blocking the hallway would
tend to drive up the costs of other moves).

Other than that, my code is nothing special -- actually, it's rather
verbose. But because a complete test of the code is time consuming and
I did not have any further use for it, I've left it in its crude "just
got it working" state. I apologize for the lack of readability and
lack of relevant abstraction here, but I'm feeling lazy.

(That said, the code echos every intermediate state as it's being
processed, and would probably run faster if I removed that.)

The first part -- a23 -- sets up a batch of globals to be used by the solver:

a23=: {{
bounds=: $y
roomsN=: _4]\I.,y e.'ABCD'
hallN =: I.,(y='.')>"1 +./y e.'ABCD'
doorsN=: ({.roomsN) - {:$y NB. room positions in hallN
boardC=: ((#hallN)#'.'),(,y) ([-.-.)'ABCD'
locationsN=: ($y)#:hallN,,roomsN
assert. locationsN -:&# boardC
mask=: (-.y e.'# ')*(1~:i.#y)+./'#'=2{y
show=: (+./"1 mask)#($mask)$(,mask)#inv ([ assert@('literal'-:datatype))@]
move =: +./\.'ABCD'~:"1 roomsN {,y
roomsM=: ($roomsN)$(-#,roomsN){.i.#boardC
agenda=: move <@(,.&0,0,.|.)@#"1&|: roomsM
done=: ((#hallN)#'.'),,($roomsN)$'ABCD'
seen=: ,:done [ costs=: ,9
boardC 0 allpaths agenda
}}

The solver is... not pretty. Conceptually, various parts of this could
have been

Re: [Jprogramming] Advent of Code Day 23

2022-02-02 Thread &#x27;Michael Day&#x27; via Programming

More chat on this old thread.

Finished at last!  50 stars for something or other...
It took quite a lot of tweaking to build in the restrictions to the 
"amphipods' " movements that I'd
mentioned in my msg of 23Jan, below. I'd overlooked the paragraph 
(originally without J's NB. as
Raul pointed out. The NB.s arise from the way I process the results of 
text-capture from a browser

in order to embed them in a J script.)

The problem remained difficult for me probably because I didn't find a 
decent data structure.
FWIW,  each "state" consisted of one item of cost with 7 hall cells + 8 
room cells for part 1,  or
with  7 + 16 room cells for part 2.  It might well be better to have 7 
hall cells + 4 room objects,
or even, possibly,  7 + 4 donors rooms + 4 sink rooms,  but I haven't 
explored these ideas.


The original approach considered single cell moves only,  ie those 
between adjacent pairs of
room cells,  between any outermost room cell and its two neighbouring 
hall cells, and between
pairs of hall cells;  distances traversed were either one or two units,  
the latter where the

transient hall cell immediately outside a room was crossed.

After my epiphany,  I dispensed with hall-hall movements altogether.  
However,  it was still
tricky to limit hall-room and room-room movements according to the 
current occupancy of

the rooms.

The code is far too verbose and loopy to be worth posting!

I'll now have a look at Raul Miller's solution,  way below in this 
post,  and see what I missed.


And then back to Project Euler to see if any current problems are 
approachable!


Thanks for your patience,

Mike

On 23/01/2022 19:02, 'Michael Day' via Programming wrote:

Chat really - sorry!

An update on my progress on this so-far elusive problem for me, part2 
at least.


I _nearly_ got the right answer - tweaking the code resulted in being 
able to reach
a termination of the tree-search - too high! - another tweak - too 
low! further

tweaks - explosion of search space.

Then I noticed: 

   NB. I MISSED THIS POINT!
   NB. Once an amphipod stops moving in the hallway, it will stay in 
that spot until it can move into a room. (That
NB. is, once any amphipod starts moving, any other amphipods currently 
in the hallway are locked in place and

NB. will not move again until they can move fully into a room.)

I'd completely overlooked this restriction - my amphipods could all 
move in the hallway ...


Back to the J-board.

I'm avoiding looking at Raul's solution,  still hoping to find one for 
myself!



READ THE PAPER BEFORE TACKLING THE QUESTIONS!



Cheers,


Mike



On 13/01/2022 01:19, Raul Miller wrote:

https://adventofcode.com/2021/day/23

For day 23, we needed to solve a lazy shrimp problem.

We had a room and hallway setup (view in monospace font):

sample=:];._2 {{)n
#
#...#
###B#C#B#D###
   #A#D#C#A#
   #
}}

Ignore spaces and '#' (wall) characters. The important locations are
marked with . or letters ABCD.

Actually, also we partially ignore the '.' characters which align
vertically here with a letter -- those locations are significant but
must always be left open.

The horizontal section of dots was the 'hallway' and the sections
initially containing letters were 'rooms'.

The task involved moving each of the letters (the shrimp) into the
rooms so that the shrimp would be arranged in alphabetical order, left
to right with these constraints (stated slightly differently in the
puzzle):

(1) Each shrimp could only move twice
(2) each move must change the shrimp's horizontal position
(3) no shrimp could pass through another shrimp
(4) shrimp cannot break through the walls

also each move cost of distance * 10^'ABCD' i. shrimpId (we use
manhattan distance here, because of rule 4).

So the task was to to do all this while minimizing the total energy
cost expended by the shrimp.

For part B, the task description was the same except that the rooms
were extended with this for the middle of each room (with these
additional shrimp):

   #D#C#B#A#
   #D#B#A#C#

My initial approach here was to solve the puzzle by hand and write
some code to tally the costs. That got me part A, but part B was too
complicated for me to see the solution. It was not until a few days
ago that I managed to solve part B (but I did use my initial solution
to help debug my part B implementation (running the solver against the
part A data set)).

To actually solve this, I wound up using an A* algorithm. For part B
this still took about half an hour (and part A took significantly
longer, ironically).

A* is a highly serial approach, but has the advantage of eliminating
significant parts of some search spaces. Instead of doing a breadth
first or depth first search (which could be parallelized), A* uses a
queue of partial results which are sorted in lowest cost order.


[Jprogramming] test

2022-02-15 Thread &#x27;Michael Day&#x27; via Programming

Please ignore

--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Advent of Code Day 23

2022-02-15 Thread &#x27;Michael Day&#x27; via Programming
[I sent this yesterday (Monday) evening to Chat,  but it hasn't appeared 
in my inbox or in the Chat Archive, so
I tried again today - same non-result.  My trivial test msg appeared in 
Programming but not in Chat just now.
So: Apologies for sending rather stale stuff to the Programming Forum 
and also if we end up with two or

three copies!]

Following Raul's suggestion in the Programming Forum,  copied just 
below, I've been trying to tidy up
my code to make it somewhat more presentable,  but there's quite a lot 
of it;  what with utility functions,
and comments on performance,  the script "aoc2123new.ijs" is nearly 600 
lines long.  So I've put it up on

my Google Drive for a while,  with this link:
https://drive.google.com/file/d/1-zhVqU6IREiMuSHPGVQkRbiFQM9rVvxZ/view?usp=sharing
I _think_ it's self-contained,  but might easily have overlooked something.

The main function is "part2" and most of the work is done in "doamp", 
acronym for

DO All Moves with optional Predecessors.

When trying this link, when logged out, my browser says - "preview not 
available" but makes it available

for download.

Rather surprisingly,  my fairly naive approach is faster than Raul's for 
both parts of the day 23

problem;  less surprisingly,  it appears to take considerably more space.

ALthough the main function is called part2,  it can solve both parts!   
Here are some extracts from

runtime diagnostics.

Sent in fixed width font!
NB. My part2 method for part1 data now runs in ~ 7.5 sec and max number 
of working states = 22553

NB.    timer'part2 13; data'
NB. ┌─┬─┐
NB. │1│1│
NB. └─┴─┘
NB. ┌─┬──┐
NB. │2│28│   NB. step number & number of states
NB. └─┴──┘
...
NB. ┌─┬─┐
NB. │7│22553│
NB. └─┴─┘
...
NB. ┌──┬┐
NB. │12│8818│
NB. └──┴┘
NB. ┌──┬─┐
NB. │ found target at cost │13520│
NB. └──┴─┘
NB. ┌──┬┐
NB. │13│1992│
NB. └──┴┘
NB. ┌─┬─┐
NB. │best found = │13520│
NB. └─┴─┘
NB. ┌─┬┐
NB. │7.6790009││
NB. └─┴┘

NB. Raul's method on part1 - run at similar time,  so runtime 
environment should be similar

NB.    timer'a23 q'[q=:>LF cut data
NB. ┌─┬┐
NB. │26.148003││
NB. └─┴┘
NB.    {.costs
NB. 13520

NB. space used much better for Raul ...
NB. 1 (7!:2@])  'part2 13; data'
...
NB. ┌─┬─┐
NB. │best found = │13522│
NB. └─┴─┘
NB. 52867104

NB.   1 (7!:2@]) 'a23 mikesdata'  NB. space for Raul's fn in part 1
NB. 2528384

NB. My part2 method for part2 data now runs in ~ 12 sec and max number 
of working states = 34338

NB.    timer'part2b 28; data2'
NB. ┌─┬─┐
NB. │1│1│
NB. └─┴─┘
...
NB. ┌─┬─┐
NB. │7│34338│
NB. └─┴─┘
...
NB. ┌──┬┐
NB. │27│1021│
NB. └──┴┘
NB. ┌──┬─┐
NB. │ found target at cost │48708│
NB. └──┴─┘
NB. ┌──┬───┐
NB. │28│708│
NB. └──┴───┘
NB. ┌─┬─┐
NB. │best found = │48708│
NB. └─┴─┘
NB. ┌──┬┐
NB. │12.186││
NB. └──┴┘

NB. Raul's method, b23, for my part 2 data - run at similar time, so 
runtime environment should be similar

NB.    timer'b23 mikesdata'
NB. ┌───┬┐
NB. │3 50.538002││
NB. └───┴┘
NB.    {.costs
NB. 48708
NB.    #costs
NB. 106541

NB. space used much better for Raul ...
NB. 1 (7!:2@])  'part2 28; data2'
...
NB. ┌──┬───┐
NB. │28│708│
NB. └──┴───┘
NB. ┌─┬─┐
NB. │best found = │48708│
NB. └─┴─┘
NB. 61575008
NB.    1 (7!:2@]) 'b23 mikesdata'
NB. 9098880

Sorry not to present more information in this note,  but the topic is 
rather stale,  so

apologies are perhaps also due for raking over its ashes!

Thanks,

Mike

On 02/02/2022 14:18, Raul Miller wrote:

My solution there was also quite verbose.

Golfing an implementation might be a worthwhile exercise.

Thanks,



On 02/02/2022 14:15, 'Michael Day' via Programming wrote:

More chat on this old thread.

Finished at last!  50 stars for something or other...
It took quite a lot of tweaking to build in the restrictions to the 
"amphipods' " movements that I'd
mentioned in my msg of 23Jan, below. I'd overlooked the paragraph 
(originally without J's NB. as
Raul pointed out. The NB.s arise from the way I process the results of 
text-capture from a browser

in order to embed them in a J script.)

The problem remained difficult for me probably because I didn't find a 
decent data structure.
FWIW,  each "state" consisted of one item of cost with 7 hall cells + 
8 room cells for part 1,  or
with  7 + 16 room cells for part 2.  It might well be better to have 7 
hall cells + 4 room objects,
or even, possibly,  7 + 4 donors rooms + 4 sink rooms,  but I haven't 
explored these ideas.

Re: [Jprogramming] polynomial division

2022-02-20 Thread &#x27;Michael Day&#x27; via Programming

Just checked on the laptop running J903:

Performance not too bad for largish orders,  even with extended type, 
albeit only

binomial coefficients:
   ts'1000 diva&binc 20'  NB. presumably overflow in binc
|NaN error: diva
|   d=.(ly{.x)    -&}.r*y
   ts'1000x diva&binc 20x'
0.2399954 1570560
   ts'1000x diva&binc 500x'
1.9407032 3000544
   ts'1000x div&binc 20x'
0.7021009 3948608
   ts'1000x div&binc 500x'
2.1598005 4815264

... and dbho still suffers a domain error for somewhat smaller inputs, 
such as here:

   ts'50 dbho&binc 20'
|domain error: dbho
|   (d{.x)    %.(2#d=.<./$M){.M=.y+/ .*y bq x

I forgot to demonstrate that the remainders work as hoped:

   E =. 1 5 10 10 7 4
   E {{ x - y mul x div y }} 1 2 1
0 0 0 0 2 3
   divlo
div&.:|.
   (|.E) {{ x - y mul x divlo y }} 1 2 1
3 2 0 0 0 0

Mike

On 20/02/2022 11:31, 'Mike Day' via Programming wrote:

This approach,  from my A-level Maths perhaps,  seems far too simple compared 
to that of the article,  but works, on this iPad running J701 (no, it can’t run 
Ian’s J902!),  including when dbho or dblo throws a domain error for, eg, 
dividing order 50 by order 30.  I haven’t tried in J903 on the laptop yet.

BTW,  I couldn’t understand why the article shows a remainder,
]q=. e dbho c 1 3 3 1
]r=.e-c t q 0 0 0 0 2 3
But I realised there’s a missing definition, eg E =. 1 5 10 10 7 4, with e 
replaced by E in the next 2 lines.

Anyway,

NB. binomial coefficients for (1+z)^y
binc =:  !~i.@>:

NB. x % y
div =: 3 : 0NB. similar result to Ken's dbho
:
q =. ''
yx=. y,:x
n =. 2 + x -&# y
while. n =. <: n do.
q  =. q, r =. %~/ {."1 yx
yx =. y,: }. -~/ yx * r,1
end.
q
)

divlo =: div&.:|.   NB. Like Ken's dblo

diva =: 3 : 0NB. a bit less elegant. Similar performance
:
q =. ''
n =. 2 + x -&# y
ly=. #y
while. n =. <: n do.
q =. q, r =. x %&{. y
if. |r do.
   d =. (ly{.x) -&}. r * y
   x =. d, ly}.x
else.
   x =. }. x
end.
end.
q
)
5 div&binc 3
1 2 1
5 div&binc 2
1 3 3 1

 ts
6!:2 , 7!:2@]
ts'50 diva&binc 10'
0.000554 9216
ts'50 div&binc 10'
0.000661 13824
ts'50 dbho&binc 10'
0.002024 211840
ts'50 dbho&binc 30'
|domain error: dbho
|   (d{.x)%.(2#d=.<./$M){.M=.y+/ .*y bq x

I slightly prefer div to diva.

Cheers,

Mike
Sent from my iPad


On 20 Feb 2022, at 03:46, Raul Miller  wrote:

https://code.jsoftware.com/wiki/Essays/Polynomial+Division

Iverson's method for polynomial division is elegant, but it's a bit
slow for large polynomials (order greater than 2000).

Does anyone have a more efficient approach? Or is this one of those
situations where it doesn't get any better?

Thanks,

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

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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] polynomial division

2022-02-20 Thread &#x27;Michael Day&#x27; via Programming

Bear in mind my later comments about performance on this laptop.
Either extended arithmetic or other tricks to deal with high exponents
are necessary in some cases.  And, of course, I didn't deal with edge
effects.  I've dealt with one such,  introducing assert.  , ie
   assert. 2 <: n =. 2 + x -&# y  ,
instead of the bare assignment for the number of loops.  I see that
dblo & dbhi do still yield results for denominator >&# numerator
which I'll think about.

Anyway,  would you,  Raul,  mind amending that article's comments on
the remainder with dbho,  introducing a definition of E and changing "e" 
to "E",
as I don't trust myself to get it right?!   As it stands the remainder 
should be 6#0  .


There's an article by Pascal Jasmin,  which might be relevant,  but I don't
understand it (yet!?) -
https://code.jsoftware.com/wiki/User:Pascal_Jasmin/A(2022)fast(2220)polynomial_division_algorithm#division_and_other_code

Cheers,

Mike


On 20/02/2022 15:34, Raul Miller wrote:

Very nice, thank you.

This took my code from me using jbreak during a division because I was
tired of starting at the hourglass to having that operation complete
nearly instantly.

Thanks again,


On Sun, Feb 20, 2022 at 6:31 AM 'Mike Day' via Programming
 wrote:
>
> This approach,  from my A-level Maths perhaps,  seems far too simple 
compared to that of the article,  but works, on this iPad running J701 
(no, it can’t run Ian’s J902!),  including when dbho or dblo throws a 
domain error for, eg, dividing order 50 by order 30. I haven’t tried in 
J903 on the laptop yet.

>
> BTW,  I couldn’t understand why the article shows a remainder,
> ]q=. e dbho c 1 3 3 1
> ]r=.e-c t q 0 0 0 0 2 3
> But I realised there’s a missing definition, eg E =. 1 5 10 10 7 4, 
with e replaced by E in the next 2 lines.

>
> Anyway,
>
> NB. binomial coefficients for (1+z)^y
> binc =:  !~i.@>:
>
> NB. x % y
> div =: 3 : 0    NB. similar result to Ken's dbho
> :
> q =. ''
> yx=. y,:x
> n =. 2 + x -&# y
> while. n =. <: n do.
>    q  =. q, r =. %~/ {."1 yx
>    yx =. y,: }. -~/ yx * r,1
> end.
> q
> )
>
> divlo =: div&.:|.   NB. Like Ken's dblo
>
> diva =: 3 : 0    NB. a bit less elegant. Similar performance
> :
> q =. ''
> n =. 2 + x -&# y
> ly=. #y
> while. n =. <: n do.
>    q =. q, r =. x %&{. y
>    if. |r do.
>   d =. (ly{.x) -&}. r * y
>   x =. d, ly}.x
>    else.
>   x =. }. x
>    end.
> end.
> q
> )
>    5 div&binc 3
> 1 2 1
>    5 div&binc 2
> 1 3 3 1
>
> ts
> 6!:2 , 7!:2@]
>    ts'50 diva&binc 10'
> 0.000554 9216
>    ts'50 div&binc 10'
> 0.000661 13824
>    ts'50 dbho&binc 10'
> 0.002024 211840
>    ts'50 dbho&binc 30'
> |domain error: dbho
> |   (d{.x)    %.(2#d=.<./$M){.M=.y+/ .*y bq x
>
> I slightly prefer div to diva.
>
> Cheers,
>
> Mike
> Sent from my iPad
>
>> On 20 Feb 2022, at 03:46, Raul Miller  wrote:
>>
>> https://code.jsoftware.com/wiki/Essays/Polynomial+Division
>>
>> Iverson's method for polynomial division is elegant, but it's a bit
>> slow for large polynomials (order greater than 2000).
>>
>> Does anyone have a more efficient approach? Or is this one of those
>> situations where it doesn't get any better?
>>
>> Thanks,
>>
>> --
>> Raul
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm


--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] polynomial division

2022-02-20 Thread &#x27;Michael Day&#x27; via Programming

I wrote binc as a monad,  just as a quick way of conjuring up
sets of binomial coefficients:

   binc 5
1 5 10 10 5 1

   3 binc 5 NB. does work, but not as intended!
1 3 3 1 0 0
NB. as does its commute:
   5 binc 3
1 5 10 10
... but again, not as I intended.

div is what does the division;  div&binc a,b just
does (binc a) div binc b


I wasn't particularly interested in the performance of binc,
as Raul was seeking a division algortithm,  and binc was
just easier than typing 1 5 10 10 5 1 or whatever.

I do agree that your definition improves on mine when it
matters,  eg
   ts'binc 500x'
0.0392271 460640
   ts'1, */\ 500x (- % >:@]) i.500x' NB. x=y for my examples
0.001463 504032

I suppose it's now worth investigating the performance of
div cf dbho and divlo cf dblo excluding the overhead of binc:

   'a b' =: binc 50 20
   a (dbho-:div) b
1
   ts'a div b'
1.21e_5 5952
   ts'a dbho b'
2.63e_5 6496
   a (dblo-:divlo) b
1
   ts'a divlo b'
1.06e_5 6976
   ts'a dblo b'
1.75e_5 6496

Thanks for pointing out the overheads imposed by binc,

Mike

On 20/02/2022 16:01, Hauke Rehr wrote:

On my machine, I get

   100 timespacex '1000x binc 500x'
0.101916 957376
   100 timespacex '1, */\ 1000x (- % >:@]) i.500x'
0.00247977 680320


Am 20.02.22 um 13:30 schrieb 'Michael Day' via Programming:

    ts'1000x div&binc 500x'
2.1598005 4815264





--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] polynomial division

2022-02-20 Thread &#x27;Michael Day&#x27; via Programming

Pas grand' chose -  the writer evidently meant to enter

   E =. 1 5 10 10 4 7
   ]q =. E dbho c
1 3 3 1
   ]r =. E - c t q
0 0 0 0 2 3

- or perhaps with capital Q & R rather than q & r -
... but it's clear enough with a bit of insight!

Cheers,

Mike

On 20/02/2022 16:15, Raul Miller wrote:

For some reason, when I was searching for jsoftware.com content on
polynomial division, the search did not turn up Pascal Jasmin's
article. It looks like Jasmin was focusing on speeding up extended
precision arithmetic, but I'll have to spend some time studying what
he wrote there.

Meanwhile, I'm not sure what you're asking for with respect to e and E
-- the division essay has an E already in the context of the dbho
example, doesn't it?

(I'm focusing on something else right now, and maybe overlooking
something obvious. If that's the case, please bear with me (and maybe
tell me what glaringly obvious thing it is that I'm ignoring).)

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] polynomial division

2022-02-20 Thread &#x27;Michael Day&#x27; via Programming
I suppose dyad |. !0 is better than dyad }.  by keeping the result in 
place.


Anyway,   although I agree that it seems attractive to ignore those zeros,
your get-around doesn't seem to apply!!! - unless I'm missing something.

I embedded an echo:
...
    if. 0={.y do. j=. j-i=. 0 i.~ 0=y
echo '0={.y';x;y
...

I encountered an error in this mickey mouse test:
   1 0 0 0 0 0 0 0 0 1 pDiv 0 0 0 1 0 1
┌─┬───┬───┐
│0={.y│1 0 0 0 0 0 0 0 0 1│0 0 0 1 0 1 0 0 0 0│
└─┴───┴───┘
┌─┬───┬───┐
│0={.y│0 0 0 0 0 0 0 1 0 0│0 0 0 1 0 1 0 0 0 0│
└─┴───┴───┘
|domain error: pDiv
|   q=.q,j    #0
but maybe these arguments aren't like those for pDiv in the Rosetta Code 
task.


This trick for my div is analogous to allowing for leading decimal zeros
in 1234 % 0.0001 in "ordinary" long division.  I wonder if it's what you
intended.

NB. x % y
div =: 3 : 0    NB. similar result to Ken's dbho
:
q =. ''
NB. allow for leading zeros in quotient
if. 0 = {. y do.
   j =. 0 i.~ 0 = y
   y =. j }. y
   x =. x, 0#~ >: j
end.
yx=. y,:x
assert. 2 <: n =. 2 + x -&# y
while. n =. <: n do.
   q  =. q, r =. %~/ {."1 yx
   yx =. y,: }. -~/ yx * r,1
end.
q
)

   1 2 3 4 div 0 0 0 1
1 2 3 4 0 0 0 0
1234 % 0.0001
1234

Anyway, my extra echo reports nothing when running this:
    cyclotomic >: i.1000
so I suspect that the check is not necessary here.

Mike

On 20/02/2022 16:35, Raul Miller wrote:

For what it's worth, here's what I was focusing on:

http://rosettacode.org/wiki/Cyclotomic_polynomial#J

As you can see, I altered your polynomial division algorithm --
there's enough zeros in the polynomials I was working with, there,
that iterating through them seemed unwise.

If there's any other significant improvements that you notice -- or
any errors which I overlooked, of course, please let me know!

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] polynomial division

2022-02-21 Thread &#x27;Michael Day&#x27; via Programming

Apologies for a mistake in my previous post, below.

This was where I said

   "This trick for my [function] div is analogous to allowing for
   leading decimal zeros
   in 1234 % 0.0001 in "ordinary" long division."

I'd forgotten that J's representation of polynomials is not the same as its
representation of numbers to some base;  the former has the zero power
leading (leftmost), whereas number representation has the highest power
leading.  My remark applies ok for the number representation but not
for polynomial coefficients.  In the latter case,  extra leading zeros 
add to

the power of the polynomial,  so their effect on a divisor is to DECREASE
the power of the result, the quotient.  I  haven't yet had time to correct
"div" to allow for this.

Also, I realise I'd misused "quotient" when I meant "divisor" in earlier
postings!

Not so cheerily,

Mike

On 20/02/2022 18:05, 'Michael Day' via Programming wrote:
I suppose dyad |. !0 is better than dyad }.  by keeping the result in 
place.


Anyway,   although I agree that it seems attractive to ignore those 
zeros,

your get-around doesn't seem to apply!!! - unless I'm missing something.

I embedded an echo:
...
    if. 0={.y do. j=. j-i=. 0 i.~ 0=y
echo '0={.y';x;y
...

I encountered an error in this mickey mouse test:
   1 0 0 0 0 0 0 0 0 1 pDiv 0 0 0 1 0 1
┌─┬───┬───┐
│0={.y│1 0 0 0 0 0 0 0 0 1│0 0 0 1 0 1 0 0 0 0│
└─┴───┴───┘
┌─┬───┬───┐
│0={.y│0 0 0 0 0 0 0 1 0 0│0 0 0 1 0 1 0 0 0 0│
└─┴───┴───┘
|domain error: pDiv
|   q=.q,j    #0
but maybe these arguments aren't like those for pDiv in the Rosetta 
Code task.


This trick for my div is analogous to allowing for leading decimal zeros
in 1234 % 0.0001 in "ordinary" long division.  I wonder if it's what you
intended.

NB. x % y
div =: 3 : 0    NB. similar result to Ken's dbho
:
q =. ''
NB. allow for leading zeros in quotient
if. 0 = {. y do.
   j =. 0 i.~ 0 = y
   y =. j }. y
   x =. x, 0#~ >: j
end.
yx=. y,:x
assert. 2 <: n =. 2 + x -&# y
while. n =. <: n do.
   q  =. q, r =. %~/ {."1 yx
   yx =. y,: }. -~/ yx * r,1
end.
q
)

   1 2 3 4 div 0 0 0 1
1 2 3 4 0 0 0 0
1234 % 0.0001
1234

Anyway, my extra echo reports nothing when running this:
    cyclotomic >: i.1000
so I suspect that the check is not necessary here.

Mike

On 20/02/2022 16:35, Raul Miller wrote:

For what it's worth, here's what I was focusing on:

http://rosettacode.org/wiki/Cyclotomic_polynomial#J

As you can see, I altered your polynomial division algorithm --
there's enough zeros in the polynomials I was working with, there,
that iterating through them seemed unwise.

If there's any other significant improvements that you notice -- or
any errors which I overlooked, of course, please let me know!

Thanks,







--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Cyclotomic Polynomials and FFT - was Re: polynomial division

2022-03-01 Thread &#x27;Michael Day&#x27; via Programming

Raul Miller's and RE Boss's (revised) entries here refer:
   http://rosettacode.org/wiki/Cyclotomic_polynomial#J

I think I'm partly responsible for pDiv in this (otherwise!) nicely 
concise and elegant

presentation of J routines to derive these polynomials.
Typically,
NB. (1+5x+10x^2+10x^3+5x^4+x^5 )%(1+3x+3x^2+x^3)  = 1+2x+x^2
   1 5 10 10 5 1 pDiv 1 3 3 1
1 2 1

pDiv is essentially elementary long division realised for polynomials 
rather than numbers;
it's rather inefficient for high-order polynomials,  and I was wondering 
how to speed it up.

I found a paper by Madhu Sudan which  addresses fast polynomial division:
   http://people.csail.mit.edu/madhu/ST12/scribe/lect06.pdf
but couldn't understand his hints at an algorithm.  I _think_ it 
successively improves
approximations to the solution,  working up from a constant term, then 
modulo x^2,
then x^4 ,  but it's very muddled to my mind,  and my mind couldn't see 
how to set about it!


Then I realised a compromise is to exploit polynomial multiplication 
using Fast Fourier Transforms,
as described first for this purpose,  I believe,  by Roger Hui; Henry's 
essay is to be found at

   https://code.jsoftware.com/wiki/Essays/FFT

That article desribes polynomial multiplication,  where we multiply the 
ffts of two
polynomials extended to an appropriate length,  a suitable power of 2.  
The inverse fft

is then applied to yield the required polynomial product.
If instead we divide one fft by another,  and take the inverse fft, we 
get the polynomial

quotient!

So here's a crib of Raul's functions;  I've merged cyclotomic and 
cyclotomic000,  dispensing

with "cache" and using the memoisation afforded by M.  :
(OK in fixed width font)

ctfft=:  {{ assert.0 lgl =. {:$ ctlist  =. ct "0 }:*/@>,{1,each q   NB. ctlist is 
2-d table of polynomial divisors
 lgd =. # dividend  =. _1,(-y){.1   NB. (x^n) - 1,  
and its size
 lg  =. >.&.(2&^.) lgl >. lgd   NB. required 
lengths of all polynomials for fft transforms

 NB. really, "divisor" is the fft of the divisor!
 divisor =. */ fft"1 lg{."1 ctlist  NB. FFT article 
doesn't deal with lists of multiplicands
 unpad roundreal ifft"1 divisor %~ fft lg{.dividend NB. similar to 
article's multiplication

   end.
}} M.

NB. fft, roundreal, ifft from FFT article.

NB. Performance - poor for lower orders...
NB. taskorderu is adverbial form of taskorder with required verb as left 
argument.


   timer'cyclotomic taskorderu 5'    NB. timer returns elpased time,  
before cache/memoisation established!

┌┬───┐
│1.163002│1 105 385 1365 1785│
└┴───┘
   timer'ctfft taskorderu 5' NB. not too good here cf cyclotomic!
┌─┬───┐
│3.5719986│1 105 385 1365 1785│
└─┴───┘
NB.  continuing with cache/memoisation as above
   timer'cyclotomic taskorderu 10'
┌───┬─┐
│5 7.8180008│1 105 385 1365 1785 2805 3135 6545 6545 10465│
└───┴─┘
   timer'ctfft taskorderu 10'   NB. some improvement!
┌┬─┐
│3 52.945│1 105 385 1365 1785 2805 3135 6545 6545 10465│
└┴─┘

So - not an order of magnitude effect,  but of some interest,  I hope!

Mike

On 20/02/2022 18:32, Raul Miller wrote:

Oh, bleah... of course.

y does not change. So that should be a test on {.x -- and that reveals
that I was using the wrong values throughout that section of code.

Here's a fixed version:

pDiv=: {{
   q=. $j=. 2 + x -&# y
   'x y'=. x,:y
   while. j=. j-1 do.
 if. 0={.x do. j=. j-<:i=. 0 i.~ 0=x
   q=. q,i#0
   x=. i |.!.0 x
 else.
   q=. q, r=. x %&{. y
   x=. 1 |.!.0 x - y*r
 end.
   end.q
}}

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Cyclotomic Polynomials and FFT - was Re: polynomial division

2022-03-01 Thread &#x27;Michael Day&#x27; via Programming

Oops - ct was my memoised version of cyclotomic,  while still using pDiv.
I expect the results will be much the same,  but I'll have a look later 
as I've
got to go out now.  I'll have to replace ct by ctfft - perhaps you'd 
like to try

while I'm pub-quizzing!

Cheers,

Mike


On 01/03/2022 19:02, Raul Miller wrote:

Ah, I had forgotten about that bit of code. Thanks.

Next question:

What is 'ct' here?

Thanks again,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Cyclotomic Polynomials and FFT - was Re: polynomial division

2022-03-01 Thread &#x27;Michael Day&#x27; via Programming

We're back from the Pub Quiz - 4th place, so "just outside the money"

Raul asked about roundreal - it's one of the utilities in the J wiki 
article on FFT multiplication:

   roundreal
[: (<.) 0.5 + 9&o.

Henry wondered about dividing ffts when non-zero remainders would 
exist.  it seems to fail, so we

can only use it safely when assured of divisibility:

   fft"1 ] 8 {."1 ] 1 5 20 10 5 1,: 1 3 3 1
42 _8.2426407j29.899495 _14j_4   0.24264069j_10.100505 10 
0.24264069j10.100505 _14j4 _8.2426407j_29.899495
 8  2.4142136j5.8284271   _2j2 _0.41421356j_0.17157288  0 
_0.41421356j0.17157288 _2j_2  2.4142136j_5.8284271

   %/fft"1 ] 8 {."1 ] 1 5 20 10 5 1,: 1 3 3 1
5.25 3.8786797j3.0208153 2.5j4.5 8.1213203j21.020815 _ 
8.1213203j_21.020815 2.5j_4.5 3.8786797j_3.0208153

   ifft %/fft"1 ] 8 {."1 ] 1 5 20 10 5 1,: 1 3 3 1
_ __ _ __ _ __ _ __

OK - here's ctfft without the inadvertent calls to ct :

ctfft=:  {{ assert.0 lgl =. {:$ ctlist  =. ctfft "0 }:*/@>,{1,each q   NB. ctlist 
is 2-d table of polynomial divisors
 lgd =. # dividend  =. _1,(-y){.1  NB. (x^n) - 
1,  and its size
 lg  =. >.&.(2&^.) lgl >. lgd  NB. required 
lengths of all polynomials for fft transforms
 fftdivis=. */ fft"1 lg{."1 ctlist NB. FFT 
article doesn't deal with lists of multiplicands
 unpad roundreal ifft"1 fftdivis %~ fft lg{.dividend   NB. similar 
to FFT article's multiplication

   end.
}} M.

NB. ... and crude measure of performance

NB. timer returns elpased time in minutes & seconds
  timer'cyclotomic taskorderu 5'    NB.  before cache/memoisation 
established!

┌─┬───┐
│1.0940018│1 105 385 1365 1785│
└─┴───┘
   timer'ctfft taskorderu 5'
┌─┬───┐
│4.3660049│1 105 385 1365 1785│
└─┴───┘
NB.  continuing with cache/memoisation as above
   timer'cyclotomic taskorderu 10'
┌───┬─┐
│4 35.623001│1 105 385 1365 1785 2805 3135 6545 6545 10465│
└───┴─┘
   timer'ctfft taskorderu 10'   NB. some improvement cf cyclotomic
┌───┬─┐
│3 58.355003│1 105 385 1365 1785 2805 3135 6545 6545 10465│
└───┴─────────────┘

So not much significant difference in the running times from those in my 
earlier report.


Cheers,

Mike

On 01/03/2022 19:17, 'Michael Day' via Programming wrote:

Oops - ct was my memoised version of cyclotomic,  while still using pDiv.
I expect the results will be much the same,  but I'll have a look 
later as I've
got to go out now.  I'll have to replace ct by ctfft - perhaps you'd 
like to try

while I'm pub-quizzing!

Cheers,

Mike


On 01/03/2022 19:02, Raul Miller wrote:

Ah, I had forgotten about that bit of code. Thanks.

Next question:

What is 'ct' here?

Thanks again,







--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Cyclotomic Polynomials and FFT - was Re: polynomial division

2022-03-02 Thread &#x27;Michael Day&#x27; via Programming
Interesting!   I've got some thoughts on this,  but it's getting late 
here,  so I'll

defer a fuller reply.

Meanwhile,  a quickie:  since the memoisation does seem to work, might 
it be better
to dispense with cache?  A pity as you put some effort into its use,  
but the code is

simpler without it.

Thanks,

Mike

On 02/03/2022 19:57, Raul Miller wrote:

I've updated the rosettacode page to include this implementation. And,
I plan on updating the j wiki polynomial division essay, also, once I
think through a bit how to describe this approach. (Descriptive
phrases and sentences would be welcome. Documentation needs good
perspectives, above all else.)

For the purpose of the rosettacode page, I used a different phrasing of rou:

rou   =: {{(,j.) r,(%:0j1),j.+|.}.r=.^o.j.(i.@%&8 % -:) y}}  NB.
roots of unity

This seems (to me) to be more concise, and straightforward, than the
purely tacit expression.

(That said, I'm not sure if this change in notation would be a good
fit for the FFT essay.)

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Power Conjunction

2022-03-06 Thread &#x27;Michael Day&#x27; via Programming

Late to the power party!

This is one way to automate the OEIS look-up - I'm not an expert on 
parsing the result,  but hunting for 'A', a single digit seems

a good starter:

   OEIS =: 'http://oeis.org/search?q='  NB. fails with https://... !

   getoeisseries =:{{ {{(-.{.) ' ',,/ y&{{~.x{~(i.7)+/~ x I.@:E.~ 
'A',y}}"0 '0123456789' }} RAW=:gethttp OEIS,commas y}}


   getoeisseries 5 9 15 23 33 45 59
A027688
A002522
A007954
A176271
A118403
A118401
A118400
A118407
A118402
A134586

where commas is what I always use to format series for OEIS searches:

commas =: 3 : 0   NB. crude - I forget how to format negatives using - 
with some ": variant!!!

 q   =. 1|.' '-.~,','&,@:":"0 y
 if. # imin=. I. q = '_' do.
 q   =. '-' imin } q
 end.
)

Not a primitive adverb,  but it's my starter for 10,

Mike

On 06/03/2022 06:36, Ian Clark wrote:

Let's cheat and look it up in oeis.org …
Skip's sequence is A027688, dropping the first term
A027688 is defined as: (n^2 + n + 3)
but (n*n + n + 3) gives better results with (13 :)

q=: 13 : '(y*y) + y + 3'

q

*~ + 3 + ]

q >:i.10

5 9 15 23 33 45 59 75 93 113


Has anyone tried automating OEIS lookup? It could be the basis for a nifty
new primitive adverb: (...) as in:

5 9 15 23 33 ...

On Sun, 6 Mar 2022 at 02:11, Elijah Stone  wrote:


Ah, David beat me to it! :)

On Sat, 5 Mar 2022, Elijah Stone wrote:


Here's how I would do it:

3++/\+:i.10
3 5 9 15 23 33 45 59 75 93

This preserves the 'missing' initial term of 3.  If you don't want it,
replace i.10 with >:i.10.

  -E

On Sat, 5 Mar 2022, 'Skip Cave' via Programming wrote:


I have this series:

5 9 15 23 33 

5+4

9

9+6

15

15+8

23

23+10

33


How can I use the power conjunction to generate this series?

Is there a more concise method to generate this than the power

conjunction?


Skip


Skip Cave
Cave Consulting LLC
--
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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Power Conjunction

2022-03-06 Thread &#x27;Michael Day&#x27; via Programming
I don't yet see how to separate the series itself/themselves from 
cross-refs!

M

On 06/03/2022 12:18, 'Michael Day' via Programming wrote:

Late to the power party!

This is one way to automate the OEIS look-up - I'm not an expert on 
parsing the result,  but hunting for 'A', a single digit seems

a good starter:

   OEIS =: 'http://oeis.org/search?q='  NB. fails with https://... !

   getoeisseries =:{{ {{(-.{.) ' ',,/ y&{{~.x{~(i.7)+/~ x I.@:E.~ 
'A',y}}"0 '0123456789' }} RAW=:gethttp OEIS,commas y}}


   getoeisseries 5 9 15 23 33 45 59
A027688
A002522
A007954
A176271
A118403
A118401
A118400
A118407
A118402
A134586

where commas is what I always use to format series for OEIS searches:

commas =: 3 : 0   NB. crude - I forget how to format negatives using - 
with some ": variant!!!

 q   =. 1|.' '-.~,','&,@:":"0 y
 if. # imin=. I. q = '_' do.
 q   =. '-' imin } q
 end.
)

Not a primitive adverb,  but it's my starter for 10,

Mike

On 06/03/2022 06:36, Ian Clark wrote:

Let's cheat and look it up in oeis.org …
Skip's sequence is A027688, dropping the first term
A027688 is defined as: (n^2 + n + 3)
but (n*n + n + 3) gives better results with (13 :)

q=: 13 : '(y*y) + y + 3'

q

*~ + 3 + ]

q >:i.10

5 9 15 23 33 45 59 75 93 113


Has anyone tried automating OEIS lookup? It could be the basis for a 
nifty

new primitive adverb: (...) as in:

5 9 15 23 33 ...

On Sun, 6 Mar 2022 at 02:11, Elijah Stone  wrote:


Ah, David beat me to it! :)

On Sat, 5 Mar 2022, Elijah Stone wrote:


Here's how I would do it:

    3++/\+:i.10
3 5 9 15 23 33 45 59 75 93

This preserves the 'missing' initial term of 3.  If you don't want it,
replace i.10 with >:i.10.

  -E

On Sat, 5 Mar 2022, 'Skip Cave' via Programming wrote:


I have this series:

5 9 15 23 33 

5+4

9

9+6

15

15+8

23

23+10

33


How can I use the power conjunction to generate this series?

Is there a more concise method to generate this than the power

conjunction?


Skip


Skip Cave
Cave Consulting LLC
-- 

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






--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Power Conjunction

2022-03-06 Thread &#x27;Michael Day&#x27; via Programming

OK - Ian wondered about automating a search in OEIS.
With a little inspection of the "page source" I've come up with this 
script;  it seems to work!


Although lots of OEIS lists are potentially mentioned if a series is 
matched,  many are cross-references

rather than the lower number of series that actually match.

My research has hardly been far-reaching,  so there may well turn out to 
be exceptions to this rule,  but

so far it appears that the pattern
   ''
works for the headwords,  as a dictionary might describe these references.

=
load   '~addons/web/gethttp/gethttp.ijs'

goeis =: getoeisseries =: {{

 commas =. {{   NB. form a comma-separated list suitable for an OEIS 
search

 q   =. 1|.' '-.~,','&,@:":"0 y
 if. # imin=. I. q = '_' do.
 q   =. '-' imin } q
 end.
}}

NB. commas 10?10

NB. 6,1,9,0,8,2,4,7,3,5,


 OEIS =. 'http://oeis.org/search?q='
NB. read RAW; the result of searching in OEIS for commas y
NB. Using global RAW for later inspection by user
 RAW  =: gethttp OEIS,commas y
NB. find all occurrences of '}} RAW

NB.  looking for subset matching "/Axx/list">
 ix =. ix +/ 7 + 10 + i.7
if. +/ ok =. '/list">' -:"1 ix {"1 RAW do.
   echo '3 results found'
   RAW {~ _7 + ok#ix
else.
   echo 'Sorry, but the terms do not match anything in the table.'
   RAW =: ''
end.
}}

NB.    goeis 5 9 15 23 33 45 59
NB. 3 results found
NB. A027688
NB. A118403
NB. A134586

NB.    goeis 5 9 15 23 33 45 59 27
NB. Sorry, but the terms do not match anything in the table.
===

IF the series is found,  you can go on to examine - even parse?! - the 
global "RAW" -
though I expect it's just as useful to go to the browser.  I don't use 
JHS enough to know

how to integrate this approach in that enviornment.

Mike

On 06/03/2022 14:06, 'Michael Day' via Programming wrote:
I don't yet see how to separate the series itself/themselves from 
cross-refs!

M

On 06/03/2022 12:18, 'Michael Day' via Programming wrote:

Late to the power party!

This is one way to automate the OEIS look-up - I'm not an expert on 
parsing the result,  but hunting for 'A', a single digit seems

a good starter:

   OEIS =: 'http://oeis.org/search?q='  NB. fails with https://... !

   getoeisseries =:{{ {{(-.{.) ' ',,/ y&{{~.x{~(i.7)+/~ x I.@:E.~ 
'A',y}}"0 '0123456789' }} RAW=:gethttp OEIS,commas y}}


   getoeisseries 5 9 15 23 33 45 59
A027688
A002522
A007954
A176271
A118403
A118401
A118400
A118407
A118402
A134586

where commas is what I always use to format series for OEIS searches:

commas =: 3 : 0   NB. crude - I forget how to format negatives using 
- with some ": variant!!!

 q   =. 1|.' '-.~,','&,@:":"0 y
 if. # imin=. I. q = '_' do.
 q   =. '-' imin } q
 end.
)

Not a primitive adverb,  but it's my starter for 10,

Mike

On 06/03/2022 06:36, Ian Clark wrote:

Let's cheat and look it up in oeis.org …
Skip's sequence is A027688, dropping the first term
A027688 is defined as: (n^2 + n + 3)
but (n*n + n + 3) gives better results with (13 :)

q=: 13 : '(y*y) + y + 3'

q

*~ + 3 + ]

q >:i.10

5 9 15 23 33 45 59 75 93 113


Has anyone tried automating OEIS lookup? It could be the basis for a 
nifty

new primitive adverb: (...) as in:

5 9 15 23 33 ...


[NB NB NB snipped earlier posts!  MD]

--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Power Conjunction

2022-03-06 Thread &#x27;Michael Day&#x27; via Programming

I forgot about regular expressions in J, but not familiar with them anyway!
Used to know them in unix, once upon a time.
Yr commas much better,  too.

M

On 06/03/2022 17:02, Raul Miller wrote:

Here's a version of getoeisseries which only returns direct hits and
not cross references:

NB. install 'web/gethttp'
require'regex web/gethttp'

OEIS =: 'http://oeis.org/search?q='  NB. fails with https://... !

getoeisseries=: {{
   a0=. I.''E.RAW
   A=. ,{."1'href="/A\d{6}"'rxmatches RAW
   a=. RAW{L:0~(a0(+i.)&.>a1-a0){~<:a0 I.A
   keep=. -.(1: e. ' title=' E. ])S:0 a
   >(}.~1+i.&'>')&.> keep#a
}}

commas=: rplc&' ,_-'@":

FYI,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Power Conjunction

2022-03-06 Thread &#x27;Michael Day&#x27; via Programming

Oops - please use this line in goeis,  just below,
   echo ' results found',~ ": +/ok
in place of
   echo '3 results found'

Mike

On 06/03/2022 17:05, 'Michael Day' via Programming wrote:

OK - Ian wondered about automating a search in OEIS.
With a little inspection of the "page source" I've come up with this 
script;  it seems to work!


Although lots of OEIS lists are potentially mentioned if a series is 
matched,  many are cross-references

rather than the lower number of series that actually match.

My research has hardly been far-reaching,  so there may well turn out 
to be exceptions to this rule,  but

so far it appears that the pattern
   ''
works for the headwords,  as a dictionary might describe these 
references.


=
load   '~addons/web/gethttp/gethttp.ijs'

goeis =: getoeisseries =: {{

 commas =. {{   NB. form a comma-separated list suitable for an OEIS 
search

 q   =. 1|.' '-.~,','&,@:":"0 y
 if. # imin=. I. q = '_' do.
 q   =. '-' imin } q
 end.
}}

NB. commas 10?10

NB. 6,1,9,0,8,2,4,7,3,5,


 OEIS =. 'http://oeis.org/search?q='
NB. read RAW; the result of searching in OEIS for commas y
NB. Using global RAW for later inspection by user
 RAW  =: gethttp OEIS,commas y
NB. find all occurrences of '}} RAW

NB.  looking for subset matching "/Axx/list">
 ix =. ix +/ 7 + 10 + i.7
if. +/ ok =. '/list">' -:"1 ix {"1 RAW do.
   echo '3 results found'
   RAW {~ _7 + ok#ix
else.
   echo 'Sorry, but the terms do not match anything in the table.'
   RAW =: ''
end.
}}

NB.    goeis 5 9 15 23 33 45 59
NB. 3 results found
NB. A027688
NB. A118403
NB. A134586

NB.    goeis 5 9 15 23 33 45 59 27
NB. Sorry, but the terms do not match anything in the table.
=== 



IF the series is found,  you can go on to examine - even parse?! - the 
global "RAW" -
though I expect it's just as useful to go to the browser.  I don't use 
JHS enough to know

how to integrate this approach in that enviornment.

Mike

On 06/03/2022 14:06, 'Michael Day' via Programming wrote:
I don't yet see how to separate the series itself/themselves from 
cross-refs!

M

On 06/03/2022 12:18, 'Michael Day' via Programming wrote:

Late to the power party!

This is one way to automate the OEIS look-up - I'm not an expert on 
parsing the result,  but hunting for 'A', a single digit seems

a good starter:

   OEIS =: 'http://oeis.org/search?q='  NB. fails with https://... !

   getoeisseries =:{{ {{(-.{.) ' ',,/ y&{{~.x{~(i.7)+/~ x I.@:E.~ 
'A',y}}"0 '0123456789' }} RAW=:gethttp OEIS,commas y}}


   getoeisseries 5 9 15 23 33 45 59
A027688
A002522
A007954
A176271
A118403
A118401
A118400
A118407
A118402
A134586

where commas is what I always use to format series for OEIS searches:

commas =: 3 : 0   NB. crude - I forget how to format negatives using 
- with some ": variant!!!

 q   =. 1|.' '-.~,','&,@:":"0 y
 if. # imin=. I. q = '_' do.
 q   =. '-' imin } q
 end.
)

Not a primitive adverb,  but it's my starter for 10,

Mike

On 06/03/2022 06:36, Ian Clark wrote:

Let's cheat and look it up in oeis.org …
Skip's sequence is A027688, dropping the first term
A027688 is defined as: (n^2 + n + 3)
but (n*n + n + 3) gives better results with (13 :)

q=: 13 : '(y*y) + y + 3'

q

*~ + 3 + ]

q >:i.10

5 9 15 23 33 45 59 75 93 113


Has anyone tried automating OEIS lookup? It could be the basis for 
a nifty

new primitive adverb: (...) as in:

5 9 15 23 33 ...


[NB NB NB snipped earlier posts!  MD]




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Cyclotomic Polynomials and FFT - was Re: polynomial division

2022-03-08 Thread &#x27;Michael Day&#x27; via Programming

Sorry - a few days have passed

Interesting!

As I had put up this idea (using fft multiplication and a special case 
for fft "division"),  I feel I can
wonder if this helps the Rosetta Code exposition of the virtues of J!  I 
like my idea,  of course,
and it's of potential interest to the J community,  but are Rosetta 
coders interested in tweaks

to improve performance?

REBoss's contribution is quite different,  and very compact,  so worth 
including.


There's no chance the contribution will reach the length of the Java 
one,  say,  but casual readers
not familiar with J might get the impression that all the code presented 
is required.


Just a thought!

Anyway,  I had a look at saving some of the continued redefinition of 
roots of unit and reuse of "cube", given
the repeated use of fft in the cyclotomic function,by defining a 
function fft1 which would be used instead of
fft"1 for multiples of lists of polynomials all of the same extended 
length,   but it doesn't help much here,

and is of course more complicated,  so I won't share it.

However,  if the fft multiplication version is to be included in the 
Rosetta Code contribution,  I think the
following offers some improvement,  mainly from the point of view of 
exposition.  A bit of thinking reveals

that the maximum length of all the polynomials will be that of x^n - 1 .
I believe this block of code is self-contained,  assuming addons include 
the fftw library.  unpad only needs
redefinition here for self-containedness.  ctfft can be renamed of 
course!  Use of M. is a matter of taste,
I suppose;  it does save having to define your own cache,  as previously 
discussed.


NB. Rosetta Coders don't need to worry about fft v fftw - that's for J-ers.


load '~addons/math/fftw/fftw.ijs'
fft   =: fftw
ifft  =: ifftw
roundreal =: [: (<.) 0.5 + 9&o.
unpad =: {.~ (1 + 0 i:~ 0 = ])

ctfft =:  {{ assert.0 ctlist  =. ctfft  "0 }:*/@>,{1,each q NB. ctlist is 2-d 
table of polynomial divisors
 dividend=. _1,(-y){.1 NB. coefficients of 
(x^n) - 1
 lg  =. >.&.(2&^.) y   NB. required length 
of each polynomial for fft transforms here
 fftdivis=. lg */  @:(fft @:{."1) ctlist   NB. fft of product 
of divisor polys = product of ffts of divisor polys
 fftquot =. fftdivis %~ fft  lg{.dividend  NB. (fft of 
(dividend%divisor) = (fft of dividend) % (fft of divisor)
 unpad roundreal ifft"1  fftquot   NB. clean up inverse 
fft of (dividend&divisor)

   end.
}} M.

Also,  I noticed a few minor typos in the remarks between "If you take 
all the divisors... " and "Task examples:"


Cheers,

Mike


On 02/03/2022 19:57, Raul Miller wrote:

I've updated the rosettacode page to include this implementation. And,
I plan on updating the j wiki polynomial division essay, also, once I
think through a bit how to describe this approach. (Descriptive
phrases and sentences would be welcome. Documentation needs good
perspectives, above all else.)

For the purpose of the rosettacode page, I used a different phrasing of rou:

rou   =: {{(,j.) r,(%:0j1),j.+|.}.r=.^o.j.(i.@%&8 % -:) y}}  NB.
roots of unity

This seems (to me) to be more concise, and straightforward, than the
purely tacit expression.

(That said, I'm not sure if this change in notation would be a good
fit for the FFT essay.)

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Cyclotomic Polynomials and FFT - was Re: polynomial division

2022-03-08 Thread &#x27;Michael Day&#x27; via Programming
Thanks.  May I just suggest again having a look at the bullet points, 
which have the odd

error?
eg "...coefficients of A cyclotomic polynomialS after 1 ..."
"... coefficients of the cyclotomic polynomial for a prime number haS as 
many..."

capitals/upper case highlighting problem letters.

Cheers
Mike

On 08/03/2022 21:01, Raul Miller wrote:

On Tue, Mar 8, 2022 at 2:01 PM 'Michael Day' via Programming
 wrote:

for fft "division"),  I feel I can wonder if this helps the Rosetta
Code exposition of the virtues of J!  I like my idea,  of course,
and it's of potential interest to the J community,  but are Rosetta
coders interested in tweaks to improve performance?

Some of them are.

But, I've taken the hint, and trimmed the J treatment of fft for the
cyclotomic polynomial task, to remove unnecessary bulk.

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] {{ }} definitions

2022-03-29 Thread &#x27;Michael Day&#x27; via Programming

Yes: eg

NB. in your script,  say

foo =: {{
   x + y
}}"0 1  NB. just as an example! (Not necessarily a sensible use 
of rank!)


NB. displaying it in the terminal session;  direct definition functions
NB. are displayed as conventional explicit definitions

   foo
4 : '   x + y'"0 1

So the rank appears where you would have put it in the old form.

Probably in the wiki somewhere!

Mike



On 29/03/2022 17:42, P Padilcdx wrote:

Is there a way to declare the rank when using {{ }} definitions? Or is it only 
possible when defining via “:”?  Apologies if covered in the wiki and I missed 
it.
--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] [Jbeta] J904 multithreading

2022-04-11 Thread &#x27;Michael Day&#x27; via Programming
The mechanism here is presumably common knowledge,  but might be worth 
sharing.

Here's what I use to allocate half of the laptop's cores for use by J:

NB. Processor Affinity
coclass 'affin'
require'dll'

GetCurrentProcess=: >@{.@('kernel32 GetCurrentProcess i'&(15!:0))
GetProcessAffinityMask=: ('kernel32 GetProcessAffinityMask i i * *'&(15!:0))
SetProcessAffinityMask=: ('kernel32 SetProcessAffinityMask i i i'&(15!:0))

setproc =: 3 : 0
'rc tid pam sam'=.GetProcessAffinityMask (GetCurrentProcess'');(,2-2);(,2-2)
ppr=. ,I. (8#2)#: sam
NB. choose random half of cores
cores =. ((?~ <.@-: ) # ppr )
SetProcessAffinityMask tid;0{,(8#2)#. 1 cores }8#0
)

So the number of cores is
   # #: sam
and you only need GetProcessAffinityMask and GetCurrentProcess for that
information.

Cheers,

Mike

On 10/04/2022 23:49, Raul Miller wrote:

There's currently no rush for deciding this kind of thing.

We need some experience with this mechanism, first. And, before that,
we need to support Henry's efforts to sort out the rough edges.

But counting cpu cores is a relatively simple task, if slightly
obscure. So I thought I should leave a note here about that.

Thanks,

-- Raul On Sun, Apr 10, 2022 at 6:34 PM Hauke Rehr 
 wrote:

why not have a command line argument providing a default number?
$USER may know better what they consider a good default

Am 11.04.22 um 00:31 schrieb Raul Miller:

It would be nice, I imagine, if we eventually had a mechanism like

https://www.cprogramming.com/snippets/source-code/find-the-number-of-cpu-cores-for-windows-mac-or-linux

to set up a default number of threads.


--
--
mail written using NEO
neo-layout.org
--
For information about J forums seehttp://www.jsoftware.com/forums.htm

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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] jpm niggle - was Re: [Jbeta] Beta users: please enable new diagnostic message

2022-04-11 Thread &#x27;Michael Day&#x27; via Programming

Thanks.

BTW,  not a Beta problem,  I realise,  and I don't know how many users 
are affected,  but
I'm still having to make functions monadic if I want showdetail to 
provide a useful report;

dyads still yield zero times for all lines - last time I looked, anyway!  po

Mike

On 11/04/2022 17:57, Henry Rich wrote:
Ah, that's telling us showdetail should be updated.  Thanks for the 
report.


Henry Rich

On 4/11/2022 12:53 PM, 'Michael Day' via Beta wrote:
Is this an example of the error messages/warnings enabled with 9!:55 
] 1e6;'   ?


   commas i.10 NB. no problem reported
0,1,2,3,4,5,6,7,8,9,

But suppose I wish to examine the performance of commas(!!):
   start_jpm_ 10
17857142
   timex'commas i.10'
4.11e_5
   showdetail_jpm_ 'commas'
recorded all lines
used and max record count: 24 17,857,142

(004) m}"n should be executed without " using leading axes of a: in m
(004) m}"n should be executed without " using leading axes of a: in m
(004) m}"n should be executed without " using leading axes of a: in m
 Time (seconds)
+++---+---+
|all |here    |rep|commas |
+++---+---+
|0.30|0.30|1  |monad 1 |. ' ' -.~ [: , ','&,@:":"0|
+++---+---+

The three diagnostics (004) m"}n ... are evidently evoked by 
something in

or called by showdetail_jpm_  .

I discovered this just now,  examining the performance of something a
bit more interesting than "commas",  but decided this example 
demonstrates

the point of interest.

Cheers,

Mike

On 09/04/2022 20:03, Henry Rich wrote:
It has long been known that J will execute many meaningless 
sentences without warning.  Examples are


NB **

#if defined(AVX)

perform_important_function misspelled_noun

each of which does nothing.

It has been difficult to give warnings only on true errors. J904 
implements a warning, based on the observation that the erroneous 
sentences produces verbs, and taking into account contexts where a 
verb result would be valid.


This warning occasioned an unusually wide range of opinion at J 
Headquarters.  Is it: tantamount to a Critical Security Patch, 
fixing a gaping hole in the language; a novelty, perhaps of interest 
to a few; an unwarranted usurpation of a programmer's prerogatives, 
and likely to break working code?


Thus the warning is optional in beta-a.  We would like to get good 
data on whether the warning is welcome, noxious, or intolerable. I 
ask all beta users to enable the warning by adding


9!:55 ] 1e6;''

to your startup script.  After a few days, report your findings in 
this Forum.  Make note of any valid lines that were flagged, and 
also of any cases where the warning revealed code to be meaningless.


Henry Rich










--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] jpm niggle - was Re: [Jbeta] Beta users: please enable new diagnostic message

2022-04-12 Thread &#x27;Michael Day&#x27; via Programming
Sorry, Henry - I just checked a dyadic function with jpm - STILL ALL 
ZEROS IN/UP TO J903.
HOWEVER - it is indeed reporting numbers of entries and times by line in 
J904, for the dyad as for monads !


So - Thanks for that,  and sorry that I didn't check.  I'd assumed that 
you'd been too

busy to deal with this issue for this beta release.

Cheers,

Mike

On 12/04/2022 16:45, Henry Rich wrote:
I thought I fixed that a while back & I believe I got good results in 
JPM.  I'll look again next time I have to profile.


Henry Rich

On 4/11/2022 1:03 PM, 'Michael Day' via Programming wrote:

Thanks.

BTW,  not a Beta problem,  I realise,  and I don't know how many 
users are affected,  but
I'm still having to make functions monadic if I want showdetail to 
provide a useful report;
dyads still yield zero times for all lines - last time I looked, 
anyway!  po


Mike

On 11/04/2022 17:57, Henry Rich wrote:
Ah, that's telling us showdetail should be updated.  Thanks for the 
report.


Henry Rich

On 4/11/2022 12:53 PM, 'Michael Day' via Beta wrote:
Is this an example of the error messages/warnings enabled with 
9!:55 ] 1e6;'   ?


   commas i.10 NB. no problem reported
0,1,2,3,4,5,6,7,8,9,

But suppose I wish to examine the performance of commas(!!):
   start_jpm_ 10
17857142
   timex'commas i.10'
4.11e_5
   showdetail_jpm_ 'commas'
recorded all lines
used and max record count: 24 17,857,142

(004) m}"n should be executed without " using leading axes of a: in m
(004) m}"n should be executed without " using leading axes of a: in m
(004) m}"n should be executed without " using leading axes of a: in m
 Time (seconds)
+++---+---+
|all |here    |rep|commas |
+++---+---+
|0.30|0.30|1  |monad 1 |. ' ' -.~ [: , ','&,@:":"0|
+++---+---+

The three diagnostics (004) m"}n ... are evidently evoked by 
something in

or called by showdetail_jpm_  .

I discovered this just now,  examining the performance of something a
bit more interesting than "commas",  but decided this example 
demonstrates

the point of interest.

Cheers,

Mike

On 09/04/2022 20:03, Henry Rich wrote:
It has long been known that J will execute many meaningless 
sentences without warning. Examples are


NB **

#if defined(AVX)

perform_important_function misspelled_noun

each of which does nothing.

It has been difficult to give warnings only on true errors. J904 
implements a warning, based on the observation that the erroneous 
sentences produces verbs, and taking into account contexts where a 
verb result would be valid.


This warning occasioned an unusually wide range of opinion at J 
Headquarters.  Is it: tantamount to a Critical Security Patch, 
fixing a gaping hole in the language; a novelty, perhaps of 
interest to a few; an unwarranted usurpation of a programmer's 
prerogatives, and likely to break working code?


Thus the warning is optional in beta-a.  We would like to get good 
data on whether the warning is welcome, noxious, or intolerable. I 
ask all beta users to enable the warning by adding


9!:55 ] 1e6;''

to your startup script.  After a few days, report your findings in 
this Forum.  Make note of any valid lines that were flagged, and 
also of any cases where the warning revealed code to be meaningless.


Henry Rich
















--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Extended precision question

2022-05-01 Thread &#x27;Michael Day&#x27; via Programming

Mainly for Ed Gottsman:

Chat really,  but the thread is already here.

I've just solved Euler Problem 788 with the assistance of extended 
precision numbers.  The solution is
slow,  taking over 14 minutes,  but at least it's less than the lifetime 
of the universe,  unlike my (projected)

methods for some of these problems!

It's relatively easy,  compared with many of the recent questions; 
https://projecteuler.net/problem=788 .


As for Ed's original post,  I'll point out that x: features aren't 
necessary for the solution of problem 66
although they can possibly help in understanding it.  I don't think 
that's a spoiler.


Cheers,

Mike

On 21/04/2022 17:43, Ed Gottsman wrote:

Hello.
  
I’m working on the Project Euler “Diophantine equation” problem (#66) and using J’s extended precision facilities.  I’ve run into behavior that confuses me.  Boiled down (and overusing x: just to be sure):
  
x: %: x: 1 + x: *: x: 9

9
  
That is (if my syntax is right), the square root of (one plus the square of a really large n) is n.  I’m apparently misunderstanding something about extended precision.  I’ve tried it with a variety of uses of x: but to no avail, and as I read the x: documentation…this is an odd result.


Any help would be much appreciated.
  
(J901 on iPadOS, for which sincere kudos to Ian Clark.)
  
Many thanks.
  
Ed

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



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


[Jprogramming] JQT not starting properly in Windows 11

2022-05-16 Thread &#x27;Michael Day&#x27; via Programming
Hello.  I tried to wake up my laptop from sleep just now,  as usual - ie 
I leave it in sleep mode while I'm asleep...
But,  as occasionally happens, it must have restarted,  and nothing was 
open.


(I wanted to explore the Babylon Spiral topic,  which I've just woken up 
to see!)


I now find that Jqt doesn't display any window when I start it.  I can 
see it in Task Manager but it's not usable.

This goes for both J904 beta-c and J903.

I recall this happening before,  a few years ago, but can't remember how 
we got round the problem; perhaps it

just went away.

Yes,  I did do a full stop and reboot of Windows.  As far as I can see,  
Windows has NOT done a surreptitious
update while I wasn't looking.  It's Windows 11 Home,  version 21H2,  
installed on 26/10/21, OS build 22000.65 ,

Windows Feature Experience Pack 1000.22000.675.0  (very round numbers!?)

I'm nothing like as proficient in using J in other manifestations, ie 
JHS & Jconsole.


HELP!

Thanks,

Mike

PS - I'll keep trying to run from time to time - will report if Jqt 
suddenly decides to reveal itself.



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] JQT not starting properly in Windows 11

2022-05-17 Thread &#x27;Michael Day&#x27; via Programming
Thanks,  but I'm pretty sure it's not off-screen.  At least, Alt+Tab 
doesn't find it,  and I frequently use those keys to swap windows.


I forgot to mention earlier that I did think of permissions,  and tried 
"run as administrator" with the same lack of a terminal screen.


And oh yes,  the yellow icon is indeed in the Windows 11 Taskbar, though 
only because I put it there!  Not a lot of use except it only needs a 
single click to evoke the non-apparent terminal!


Currently Clueless.

Thanks to you & Rob,

Mike

On 17/05/2022 12:00, Joe Bogner wrote:

I now find that Jqt doesn't display any window when I start it.  I can
see it in Task Manager but it's not usable.



I've had JQT show up off-screen once or twice and had to use a shortcut to
bring it back on screen. I think it was when I was in a multi-monitor
situation and went back to a single monitor. It hasn't happened in years
but passing along in case it helps

Press Alt + Tab to select the missing window.
Press Alt + Space + M to change the mouse cursor to the move cursor.
Use the left, right, up or down keys on your keyboard to bring the window
back into view.
Press Enter or click the mouse to let the window go once recovered.

https://www.google.com/search?q=windows+restore+off+screen+window

or
https://support.microsoft.com/en-us/topic/some-programs-are-displayed-off-the-screen-b2a915b7-4705-c455-febf-8ddb6e7f0ae4

Is it showing the green J icon on the taskbar? Or maybe Windows 11 doesn't
have that anymore..
--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] JQT not starting properly in Windows 11

2022-05-17 Thread &#x27;Michael Day&#x27; via Programming

Success???!!!

I really should clean up the old J installations - but as they're 
there,  I tried J902, J901, J807,  giving
up on each loading and usually closing their "task".  But the J807 
terminal has just leapt into life after
5-10 minutes of me looking at emails etc.  With this encouraging sign of 
survival,  I clicked on J904

beta's icon in the Taskbar and its terminal appeared almost immediately.

Weird.  I'll keep it running for a while now.

Sorry to cry wolf.

Mike

On 17/05/2022 17:19, 'Michael Day' via Programming wrote:
Thanks, but I'm pretty sure it's not off-screen.  At least, Alt+Tab 
doesn't find it,  and I frequently use those keys to swap windows.


I forgot to mention earlier that I did think of permissions,  and 
tried "run as administrator" with the same lack of a terminal screen.


And oh yes,  the yellow icon is indeed in the Windows 11 Taskbar, 
though only because I put it there!  Not a lot of use except it only 
needs a single click to evoke the non-apparent terminal!


Currently Clueless.

Thanks to you & Rob,

Mike

On 17/05/2022 12:00, Joe Bogner wrote:

I now find that Jqt doesn't display any window when I start it.  I can
see it in Task Manager but it's not usable.


I've had JQT show up off-screen once or twice and had to use a 
shortcut to

bring it back on screen. I think it was when I was in a multi-monitor
situation and went back to a single monitor. It hasn't happened in years
but passing along in case it helps

Press Alt + Tab to select the missing window.
Press Alt + Space + M to change the mouse cursor to the move cursor.
Use the left, right, up or down keys on your keyboard to bring the 
window

back into view.
Press Enter or click the mouse to let the window go once recovered.

https://www.google.com/search?q=windows+restore+off+screen+window

or
https://support.microsoft.com/en-us/topic/some-programs-are-displayed-off-the-screen-b2a915b7-4705-c455-febf-8ddb6e7f0ae4 



Is it showing the green J icon on the taskbar? Or maybe Windows 11 
doesn't

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






--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] JQT not starting properly in Windows 11

2022-05-17 Thread &#x27;Michael Day&#x27; via Programming
Thanks,  Raul.   I've downloaded Process Explorer, as you suggest, as it 
sounds useful.


I think you're right that this laptop offers two (or more?) "desktops",  
but I've never
deliberately used the feature,   and it doesn't look as though Jqt was 
hiding elsewhere.


Anyway,  as I mentioned in an earlier message,  the problem of the 
apparent non-availability

of Jqt9 seems to have resolved itself for the time being.

Cheers,

Mike





On 17/05/2022 17:29, Raul Miller wrote:

Here, I would recommend Process Explorer.

The current microsoft url for it is
https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer

Right click on the process here will give you window controls (like
"bring to front") if there is a window. If there's not, there's no
window (and "recovery" probably involves shutting it down (or,
rebooting)).

That said, Windows has (in at least some versions) a multiple desktop
feature (which I don't have enough practical experience with) which
might be relevant here.

I hope this helps,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] J904-beta-d

2022-05-20 Thread &#x27;Michael Day&#x27; via Programming

Thanks.  The upgrade was easy,  but the result is unfortunate,  at
least on this laptop running Windows 11.

Attempting to open any of Jqt, JHS, Jconsole does establish a new 
instance of
jqt.exe or jconsole.exe, according to the details display of Task 
Manager,  but it

immediately shows its status as "suspended."

(Raul MIller recently suggested I use Process Explorer - it shows the same
information as far as I can see.)

Task Manager refused to terminate these tasks.  ("Unable to terminate 
process -

The operation could not be completed.  Access is denied")
Restarting windows removed them of course.

I had added some stuff to the startup.ijs file,  trying to establish 
threads,  and

I wondered whether that was creating a problem given Henry's changed some
behaviour;  After commenting out those operations in the startup, opening
the exes still results in suspended status.

I'm not aware of having changed the setup in any way other than doing the
upgrade,  until I altered the startup.ijs file,  anyway.

It's difficult to give any useful information.

Any ideas?

Thanks,

Mike

On 20/05/2022 16:06, Eric Iverson wrote:

J904-beta-d is available for windows/linux/macos.

If you already run J904-beta, then upgrade is easy:
load'pacman'
'upgrade'jpkg'jengine'

If you have not yet installed J904-beta, time to get started!
https://code.jsoftware.com/wiki/System/Installation/J904


Release notes:
https://code.jsoftware.com/wiki/System/ReleaseNotes/J904


Questions/bug reports/etc. should go to the beta forum.
--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Sudoku16

2022-06-19 Thread &#x27;Michael Day&#x27; via Programming
FWIW,  I've been looking at this,  and my own slower and more 
space-consuming versions.
I tried amending Roger's similar original code,  posted in the forum,  I 
think, with obvious
changes as follows.  Some of his verbs,  including your ac & ar I think 
differ in the wiki article

from the ones I have.  I've used suffixes x or hx for hex:

NB. Hui's solution for 16x16?

size2x  =: 2#sizex  =: *: smallx =: 4
jx  =. (]/. i.@#) ,{;~smallx#i.smallx
rx  =. size2x $"1 i.size2x
cx  =. (size2x$i.sizex){|:i.size2x
bx  =. (jx{sizex#i.sizex) { jx
Ix  =: rx,"1 cx ,"1 bx
Rx  =: jx,(,|:)i.size2x

freex   =: 0&= > (1+i.sizex)"_ e."1 Ix"_ { ,
regionsx=: Rx"_ {"_ 1 ,"2
eux =: e.&(i.sizex+1) *. 0&= +. ~:"1
okx =: (1$~(smallx,1)*size2x)"_ -:"2 eux@regionsx

s1ux    =: 3 : 0
 m=. 1=+/"2 Rx{,/y
 j=. I. +./"1 m
 k=. 1 i."1~ j{m
 i=. ,(k{"_1 |:"2 (j{Rx){,/y) #"1 j{Rx
 size2x$(1+k) i}0$~*/size2x
)

NB. s1x    =: +/ .*&(1+i.9) * 1: = +/"1
NB. s1 =: (+ (s1x >. s1u)@free)^:_"2
NB. sudoku =: s2 @: (ok # ]) @: s1 ^:_

s1xx    =: +/ .*&(1+i.sizex) * 1: = +/"1
s1hx    =: (+ (s1xx >. s1ux)@freex)^:_"2

s2ax    =: 3 : 0
 if. -. 0 e. ,y do. ,:y return. end.
 b=. freex y
 i=. (i.<./),(+/"1 b){(1+sizex),}.i.sizex
 d=. 1+I.i{,/b
 y +"2 d *"0 2 i=i.size2x
)

s2x =: ; @: (<@s2ax"2)

sudokux =: s2x @: (okx # ]) @: s1hx ^:_
NB. ==

When I run this on my solvable array, sixteen2,  it fails:
   s1x sixteen2
|length error: s1x
|   s1x sixteen2

Debug shows the error occurs in or around freex,  but I haven't yet 
discovered how.


Here's sixteen2:
   sixteen2
 3  6  0  0  0  0  4 15 12 11 13  2  8  0  5 0
 0  0 15  0  1  0 14  0  0  0  8  0 13  0  0 0
 0 14 13  0  0  8 10  0  0 16  5  0  0  0  0 0
 0  5  4  0  0  0  0  0  0  0  0  7  3 11  0 2
 0  0  9  0  0  7  0  0  0  0  3 10  6  4  0 0
 0 11  0  0  4 13  0  0  0  0  0  0  7 15 10 8
 0  0  0  0 15  0  0  0  0  0  6  4 11  0 14 0
 0 15  0  0  0  0  6  0 13  2  0  0  9 12  0 0
12  1  0  0  0  3  0  6  9  4 14  8  5  0  0 0
 0  0  0  0 13  2  0 12  0  5 10  3  1 14  9 0
 2  0  0  9  0  5  0  0 11 12  7  0  0  8 15 0
 0  0  8 14  0  4  7 11  1 13  0  0  0  0  0 0
 4  0  0  0  3  0 16  0  0  6  0  0  0  0  0 0
16  7 12 13 14  9  0  2  8  0  0  0  0 10  0 0
11  0  1  0  0 15  0  0  0  0  0  0  0  5  0 0
15  8  0  0  6  0  5 10  3  0  0  0  0  7 11 0

My own code is more secure in APL,  and too long-winded
to share here!

Cheers,

Mike




On 19/06/2022 17:42, Brian Schott wrote:

Raul,

I truly appreciate your comments and while they seem very reasonable I do
not know how to delve more deeply into the permutations as you suggest. I
am leaning more to dropping the idea of finding a solution based on Roger’s
algorithm. Instead I want to look more closely at his results for the verbs
AR and AC. In his algorithm he takes the larger of the two results, that is
the larger of AR or AC , where he expects one of each pair to be zero and
the other to be a valid candidate. Whenever there is a nonzero AC it is a
unique and correct candidate, but the values for AR are selected using
index of, i. . I am suspicious that the selection of AR is almost arbitrary
and is causing the problem. I think a human being could do a better job of
selecting among the alternatives from AR.

By the way in my definition for the verb AR the final negative one should
be a zero, but it doesn’t change things much. Also in my text above I am
capitalizing AR and AC but they are lowercase verbs.

If I am correct about using AR and AC to help a human, I would use a
variation on AC that shows all of the possible results instead of the one
captured by the ‘index of’ primitive. In light of that I am looking for
ways to use 4 x 4 arrangements of dots to display each of the cell’s
information. I was looking in the Unicode lists for 4 x 4 dot arrangements
but was unable to find any, so I am trying to imagine alternatives. So far
I can only think of using viewmat to construct the dot patterns.

Any more ideas?




--

(B=) <-my sig
Brian Schott
--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Sudoku16

2022-06-20 Thread &#x27;Michael Day&#x27; via Programming
Purists may object to the number representation in the 16x16 puzzle, in 
the generalisation I've just posted;
numbers 1-16 are encoded as 1-g !  Clearly they could be "better" as 
0-f.  I don't know which is preferable!

I normally stick to a numeric output,  involving no encoding.

NB - I haven't copied the correspondence in this remark.

Cheers,

Mike

--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [Jprogramming] Sudoku16

2022-06-24 Thread &#x27;Michael Day&#x27; via Programming
Sorry for late posting - apparently a problem with my broadband 
provider's server.


Yes, it can be worth doing a limited feasibility check on your input.  
Every column,

row and small box should have no repeated elements apart from the "missing"
indicator,  such as 0 or perhaps one of '.-*0' ,  eg,  using my 
generalisation of Roger's code:
    */ (2 */ @: > #/.~@: -.&0)"1 R{,fiend   NB. fiend is a numeric 9x9 
puzzle


1


It might be of minor interest to note I've got my modification of Roger 
Hui's wiki essay


code to solve a 25x25 puzzle which I lifted from an online source,

https://www.sudoku-puzzles-online.com/

Annoyingly,  I haven't dicovered how to download it in a form usable 
directly by J.  I

spent far too much time transcribing just one 25x25 puzzle by eye and hand.

I modified the solve function , posted on 20 June. just a tad to allow 
the input of a character

representation.  I'll just reproduce the new and amended lines:

solve =: 3 : 0
'.123456789abcdefghjklmnpqrstuvwxyzA' solve y  NB. x is a default 
representation for up to 36x36 just:

if. ' ' = 1{.0{.ry =. , y do.
   chars =. ''
   chars =. chars, /:~ ~., ' .*-' (e.~#]) ry NB. any other 
representations of unknown cells?

   chars =. chars, /:~ ~., '123456789' (+./@:e.~#[) ry
   chars =. chars, /:~ ~., 'abcdefghijklmnopqrstuvwxyz' (+./@:e.~#[) ry
   chars =. chars, /:~ ~., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' (+./@:e.~#[) ry
   sudokurep =: chars
   y =. chars i. y
else.
   sudokurep =: x
end.
.
see1 =: (;~n2$n1{.1)&(<;.1) @ ({&sudokurep) @ (n22&$) @ ,

.

)


Here's the puzzle I copied,  "confirmed" or "advanced" number 7957:


t25 =: (#{."1 ] ) dtb"1 >LF cut 0 : 0
j  g n  os wc iy   r aup
 o  qf   w    n  mgeb
 ycaix rlp  t  b d  nvs
n qcb e  vg  x  t
wbmks   ig   pnf  cd
 p s    w fxa d   v u l
k  u   xyv rhog    cj p q
   tj e nq  sy xo mbf w
 lxob ufk i   t   d    ns
  rqdtc   w uh   o g
u    kt  o i    vbpm gj h
  j   xv   pdrqwat  o   u
atib sym   h w   jod nfcx
o   w  dfbtkns   ux   a
v he ligq    b c  fk    d
 g x   ud m   yebqt
lh    r   p   s dmw gcxu
  q rmn pk tw  fg b sh
m b ac    hoej urx   p  y
  t o s   d bga h    f i
 cn  yps   db   vukfe
x  p  vh  b kwa j
  ajy  n f  p  hte sdriw
bfud  n    v   im  x
 wli j   ur xv pf  q b  n
)


see {:solveh t25
┌─┬─┬─┬─┬─┐
│jxegv│nktos│bwcdi│ymqhr│laupf│
│toprq│fdjvw│syuxn│icakl│hmgeb│
│hycai│xmrlp│ogtkf│bedju│nvsqw│
│ndflu│aqcby│ejmph│swvgo│ixrkt│
│wbmks│uheig│qlvar│txpnf│yjcdo│
├─┼─┼─┼─┼─┤
│ipysh│rgowm│fxaed│qnkvj│utlbc│
│knwue│ibxyv│lrhog│asftc│jdpmq│
│gavtj│delnq│cusyp│xoimb│fkwhr│
│clxob│hufkj│ivqmt│gprdw│aeyns│
│fmrqd│tcpsa│wbknj│luhey│xovgi│
├─┼─┼─┼─┼─┤
│usdcl│ktwao│xiyfe│nvbpm│qgjrh│
│ykjfn│exvhc│mpdrq│watig│olbsu│
│atibp│symur│ghlwv│eqjod│knfcx│
│oqgmw│pjdfb│tknsc│rluxh│eiayv│
│vrhex│ligqn│jaobu│cysfk│pwmtd│
├─┼─┼─┼─┼─┤
│pgsxc│waudh│vfrlm│oinye│bqtjk│
│lhkyf│orbte│pniqs│jdmwv│gcxua│
│djqvr│mnipk│ytwux│fgcba│sheol│
│mibna│cfqgl│hoejk│urxst│wpdvy│
│eutwo│vsyjx│dcbga│khlqp│rfnim│
├─┼─┼─┼─┼─┤
│rcnhg│ypsmi│aqjtw│dbolx│vukfe│
│xeopt│gvhrd│usfib│mkwan│cyqlj│
│qvajy│blnxf│kmpco│hteus│driwg│
│bfudk│qwact│neghl│vjyri│msoxp│
│swlim│jokeu│rdxvy│pfgcq│tbhan│
└─┴─┴─┴─┴─┘


   ts
6!:2 , 7!:2@]
   ts'solveh t25'   NB. performance ok for this example
0.0374274 1461408

They offer even larger puzzles,  but I'll avoid those until I see how to 
download them

in a usable format!



On 20/06/2022 18:00, Brian Schott wrote:

All,

My code is not perfect, but the error I was noticing in trying to step
through the algorithm using the verbs f and diff were correct, BUT my
initial data in the noun raw was missing a starting SPACE. So the example
data was unsolvable. When I corrected the data, I was able to get an answer
with Mike's most recent verb 'solve', and it looks like it is the correct
answer.

I apologize for the noise. And will try to improve my solution now; for
some reason my version of 'sudoku' is flawed, but I think I can rectify
that now that I have a working version of the verbs f and diff.

Again, I apologize. And thank you.
--
For information about J forums seehttp://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


  1   2   3   >