Re: [Jprogramming] [Jgeneral] Report of the J wiki meeting of December 14th, 2023

2023-12-27 Thread 'Skip Cave' via Programming
All,

I would like to attend the Thursday J Wiki meetings. How do I get an invite
to those meetings?

Skip

Skip Cave
Cave Consulting LLC


On Thu, Dec 28, 2023 at 12:05 AM 'robert therriault' via General <
gene...@jsoftware.com> wrote:

> == Report of Meeting 2023-12-14 ==
>
> Present:  Art Anger, Ed Gottsman, Raul Miller, and Bob Therriault
>
> Full transcripts of this meeting are now available on the its wiki page.
> https://code.jsoftware.com/wiki/Wiki/Report_of_Meeting_2023-12-14
>
> 1) Ed reported that he had removed the time slider as it was taking up
> space and it only applied to forum posts. Skip Cave's Quora posts have been
> added, but there is a concern that there are verbs that are included in the
> solutions that are not defined. The solution may be to split the display so
> that the solution is shared with a wiki page that has Skip's definitions on
> it, possibly in an expanded text fashion.
>
> 2) Ed also identified the issues that he has had with highlighting buttons
> in Night shift mode which can vary between dark backgrounds and light
> backgrounds. Changing the thickness of the border may be an option because
> it is not affected by Night shift.
>
> 3) Ed is working on creating some navigational ways to show higher
> dimensional arrays. He is not looking at this problem as purely
> visualization because he finds anything above 6 dimensions impossible to
> visualize. His navigation aid is a three dimensional array of boxes that
> has the dimensions and types of the contents. By clicking on a box he can
> show the contents of that box with a breadcrumb display across the top that
> shows where you are in the navigation of the array. He showed an example of
> a 3 dimensional sliced torus although it did not seem to be displayed the
> way that he expected. With this view it is possible to choose any pair of
> axes to display the rest of the dimensions of the array. Raul related this
> back to his REGEX lab which is working in three dimensions and Fourier
> transforms which are n-rank with each dimension as a value of 2. Bob
> mentioned Grant Sanderson's video on quaternions which has an excellent
> display of 4 dimension space. https://www.youtube.com/watch?v=d4EgbgTm0Bg
>
> 4) Bob mentioned that Chris Burke had contacted him again to express
> concern about the play-doh look of the wiki and the way that it might
> represent Jsoftware inappropriately to some of its clients. The more
> cartoonish navigation is actually independent of the traditional guides.
> Bob felt that the Jsoftware site could link to the guide navigation
> https://code.jsoftware.com/wiki/Main_Page while other links outside of
> Jsoftware could link to the cartoonish look
> https://code.jsoftware.com/wiki/Category:Home.  Raul wondered if the
> graphics could be generated from J code and that might be more acceptable.
> https://code.jsoftware.com/wiki/Studio/Gallery A further clarification
> may need to be determined as to the role of the wiki with respect to
> Jsoftware. This resulted in a discussion about the changes that had been
> made to some of the Jsoftware content that had been brought into the wiki.
> Ed felt there might need to be a discussion that clarified the lines of
> demarcation between J software and the wiki. Bob felt that a more corporate
> approach would be something closer to the Announcements page
> https://code.jsoftware.com/wiki/Category:Announcements_A , but this might
> not be as attractive to new users. The question that remains is how we can
> best serve the audiences that we have in mind, knowing that it may not be
> possible to serve all audiences equally.
>
> For access to previous meeting reports
> https://code.jsoftware.com/wiki/Wiki_Development If you would like to
> participate in the development of the J wiki please contact us on the
> general forum and we will get you an invitation to the next J wiki meeting
> held on Thursdays at 23:00 (UTC) Next meeting is December 28, 2023.
> --
> 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] Index of item in table

2023-12-26 Thread 'Skip Cave' via Programming
What would a general "find the index of the value x in the array y" verb
named fixv look like?

It would work like this:

] p=.3 4 5$?60$50

10 49 11 0 4

39 33 34 32 38

49 24 43 36 41

1 21 11 14 27


7 28 38 9 26

24 42 39 12 3

8 28 33 1 4

46 40 7 49 0


10 8 49 37 39

5 45 46 39 6

7 38 32 2 7

5 10 48 16 37


45 fixv p

2 1 1


If there were more than one match, what should the output be?


Skip Cave
Cave Consulting LLC


On Tue, Dec 26, 2023 at 7:48 PM LdBeth  wrote:

> This is related to the question I asked several days ago,
>
> http://jsoftware.com/pipermail/programming/2023-December/062994.html
>
> My suggestion would be
>
>  8 (($@])#:[i.~,@]) A
> 1 3
>
> Although you might want to an alternative behavior when there are
> multiple matches.
>
> LdBeth :)
>
> >>>>> In  o4rkystuqvjqqqtfxpqjy38zwarncd_ttl...@mail.gmail.com>
> >>>>>   David Pinchbeck  wrote:
> > Having trouble finding this in the wiki:  I know that we can select from
> a
> > table using a boxed pair
>
> > A
>
> > 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
>
>
> > (<1 3){A
>
> > 8
>
> > How do I write a verb f to do the reverse, so that
> > 8 f A
> > yields the result 1 3  ?
>
> > Thanks,
> > David
> > --
> > David Pinchbeck
> > Associate Professor of Mathematics
> > St. Joseph's College
> > Standish, ME
> > --
> > 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


[Jprogramming] Square roots

2023-09-24 Thread 'Skip Cave' via Programming
How to get more accurate square roots?

%:1023810239x

31997

1023810239x ^ 1r2

31997

31997x^2

1023808009


Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Primes with combination of same digits

2023-09-23 Thread 'Skip Cave' via Programming
Once  you generate all the n-digit prime permutations, you can use the
histogram verb to find all the primes with the same digits:

p 3

113 131 137 139 173 179 191 193 197 199 311 313 317 331 337 373 379 397 719
733 739 773 797 911 919 937 971 977 991 997


hist=:~.,: #/.~

hist ;10#.ea /:~ ea sep ea p 3

113 137 139 179 119 199 133 337 379 377 779 799

3 3 2 4 2 3 2 3 4 1 2 1


Skip Cave
Cave Consulting LLC


On Sat, Sep 23, 2023 at 12:53 AM Skip Cave  wrote:

> Here's a verb p(n) to produce all n-digit primes with the same digits:
>
> odo=:#: i.@(*/)
>
> p=:{{(#~1:)10#.(odo y#4){1 3 7 9}}
>
>
> try it:
>
> p 2
>
> 11 13 17 19 31 37 71 73 79 97
>
> p 3
>
> 113 131 137 139 173 179 191 193 197 199 311 313 317 331 337 373 379 397
> 719 733 739 773 797 911 919 937 971 977 991 997
>
> p 4
>
> 1117 1171 1193 1319 1373 1399 1733 1777 1913 1931 1933 1973 1979 1993 1997
> 1999 3119 3137 3191 3313 3319 3331 3371 3373 3391 3719 3733 3739 3779 3793
> 3797 3911 3917 3919 3931 7177 7193 7331 7333 7393 7717 7793 7919 7933 7937
> 7993 9133 9137 9173 9199 9311 9319 9337 9371 9377 9391 9397 9719 9733 9739
> 9791 9931 9973
>
> p 5
>
> 3 7 9 11131 11171 11173 11177 11197 11311 11317 11393 11399
> 11717 11719 11731 11777 11779 11933 11939 11971 13171 13177 13313 13331
> 13337 13339 13397 13399 13711 13799 13913 13931 13933 13997 13999 17117
> 17137 17191 17317 17333 17377 17393 17713 17737 17791 17911 17939 17971
> 17977 19139 19319 19333 19373 19379 19391 19717 19739 19777 19793 19913
> 19919 19937 19973 19979 19991 19993 19997 31139 31177 31193 31319 31333
> 31337 31379 31391 31393 31397 31771 31793 31799 31973 31991 33113 33119
> 33179 33191 33199 33311 33317 1 33377 33391 33713 33739 33773 33791
> 33797 33911 33931 33937 33997 37117 37139 37171 37199 37313 37337 37339
> 37379 37397 37717 37799 37991 37993 37997 39113 39119 39133 39139 39191
> 39199 39313 39317 39371 39373 39397 39719 39733 39779 39791 39799 39937
> 39971 39979 71119 71171 71191 71317 71333 71339 71399 71711 71713 71719
> 71777 71917 71933 71971 71993 71999 73133 73331 73379 73771 73939 73973
> 73999 77137 77171 77191 77317 77339 77377 77711 77713 77719 77731 3
> 77797 77933 77977 77999 79111 79133 79139 79193 79319 79333 79337 79379
> 79393 79397 79399 79777 79939 79973 79979 79997 7 91139 91193 91199
> 91331 91373 91393 91397 91711 91733 91771 91939 91997 93113 93131 93133
> 93139 93179 93199 93319 93337 93371 93377 93719 93739 93911 93913 93937
> 93971 93979 93997 97117 97171 97177 97373 97379 97397 97711 97771 97777
> 97919 97931 97973 99119 99131 99133 99137 99139 99173 99191 99317 99371
> 99377 99391 99397 99713 99719 99733 99793 99971 1
>
> Skip Cave
> Cave Consulting LLC
>
>
> On Sat, Sep 23, 2023 at 12:26 AM Richard Donovan 
> wrote:
>
>> Hi
>>
>> I am trying to develop a program to find primes with n digits abc such
>> that acb bac bca cab and cba are also primes. (obviously trivial if aaa is
>> prime!).
>>
>> An example with n=3 is
>>
>> 1 p: 199 919 991
>>
>> 1 1 1
>>
>> These primes are thin on the ground since they cannot contain any of the
>> digits 2 4 5 6 8 or 0 and I am wondering if it would be best to construct
>> numbers omitting those containing those prohibited digits, or test every
>> comination of p: i. n which seems wasteful, especially since I want to find
>> all such primes below one million.
>>
>> Can anyone see an efficent way to produce this?
>>
>> Thanks in advance,
>>
>> Richard
>> --
>> 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] Primes with combination of same digits

2023-09-22 Thread 'Skip Cave' via Programming
Here's a verb p(n) to produce all n-digit primes with the same digits:

odo=:#: i.@(*/)

p=:{{(#~1:)10#.(odo y#4){1 3 7 9}}


try it:

p 2

11 13 17 19 31 37 71 73 79 97

p 3

113 131 137 139 173 179 191 193 197 199 311 313 317 331 337 373 379 397 719
733 739 773 797 911 919 937 971 977 991 997

p 4

1117 1171 1193 1319 1373 1399 1733 1777 1913 1931 1933 1973 1979 1993 1997
1999 3119 3137 3191 3313 3319 3331 3371 3373 3391 3719 3733 3739 3779 3793
3797 3911 3917 3919 3931 7177 7193 7331 7333 7393 7717 7793 7919 7933 7937
7993 9133 9137 9173 9199 9311 9319 9337 9371 9377 9391 9397 9719 9733 9739
9791 9931 9973

p 5

3 7 9 11131 11171 11173 11177 11197 11311 11317 11393 11399
11717 11719 11731 11777 11779 11933 11939 11971 13171 13177 13313 13331
13337 13339 13397 13399 13711 13799 13913 13931 13933 13997 13999 17117
17137 17191 17317 17333 17377 17393 17713 17737 17791 17911 17939 17971
17977 19139 19319 19333 19373 19379 19391 19717 19739 19777 19793 19913
19919 19937 19973 19979 19991 19993 19997 31139 31177 31193 31319 31333
31337 31379 31391 31393 31397 31771 31793 31799 31973 31991 33113 33119
33179 33191 33199 33311 33317 1 33377 33391 33713 33739 33773 33791
33797 33911 33931 33937 33997 37117 37139 37171 37199 37313 37337 37339
37379 37397 37717 37799 37991 37993 37997 39113 39119 39133 39139 39191
39199 39313 39317 39371 39373 39397 39719 39733 39779 39791 39799 39937
39971 39979 71119 71171 71191 71317 71333 71339 71399 71711 71713 71719
71777 71917 71933 71971 71993 71999 73133 73331 73379 73771 73939 73973
73999 77137 77171 77191 77317 77339 77377 77711 77713 77719 77731 3
77797 77933 77977 77999 79111 79133 79139 79193 79319 79333 79337 79379
79393 79397 79399 79777 79939 79973 79979 79997 7 91139 91193 91199
91331 91373 91393 91397 91711 91733 91771 91939 91997 93113 93131 93133
93139 93179 93199 93319 93337 93371 93377 93719 93739 93911 93913 93937
93971 93979 93997 97117 97171 97177 97373 97379 97397 97711 97771 9
97919 97931 97973 99119 99131 99133 99137 99139 99173 99191 99317 99371
99377 99391 99397 99713 99719 99733 99793 99971 1

Skip Cave
Cave Consulting LLC


On Sat, Sep 23, 2023 at 12:26 AM Richard Donovan 
wrote:

> Hi
>
> I am trying to develop a program to find primes with n digits abc such
> that acb bac bca cab and cba are also primes. (obviously trivial if aaa is
> prime!).
>
> An example with n=3 is
>
> 1 p: 199 919 991
>
> 1 1 1
>
> These primes are thin on the ground since they cannot contain any of the
> digits 2 4 5 6 8 or 0 and I am wondering if it would be best to construct
> numbers omitting those containing those prohibited digits, or test every
> comination of p: i. n which seems wasteful, especially since I want to find
> all such primes below one million.
>
> Can anyone see an efficent way to produce this?
>
> Thanks in advance,
>
> Richard
> --
> 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] Interesting Quora Problem:

2023-09-11 Thread 'Skip Cave' via Programming
Wow! Raul & Ben both provided solutions to my Quora problem that were
radically different from my original solution, and radically different from
each other. Both solutions reduced the execution time & space by several
orders of magnitude, when compared with my original solution. Also, both
used different approaches that took advantage of features in J which I knew
about, but had not used very much. A good learning experience.

Raul used a 'chain of dyadic verbs' (x F x F x F y) to solve the problem. I
haven't ever tried this, where right-to-left execution is used to feed the
result of one dyadic verb into the next one on the left. It was a bit
confusing until I realized that the rightmost verb 'eats' its left
argument, so that the verb result is passed to the next verb on the left,
instead of the previous verb's left argument. This problem provides a good
example of the use of this feature.  I wonder if this linear 'chain of
verbs' could be replaced with the hatco operator (^:)?

Ben used the Anagram primitive (A.) to generate permutations of digits.
Now I'm still trying to get my head around (parse) the two direct
definitions Ben provided:

all =: ,/ odds {{ }. x 1 3 7 9 } y 2 4 6 8 } '0oeoe5eoeo' }}"1/ evens
all #~ (1+i.9) {{*./ 0 = x | ". x {."0 1 y }}"1 all

If explained in detail, this example would make a good tutorial on how to
use Direct Definition.

This Quora problem shows the versatility of J primitives, and how J can
provide multiple tools for different approaches to solve a specific
problem.

Skip Cave
Cave Consulting LLC


On Sun, Sep 10, 2023 at 1:01 PM Skip Cave  wrote:

> Quora Question: Can you arrange the digits 1-9 to make a nine-digit number
> such that the first digit is divisible by one, the first two digits are
> divisible by two, the first three divisible by three and so on?
>
> My solution:
> ea=.&.>
>
> at=.>10#.ea(a=.362880 9$1 to 9){.ea{n=.>:perm 9
>
> {:"1 at#~*./"1[0=a|"1 at
>
> 381654729
>
>
> The answer is 381654729.
>
>
> Check:
>
> ]m=.>10#.ea(;/1 to 9){.ea{sep 381654729
>
> 3 38 381 3816 38165 381654 3816547 38165472 381654729
>
> (1 to 9)| m
>
> 0 0 0 0 0 0 0 0 0
>
>
> There is only one answer. Is there a way to simplify or minimize the big
> repetitive array 'a' to make the two J code lines more memory efficient &
> succinct?
>
>
> Skip Cave
> Cave Consulting LLC
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Interesting Quora Problem:

2023-09-10 Thread 'Skip Cave' via Programming
Quora Question: Can you arrange the digits 1-9 to make a nine-digit number
such that the first digit is divisible by one, the first two digits are
divisible by two, the first three divisible by three and so on?

My solution:
ea=.&.>

at=.>10#.ea(a=.362880 9$1 to 9){.ea{n=.>:perm 9

{:"1 at#~*./"1[0=a|"1 at

381654729


The answer is 381654729.


Check:

]m=.>10#.ea(;/1 to 9){.ea{sep 381654729

3 38 381 3816 38165 381654 3816547 38165472 381654729

(1 to 9)| m

0 0 0 0 0 0 0 0 0


There is only one answer. Is there a way to simplify or minimize the big
repetitive array 'a' to make the two J code lines more memory efficient &
succinct?


Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Rank difficulties

2023-09-07 Thread 'Skip Cave' via Programming
Re the question: "why is J not as popular as it ought to be"
I provide J solutions to various problems on Quora <https://www.quora.com/>,
mainly to improve my J programming skills. I have solved thousands of Quora
problems over the last 8 years. Many of my solutions have tens of thousands
of views, and dozens of upvotes. I occasionally get comments asking about
J, both positive & negative.  The responses range from "I need to know
more" to "Too complex/terse". The most common response is "I never knew
about J" or the equivalent.
So it sounds like J needs a promo campaign.

I sporadically put the following text at the end of each of my J solutions
on Quora:
<<<>>>
“Civilization advances by extending the number of important operations
which we can perform without thinking of them.”
― Alfred North Whitehead
https://www.jsoftware.com/
J Promo Video: https://www.youtube.com/watch?v=aV936cVrN0I
J Playground: https://jsoftware.github.io/j-playground/bin/html/emj.html
<https://jsoftware.github.io/j-playground/bin/html/emj.html>
J Docs Pages: https://code2.jsoftware.com/mediawiki/index.php/Main_Page
New J Math: https://code.jsoftware.com/wiki/The_New_J_Math#beg
<<<>>>

Skip Cave
Cave Consulting LLC


On Thu, Sep 7, 2023 at 4:09 PM Piet de Jong  wrote:

> Thanks for all the great suggestions which has helped me a lot.
>
> To my mind it does raise a couple of issues or questions.
>
> I’ll stick my head out with them, knowing there might be much blowback.
> But bear with me.
>
> Slicing is a pretty intuitive concept so why should it be so intricate and
> “hard"?
>
> Maybe this is one of the reasons why J is not as popular as it ought to be.
>
> I “love” J and always use it.
>
> But I have not been able to convince a single other person to take it up.
>
> I’m always wondering why?   Does it mean it’s just too intricate for the
> average Joe.
> Most people on this forum I imagine love the intricacy and see it as an
> enjoyable challenge.
>
> But the average Joe just wants to solve problems as quickly as possible
> and get on with life, not waste time on challenging intricate puzzles.
>
> So perhaps J is too much “puzzle solving” rather than “problem solving”
>
> Notwithstanding the above — I’ll always stick with J.
>
>
> > On 8 Sep 2023, at 04:22, Jose Mario Quintana <
> jose.mario.quint...@gmail.com> wrote:
> >
> > Oops, I forgot o=. @:
> >
> > On Thu, Sep 7, 2023 at 1:27 PM Jose Mario Quintana <
> > jose.mario.quint...@gmail.com> wrote:
> >
> >>> The order of the last two appear "unnatural".  (To my way of thinking
> at
> >> least)
> >>> This seems to beg the question what is the natural order when  slicing.
> >>
> >> The answer might depend on the intended usage of the verb that you have
> in
> >> mind. If, for example,
> >> you want to preserve the order of the remaining axes, then Henry's
> >> suggestion modified by Raul would work,
> >>
> >>   $ Y=. i.2 3 4 5
> >> 2 3 4 5
> >>
> >>   slicep=. ~.@(, i.@#@$) |: ]
> >>
> >>   (0 1 2 3) ($ o slicep"0 _) Y
> >> 2 3 4 5
> >> 3 2 4 5
> >> 4 2 3 5
> >> 5 2 3 4
> >>
> >> Another possibility is to rotate the axes,
> >>
> >>   slicer=. (|. i.@:#@:$@:]) |: ]
> >>
> >>   (0 1 2 3) ($ o slicer"0 _) Y
> >> 2 3 4 5
> >> 3 4 5 2
> >> 4 5 2 3
> >> 5 2 3 4
> >>
> >> I hope this helps
> >>
> >>
> >> On Wed, Sep 6, 2023 at 7:58 PM Piet de Jong  wrote:
> >>>
> >>> This works!
> >>> Except the ordering of the axes is slightly unusual to my way of
> >> thinking.
> >>> For example suppose m=.i.3 3 3 is the “cube" be sliced and v is your
> >> verb.
> >>> Then the items of (0 v m) has successive items  “going back” into the
> >> cube.
> >>> The items (1 v m) are the horizontal slices.
> >>> The items of (2 v m) are the vertical slices.
> >>>
> >>> The order of the last two appear "unnatural".  (To my way of thinking
> at
> >> least)
> >>> This seems to beg the question what is the natural order when  slicing.
> >>>
> >>>> On 7 Sep 2023, at 08:32, Henry Rich  wrote:
> >>>>
> >>>> Since you want all the slices, what you are looking for is a
> transpose.
> >>>>
> >>>> Maybe
> >>>>
> >>>> ~.@(, i.@#) |: ]
> >>>>
> >

[Jprogramming] Google Bard question.

2023-08-29 Thread 'Skip Cave' via Programming
What are the best computer languages to deal with matrix operations?

There are many programming languages that are well-suited for matrix
operations. Here are some of the most popular ones:

   - MATLAB: MATLAB is a proprietary programming language developed by
   MathWorks. It is specifically designed for mathematical computing and has a
   wide range of built-in functions for matrix operations. MATLAB is a
   powerful language, but it can be expensive to license.
   [image: MATLAB programming language logo]Opens in a new window
   <https://en.wikipedia.org/wiki/MATLAB>en.wikipedia.org
   <https://en.wikipedia.org/wiki/MATLAB>
   MATLAB programming language logo
   - Python: Python is a general-purpose programming language that is
   becoming increasingly popular for scientific computing. It has a large and
   active community of developers, and there are many libraries available for
   matrix operations. Python is also free and open-source.
   [image: Python programming language logo]Opens in a new window
   <https://en.wikipedia.org/wiki/Python_(programming_language)>
   en.wikipedia.org
   <https://en.wikipedia.org/wiki/Python_(programming_language)>
   Python programming language logo
   - Julia: Julia is a relatively new programming language that is designed
   to be fast and efficient for numerical computing. It is still under
   development, but it has a growing community of users.
   [image: Julia programming language logo]Opens in a new window
   <https://en.wikipedia.org/wiki/Julia_(programming_language)>
   en.wikipedia.org
   <https://en.wikipedia.org/wiki/Julia_(programming_language)>
   Julia programming language logo
   - R: R is a statistical programming language that is widely used for
   data analysis. It has a number of built-in functions for matrix operations,
   and there are many additional libraries available.
   [image: R programming language logo]Opens in a new window
   <https://commons.wikimedia.org/wiki/File:R_logo.svg>commons.wikimedia.org
   <https://commons.wikimedia.org/wiki/File:R_logo.svg>
   R programming language logo
   - C/C++: C/C++ are compiled languages that are known for their speed and
   efficiency. They are not as well-suited for matrix operations as some of
   the other languages on this list, but they can be used for very large and
   complex calculations.
   [image: C programming language logo]Opens in a new window
   <https://commons.wikimedia.org/wiki/File:C_Programming_Language.svg>
   commons.wikimedia.org
   <https://commons.wikimedia.org/wiki/File:C_Programming_Language.svg>
   chevron_right
   C programming language logo

The best language for you will depend on your specific needs and
requirements. If you are looking for a powerful and versatile language with
a wide range of built-in functions, then MATLAB is a good choice. If you
are looking for a free and open-source language with a large community of
users, then Python is a good option. If you need a language that is fast
and efficient for numerical computing, then Julia is a good choice. If you
are primarily interested in statistical analysis, then R is a good choice.
And if you need a language that is very fast and efficient, then C/C++ are
good choices.

Ultimately, the best way to decide which language is right for you is to
try them out and see which one you prefer. There are many resources
available online and in libraries that can help you get started.
Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Anagram Operator (A.) and Generalized Datatype declaration in function assignments.

2023-08-14 Thread 'Skip Cave' via Programming
t=.{{":y}}

t 12345678987654321

12345678987654321


datatype t 12345678987654321

literal


Skip Cave
Cave Consulting LLC


On Mon, Aug 14, 2023 at 1:29 PM Gilles Kirouac  wrote:

>  >>> What expression allows a function to recieve an argument 'y' as a
> literal
>  >>> without using quotes?
>
> None.
>
> BTW, do not rely on the output of ": (default format) to determine the
> type, because it uses a default format with a default precision. Use
> datatype instead.
>
> datatype 180548043269214561950911457875657
> floating
> datatype 180548043269214561950911457875657x
> extended
>  34j0 ": 180548043269214561950911457875657
>   18054804326921457349416459226316  NB. loss of precision after 15 digits
>  34j0 ": 180548043269214561950911457875657x
>   180548043269214561950911457875657 NB. no loss of precision
>
>
>
> ~ Gilles
>
> Le 2023-08-14 à 14:00, Ak O a écrit :
> > Unfortunately ": does not work in this case.
> > The length of the input causes the input to be treated as a float.  The
> > result  is:
> >
> >   ": 180548043269214561950911457875657
> > 1.80548e32
> >
> >
> >
> > On Mon., Aug. 14, 2023, 11:16 'Skip Cave' via Programming, <
> > programm...@jsoftware.com> wrote:
> >
> >> ":y converts an integer in y into a literal.
> >>
> >> Skip Cave
> >> Cave Consulting LLC
> >>
> >>
> >> On Mon, Aug 14, 2023 at 11:58 AM Ak O  wrote:
> >>
> >>> What expression allows a function to recieve an argument 'y' as a
> literal
> >>> without using quotes?
> >>>
> >>> Below are two  deficient functions.
> >>> The size of the vector is given by 'x'. The permutation
> >>> index is meant to be given by 'y'.
> >>>
> >>> My intention is treat 'y' as a literal, without needing to use quotes
> on
> >>> the input.
> >>>
> >>> This first function works by escaping to the keyboard for input
> >>> I would like rather for the function to receive the input from the raw
> >>> argument and not have to escape to the keyboard.
> >>>
> >>> Desired Input
> >>> 30 extd 180548043269214561950911457875657
> >>> Rather than
> >>> 30 extd '180548043269214561950911457875657'
> >>>
> >>>
> >>> This function is deficient by its operating sequence.
> >>> It escapes to keyboard, which preservs the literal type.
> >>>
> >>> extd =: 4 : 0
> >>> n=. ((1!:1) 1
> >>> ((".@,&'x' n)) A. i. x
> >>> )
> >>>
> >>> 30 extd 180548043269214561950911457875657
> >>>
> >>> Keyboard input (if this approach makes sense, can the keyboard input
> be
> >>> simulated by using y as the feed?)
> >>> 180548043269214561950911457875657
> >>>
> >>> Result
> >>> 20 12 4 29 7 17 22 11 2 27 28 23 6 21 9 3 24 10 26 13 15 1 18 8 25 19
> 0 5
> >>> 16 14
> >>>
> >>>
> >>>
> >>> Alternative deficient function by the input form.
> >>> Yields the correct result  but uses quotes in the input.
> >>>
> >>> extdquotes =: 4 : 0
> >>> ((".@,&'x' n)) A. i. x
> >>> )
> >>>
> >>> 30 extdquotes '180548043269214561950911457875657'
> >>>
> >>> Result
> >>> 20 12 4 29 7 17 22 11 2 27 28 23 6 21 9 3 24 10 26 13 15 1 18 8 25 19
> 0 5
> >>> 16 14
> >>>
> >>>
> >>> I am looking for the function that uses the input for extd that
> delivers
> >>> the result of extdquotes
> >>>
> >>>
> >>> Thank you for your help
> >>> Ak
> >>>
>   ...
> --
> 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] Anagram Operator (A.) and Generalized Datatype declaration in function assignments.

2023-08-14 Thread 'Skip Cave' via Programming
":y converts an integer in y into a literal.

Skip Cave
Cave Consulting LLC


On Mon, Aug 14, 2023 at 11:58 AM Ak O  wrote:

> What expression allows a function to recieve an argument 'y' as a literal
> without using quotes?
>
> Below are two  deficient functions.
> The size of the vector is given by 'x'. The permutation
> index is meant to be given by 'y'.
>
> My intention is treat 'y' as a literal, without needing to use quotes on
> the input.
>
> This first function works by escaping to the keyboard for input
> I would like rather for the function to receive the input from the raw
> argument and not have to escape to the keyboard.
>
> Desired Input
> 30 extd 180548043269214561950911457875657
> Rather than
> 30 extd '180548043269214561950911457875657'
>
>
> This function is deficient by its operating sequence.
> It escapes to keyboard, which preservs the literal type.
>
> extd =: 4 : 0
> n=. ((1!:1) 1
> ((".@,&'x' n)) A. i. x
> )
>
> 30 extd 180548043269214561950911457875657
>
> Keyboard input (if this approach makes sense, can the keyboard input  be
> simulated by using y as the feed?)
> 180548043269214561950911457875657
>
> Result
> 20 12 4 29 7 17 22 11 2 27 28 23 6 21 9 3 24 10 26 13 15 1 18 8 25 19 0 5
> 16 14
>
>
>
> Alternative deficient function by the input form.
> Yields the correct result  but uses quotes in the input.
>
> extdquotes =: 4 : 0
> ((".@,&'x' n)) A. i. x
> )
>
> 30 extdquotes '180548043269214561950911457875657'
>
> Result
> 20 12 4 29 7 17 22 11 2 27 28 23 6 21 9 3 24 10 26 13 15 1 18 8 25 19 0 5
> 16 14
>
>
> I am looking for the function that uses the input for extd that delivers
> the result of extdquotes
>
>
> Thank you for your help
> Ak
>
>
> On Sat., Aug. 12, 2023, 13:43 Henry Rich,  wrote:
>
> > It's like this:
> >
> > /long-number/ is a single word.  If the length is <19 digits, it is an
> > integer, otherwise a float (which necessarily has only 16 digits of
> > precision).
> >
> > /long-number/x is a single word, but it is always an extended integer,
> > and every digit of /long-number/ is preserved.
> >
> > x: /number/ is two words.  /number/ is evaluated first, and then x: is
> > applied to its value to give an extended integer.
> >
> > In that last case, if /number/ has more than 19 digits, it will have
> > been represented as a float, and the extended integer will have only 16
> > digits of precision.
> >
> > Henry Rich
> >
> > On 8/12/2023 3:25 PM, Ak O wrote:
> > > My thought was that 'x' must always be  extended by definition.
> > >
> > > I was trying to think what cases this operator's 'x' argument would not
> > be
> > > strictly extended.
> > >
> > > Chris demonstrated that the input 'x' in my example is float by
> > > construction.
> > >
> > > Raul explained that the  parser treats the number before it treats the
> > > operator  ( if I have understood his message correctly).
> > >
> > > So if I have understood all of this correctly. As a raw input, it is
> the
> > > extended representation of the float input 'x' that is actually what is
> > > being operated on by A. to yield the result.
> > >
> > >
> > >
> > > Ak
> > >
> > >
> > > On Sat., Aug. 12, 2023, 11:34 Henry Rich, 
> wrote:
> > >
> > >> I misunderstood your question.
> > >>
> > >> (x A. y) starts by verifying that (*./ (|x) < !.#y) and then converts
> x
> > >> to a permutation with
> > >> (i.@-&.<: y) #: x
> > >> (all in extended precision if x is extended), followed by a number of
> > >> rotations within an index vector.  It is much less work to start with
> > >> the permutation vector rather than the anagram index.
> > >>
> > >> Henry Rich
> > >>
> > >> On 8/11/2023 8:29 PM, Ak O wrote:
> > >>> For me,
> > >>> (x: y)
> > >>> does not preserve the input.
> > >>>
> > >>> The result I get is not the same.
> > >>>
> > >>>
> > >>> ( x:180548043269214561950911457875657 )
> > >>>180548043269214573494164592263168
> > >>> This does not work.
> > >>>
> > >>>
> > >>>
> > >>> 180548043269214561950911457875657x
> > >>> 180548043269214561950911457875657
> > >>&

Re: [Jprogramming] Advent of Code 2022 in J, as a tutorial

2023-08-09 Thread 'Skip Cave' via Programming
-first-number-What-is-the-second-number/answer/Ellis-Cave>
The unit of a two-digit number is 2 less than the tens digits. If the
number is decreased by 13 and then divided by the sum of the digits, the
result is 5. What is the number?
<https://www.quora.com/The-unit-of-a-two-digit-number-is-2-less-than-the-tens-digits-If-the-number-is-decreased-by-13-and-then-divided-by-the-sum-of-the-digits-the-result-is-5-What-is-the-number/answer/Ellis-Cave>
What is the number of integers between 101 and 199 which are exactly
divisible by 5 or 7?
<https://www.quora.com/What-is-the-number-of-integers-between-101-and-199-which-are-exactly-divisible-by-5-or-7/answer/Ellis-Cave>
How many integers (positive and negative) are divisors of 20?
<https://www.quora.com/How-many-integers-positive-and-negative-are-divisors-of-20/answer/Ellis-Cave>
What is a number which is of 4 digits and divisible by 3 but not by 9?
<https://www.quora.com/What-is-a-number-which-is-of-4-digits-and-divisible-by-3-but-not-by-9/answer/Ellis-Cave>
What is a five-digit number divisible by 2, 3, 4, and 9?
<https://www.quora.com/What-is-a-five-digit-number-divisible-by-2-3-4-and-9/answer/Ellis-Cave>
How many numbers between 1 and 1000 are divisible by 3 and 7 but not 2, 5
or 11?
<https://www.quora.com/How-many-numbers-between-1-and-1000-are-divisible-by-3-and-7-but-not-2-5-or-11/answer/Ellis-Cave>
How many numbers from 100 to 1 have EXACTLY 3 of the same digit?
<https://www.quora.com/How-many-numbers-from-100-to-1-have-EXACTLY-3-of-the-same-digit/answer/Ellis-Cave>
Assume you have a 3 digit number, the last digit is twice as big as the
first digit.The product of all the digits is 14.what is the number?
<https://www.quora.com/Assume-you-have-a-3-digit-number-the-last-digit-is-twice-as-big-as-the-first-digit-The-product-of-all-the-digits-is-14-what-is-the-number/answer/Ellis-Cave>
How do I prove that 1+2–√+3–√+4–√+…100−−−√<676?
<https://www.quora.com/How-do-I-prove-that-1-sqrt-2-sqrt-3-sqrt-4-sqrt-100-676/answer/Ellis-Cave>
What are four irrational numbers between 3/4 and 4/5?
<https://www.quora.com/What-are-four-irrational-numbers-between-3-4-and-4-5/answer/Ellis-Cave>
For positive integer a, b, are there any satisfy 3 (a^2-ab+b^2) = 71(a+b)?
<https://www.quora.com/For-positive-integer-a-b-are-there-any-satisfy-3-a-2-ab-b-2-71-a-b/answer/Ellis-Cave>
How many numbers from 2000 to 2101 are divisible by 2 or by 3?
<https://www.quora.com/How-many-numbers-from-2000-to-2101-are-divisible-by-2-or-by-3/answer/Ellis-Cave>

There are many hundreds more like these.

Skip

Skip Cave
Cave Consulting LLC


On Wed, May 31, 2023 at 10:01 AM Henry Rich  wrote:

> How do you convince someone that J is really different?  Examples seem
> contrived.
>
> I am trying something new.  I have used J to solve a suite of
> programming problems posed by an impartial source, to wit Advent of Code
> 2022.  Tire-kickers can compare the J solutions against those in other
> languages.
>
> The pages are at https://code.jsoftware.com/wiki/ShareMyScreen .
>
> IF YOU ARE NEW TO J, you are the person I need to hear from. Where do I
> need to add explanatory material, or rewrite a section?
>
> IF YOU ARE AN OLD J HAND, consider adding your own programs.  They can
> be from any source as long as you make the solution comprehensible to a
> novice.
>
> I know several users on this list solved the AoC2022 problems;
> alternative solution pages would be welcome.
>
> Henry Rich
>
>
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Rotating rows

2023-06-12 Thread 'Skip Cave' via Programming
Rob,
Rotate by row/column was exactly what I needed, thanks!

Tony,
Wow! I didn't know that catalog worked like that!  Thanks!

Skip

Skip Cave
Cave Consulting LLC


On Mon, Jun 12, 2023 at 2:53 AM 'Rob Hodgkinson' via Programming <
programm...@jsoftware.com> wrote:

> See dyadic rotate (
> https://code.jsoftware.com/wiki/Vocabulary/bardot#dyadic)
>
> APL had rotate on either first or last axis, and J has rotate that can be
> ‘adapted’ to do what you want using rank:
>
>]s1=.4 4${(4#'ABCD'),.(-.&' ')":4#1234
> ┌──┬──┬──┬──┐
> │A1│A2│A3│A4│
> ├──┼──┼──┼──┤
> │B1│B2│B3│B4│
> ├──┼──┼──┼──┤
> │C1│C2│C3│C4│
> ├──┼──┼──┼──┤
> │D1│D2│D3│D4│
> └──┴──┴──┴──┘
>
> 0 1 2 3 |."0 1 s1 NB. Rotate Item 1 by 0, Item 2 by 1
> (left), Item 3 by 2 (left), Item 4 by 3 (left)
> ┌──┬──┬──┬──┐
> │A1│A2│A3│A4│
> ├──┼──┼──┼──┤
> │B2│B3│B4│B1│
> ├──┼──┼──┼──┤
> │C3│C4│C1│C2│
> ├──┼──┼──┼──┤
> │D4│D1│D2│D3│
> └──┴──┴──┴──┘
>
> 0 1 2 3 |."0 1&.|: s1 NB. This same as above but uses &.
> (And it’s inverse) to transpose the matrix before and after the rotate, so
> that the same operation now works column wise
> ┌──┬──┬──┬──┐
> │A1│B2│C3│D4│
> ├──┼──┼──┼──┤
> │B1│C2│D3│A4│
> ├──┼──┼──┼──┤
> │C1│D2│A3│B4│
> ├──┼──┼──┼──┤
> │D1│A2│B3│C4│
> └──┴──┴──┴──┘
>
> Is this what you are after Skip ?   HTH, Rob
>
> > On 12 Jun 2023, at 5:34 pm, 'Skip Cave' via Programming <
> programm...@jsoftware.com> wrote:
> >
> > I can generate a 4x4 square with unique identifiers in each square:
> >
> > ]s1=.4 4${(4#'ABCD'),.(-.&' ')":4#1234
> >
> > ┌──┬──┬──┬──┐
> >
> > │A1│A2│A3│A4│
> >
> > ├──┼──┼──┼──┤
> >
> > │B1│B2│B3│B4│
> >
> > ├──┼──┼──┼──┤
> >
> > │C1│C2│C3│C4│
> >
> > ├──┼──┼──┼──┤
> >
> > │D1│D2│D3│D4│
> >
> > └──┴──┴──┴──┘
> >
> > How can I rotate each row a different amount?
> >
> > I want to rotate row zero 0 cells left, row 1 one cell left, row 2 two
> > cells left, & row three 3 cells left?
> >
> >
> > How to do the same for columns?
> >
> > 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


[Jprogramming] Rotating rows

2023-06-12 Thread 'Skip Cave' via Programming
I can generate a 4x4 square with unique identifiers in each square:

]s1=.4 4${(4#'ABCD'),.(-.&' ')":4#1234

┌──┬──┬──┬──┐

│A1│A2│A3│A4│

├──┼──┼──┼──┤

│B1│B2│B3│B4│

├──┼──┼──┼──┤

│C1│C2│C3│C4│

├──┼──┼──┼──┤

│D1│D2│D3│D4│

└──┴──┴──┴──┘

How can I rotate each row a different amount?

I want to rotate row zero 0 cells left, row 1 one cell left, row 2 two
cells left, & row three 3 cells left?


How to do the same for columns?

Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] GitHub Copilot anyone used this with J?

2023-05-09 Thread 'Skip Cave' via Programming
A few years ago, I came up with this verb to find palindromic integers in a
list of integers:

pal=.]#~(=|.&.":&>)


Test:

pal 12321 12322 345 343 789987 9878

12321 343 789987


Is there a more efficient approach?



Skip Cave
Cave Consulting LLC


On Tue, May 9, 2023 at 12:56 PM 'Michael Day' via Programming <
programm...@jsoftware.com> wrote:

> I realise this thread is about experimenting with AI coding in J, so
> forgive me for
> merely suggesting just another function  for a shortest derived
> palindrome formed
> by prepending a string to a given string:
>
> NB. Test palindrome-ness with a hook:
> ispal =: -:|.
>
> NB. Form palindrome given character string (or numeric vector) y
> mdpal =: {{
> y,~ |.y}.~ (>:@i:&1) ispal \ y
> }}
>
> mdpal 'abcd'
> dcbabcd
> mdpal 'aacecaaa'
> aaacecaaa
>
> Appending a string might be better:
> mdpal 'abcbadefg'
> gfedabcbadefg
>
> mdpal&.|. 'abcbadefg'  NB. simulate appending by working on reverse...
> abcbadefgfedabcba
> ... though not in this case!
>
> Just for fun,
>
> Mike
> PS - I am not  a Robot !?
>
>
>
> On 07/05/2023 10:30, Thomas McGuire wrote:
> > Forgive me for keeping my own thread alive.
> >
> > This article at Hackernoon put together a comparison of Coding AI bots
> using Leetcode questions as the stem:
> >
> https://hackernoon.com/how-ai-bots-code-comparing-bing-claude-co-pilot-gpt-4-and-bard
> 
> > How AI Bots Code: Comparing Bing, Claude+, Co-Pilot, GPT-4 and Bard
> > hackernoon.com
> >
> > Co-pilot was the easiest one for me to access so that’s why I chose it.
> >
> > So following hackernoon’s lead here are the results on Leetcode question
> 214:
> >
> > STEM:
> > NB. find the shortest palindrome for a string by adding letters to the
> front of it
> > shortpal =: 3 : 0
> >
> > Copilot code:
> > NB. find the shortest palindrome for a string by adding letters to the
> front of it
> > shortpal =: 3 : 0
> >'s'=.y
> >n=. #s
> >for_i. n do.
> >  if. (s i.~ |. s) = s do.
> >return. s
> >  end.
> >  s=. (i{a.) , s
> >end.
> > )
> >
> > Now the copilot code doesn’t work but the structure of this very
> un-J-like code is workable. I made some changes and got it working:
> > Copilot code fixed to work:
> > shortpal1 =: 3 : 0
> >'s'=.y
> >n=. #s
> >for_i. s do.
> >  if. s -: |. s do.
> >return. s
> >  end.
> >  s=. (|.(_1-i_index){.s) , y
> >end.
> > )
> >
> > the changes were
> > - fixed the palindrome test to exit the function.
> > - fixed the building of the palindrome alway starting from the original
> string, catenating the reverse of the next increment of letters from the
> end of the string.
> >
> >
> >
> > My J way of handling this problem is as follows:
> > NB. fpal - filter for palindromes, return the palindrome else return
> > NB.empty atom if not a palindrome
> > fpal=: 0&$`]@.(] -: |.)
> >
> > NB. mkpalindrome - make palindrome by catenating reversed suffixes
> > NB.filter out the palindromes, remove empty boxed
> > NB.elements. Then get the shortest one created which
> > NB.is the tail of the boxed list. unbox the answer
> > mkpalindrome =: {{>@{:@-.&(<'') <@fpal@(,)@|.\.y}}
> >
> > Running this on the leetcode simple examples:
> > mkpalindrome 'abcd'
> > dcbabcd
> > mkpalindrome 'aacecaaa'
> > aaacecaaa
> >
> > Interestingly, in my previous email ,Copilot was able to discern the
> fork for average. In the palindrome case the fairly well known fork for
> palindrome testing was not discovered by Copilot.  Yet when I was
> developing my 'improved 'J example. I happened to type the following:
> > NB. test if string is a palindrome
> >
> > Copilot responded:
> > pal =: 3 : 0
> >s=.y
> >s -: |. s
> > )
> >
> > This is close to the fork implementation.
> >
> > I won’t post the code, but by using the {{}} method of function calls
> Copilot produced a child like attempt at a J one liner. When I used an open
> paren ‘(' to see if I could force a fork implementation it again gave a
> child like response for a J fork. Neither of the answers were working code.
> >
> > Copilot is supposed to be pair programming with an AI bot. The github
> site indicates that in Python about 40% of the Copilot suggested Python
> code gets used. In o

Re: [Jprogramming] File Operations

2023-02-01 Thread 'Skip Cave' via Programming
I tried Bill's suggestion:

fn =. < 'C:\Users\skip\J904-user\temp'

fn (fwrite~ 3!:1) {2,\?15#50

_1


(3!:2)@fread fn

|domain error

| (3!:2)@fread fn


Looks like some kind of write error. Where in the doc are these errors
defined?

Skip Cave
Cave Consulting LLC


On Wed, Feb 1, 2023 at 11:07 PM bill lam  wrote:

> 1!:1 and 1!:2 can only operate on simple strings (rank 1 literal array)
> You can use 3!:1 and 3!:2 to convert between J array and simple string,eg
>
>  fn (fwrite~ 3!:1) {2,\?15#50
>
> (3!:2)@fread fn
>
> this way you need not assign the value of {2,\?15#50 to a name
>
> On Thu, Feb 2, 2023 at 12:48 PM 'Skip Cave' via Programming <
> programm...@jsoftware.com> wrote:
>
> > I have a boxed noun:
> >
> > ] testfile =: {2,\?15#50
> >
> >
> >
> ┌┬─┬─┬─┬─┬─┬┬┬┬┬─┬┬───┬┐
> >
> > │9 21│21 47│47 37│37 13│13 33│33 20│20 4│4 49│49 6│6 25│25 33│33 9│9 6│6
> > 43│
> >
> >
> >
> └┴─┴─┴─┴─┴─┴┴┴┴┴─┴┴───┴┘
> >
> >
> > I want to store it in the following location on my machine:
> >
> >
> > ]fn =. < 'C:\Users\skip\J904-user\temp'
> >
> > ┌┐
> >
> > │C:\Users\skip\J904-user\temp│
> >
> > └┘
> >
> > Then I will close that J session.
> >
> >
> > Later, I will start a new J session, and I want to read that saved file
> > into a noun called 'test1'
> >
> >
> > What is the J code for writing the noun into a file in the first session?
> >
> > What is the J code to read the file into a noun in the second session?
> >
> > Should I use 1!2 & 1!:1, or fwrite & fread, or something else?
> >
> >
> > Where in the J doc are these file operations and their tradeoffs
> described?
> >
> >
> > 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


[Jprogramming] File Operations

2023-02-01 Thread 'Skip Cave' via Programming
I have a boxed noun:

] testfile =: {2,\?15#50

┌┬─┬─┬─┬─┬─┬┬┬┬┬─┬┬───┬┐

│9 21│21 47│47 37│37 13│13 33│33 20│20 4│4 49│49 6│6 25│25 33│33 9│9 6│6 43│

└┴─┴─┴─┴─┴─┴┴┴┴┴─┴┴───┴┘


I want to store it in the following location on my machine:


]fn =. < 'C:\Users\skip\J904-user\temp'

┌┐

│C:\Users\skip\J904-user\temp│

└┘

Then I will close that J session.


Later, I will start a new J session, and I want to read that saved file
into a noun called 'test1'


What is the J code for writing the noun into a file in the first session?

What is the J code to read the file into a noun in the second session?

Should I use 1!2 & 1!:1, or fwrite & fread, or something else?


Where in the J doc are these file operations and their tradeoffs described?


Skip


Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Interesting Question on Quora

2022-12-28 Thread 'Skip Cave' via Programming
Is J programming language suitable for machine learning, especially with
reinforcement learning?

https://www.quora.com/Is-J-programming-language-suitable-for-machine-learning-especially-with-reinforcement-learing?q=J%20programming
<https://www.quora.com/Is-J-programming-language-suitable-for-machine-learning-especially-with-reinforcement-learing?q=J%20programming>

Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Catenating columns.

2022-12-06 Thread 'Skip Cave' via Programming
Elijah,
that's what I want!

54 48,"_ 0 i.10

54 48 0

54 48 1

54 48 2

54 48 3

54 48 4

54 48 5

54 48 6

54 48 7

54 48 8

54 48 9


Where can I find the documentation on *,"_ 0 * ??


Skip Cave
Cave Consulting LLC


On Tue, Dec 6, 2022 at 1:32 AM Elijah Stone  wrote:

> ,. is ,"_1; in other words, catenate corresponding cells of each argument.
> 54 48 has 2 cells, but i.10 has 10 cells; that doesn't work.
>
> Perhaps you want 54 48 ,"_ 0 i.10.
>
> On Tue, 6 Dec 2022, 'Skip Cave' via Programming wrote:
>
> > I can add a column of increasing integers to a fixed integer:
> >
> > 48,.i.10
> >
> > 48 0
> >
> > 48 1
> >
> > 48 2
> >
> > 48 3
> >
> > 48 4
> >
> > 48 5
> >
> > 48 6
> >
> > 48 7
> >
> > 48 8
> >
> > 48 9
> >
> >
> > Now I want to add the same increasing column to *two* fixed integers:
> >
> > 54 48,.i.10
> >
> > |length error
> >
> > | 54 48 ,.i.10
> >
> >
> > Why doesn't this work?
> >
> > 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


[Jprogramming] Catenating columns.

2022-12-05 Thread 'Skip Cave' via Programming
I can add a column of increasing integers to a fixed integer:

48,.i.10

48 0

48 1

48 2

48 3

48 4

48 5

48 6

48 7

48 8

48 9


Now I want to add the same increasing column to *two* fixed integers:

54 48,.i.10

|length error

| 54 48 ,.i.10


Why doesn't this work?

Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Differentiation problem

2022-11-24 Thread 'Skip Cave' via Programming
What is the equivalent of the program:
* plot|:^@-@-:@^&2"0 D.(i.3)10%~50-~i.101*
for users of J version 9.04g,  where the D. primitive has been removed?
Where is the doc on the new calculus functions?

Skip

Skip Cave
Cave Consulting LLC


On Thu, Nov 24, 2022 at 12:01 PM 'Bo Jacoby' via Programming <
programm...@jsoftware.com> wrote:

>plot|:^@-@-:@^&2"0 D.(i.3)10%~50-~i.101
>
>
> NB. The blue curve is the bell curve. Mean value = 50. Standard deviation
> = 10NB. The read curve is the derivative of the blue curve. It crosses Y=0
> at X=50NB. The green curve is the derivative of the red curve. It crosses
> Y=0 at X=50-10 and X=50+10
> NB. But why is the green curve so ugly around X=50?
> 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


Re: [Jprogramming] Truncating primes

2022-11-19 Thread 'Skip Cave' via Programming
Interesting!

Now what is the J verb that will find an n-digit integer that is still
prime when each of the digits are removed?


Skip Cave
Cave Consulting LLC


On Sat, Nov 19, 2022 at 3:51 PM Richard Donovan 
wrote:

> Hi
>
> I am doing experiments with large primes, in particular looking at primes
> that remain primes when n digits are truncated from the left. For example
> 6391373391373913731373373733 remains prime at each
> step.
>
> The largest of these in base 10 is 357686312646216567629137.
>
> I wrote the following code in preparation for further investigation but I
> find that the 24 digit number above is not handled as I wish it to be, as
> you will see below.
>
> What have I missed?
>
> Thanks
>
>
>
>
> digits
> "."0@":
>
> ltrunc
> 3 : 0"0 0 0
> n=: ": 0, }. digits y
> x: ". n-. ' '
> )
>
>
>
> NB. Works fine with 7 digit number...
> ltrunc^:a: 6391373
> 6391373391373913731373   3737330
>
>
> NB. But I can’t get it working for a 24 digit number!
> ltrunc 357686312646216567629137
> 0 0 5 7 6 8 6 0 2 3
> ltrunc 357686312646216567629137x
> 57686312646216568012800
> ltrunc x:357686312646216567629137x
> 57686312646216568012800
>
> Is there a way around the limit?
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] SEMANTiCS 2022: Programme Highlights in One Place

2022-09-28 Thread 'Skip Cave' via Programming
Search for many organizations does not work at all. Researchers have found
that Knowledge Graphs provide an efficient way to express the knowledge in
complex subjects. Knowledge Graphs would likely provide a more
comprehensive & effective way to organize the information in the J Wiki, as
well as provide an effective search engine to help users find the
information they need in the Wiki.

In this talk <https://www.youtube.com/watch?v=9PbuiuJ3iYw=9644s>,
Enterprise Knowledge CEO Zach Wahl and COO Joseph Hilger will guide you
through using enterprise knowledge graphs to deliver search results that
are in context and reflect user intent.

Here's a link to all the talks at the Semantics 2022 conference:
https://www.poolparty.biz/blogposts/poolparty-at-semantics-2022/?utm_medium=email&_hsmi=227453957&_hsenc=p2ANqtz-8vjJ4PsmJ4IGlj7SmhkQ3qV6r2Yh64esEUc7DkIeeNIE50PwxBzKgCQ9PCFx75x7WkeyFv4fZGvkj4vpaeNU5GLKO_1A_content=227388015_source=hs_email


Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Sort

2022-03-13 Thread 'Skip Cave' via Programming
Is this how sort is supposed to work?

sep=:10#.^:_1]


|:sep 120 to 130

1 1 1 1 1 1 1 1 1 1 1

2 2 2 2 2 2 2 2 2 2 3

0 1 2 3 4 5 6 7 8 9 0


/:~|:sep 120 to 130

0 1 2 3 4 5 6 7 8 9 0

1 1 1 1 1 1 1 1 1 1 1

2 2 2 2 2 2 2 2 2 2 3

Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Power Conjunction

2022-03-05 Thread 'Skip Cave' via Programming
From Ian:

q=.*~+3+]

q i.10

3 5 9 15 23 33 45 59 75 93


Wow! even more concise! I would have never thought to look that sequence up
on OEIS for the formula.


Skip


Skip Cave
Cave Consulting LLC


On Sun, Mar 6, 2022 at 12:37 AM 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
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Power Conjunction

2022-03-05 Thread 'Skip Cave' via Programming
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


Re: [Jprogramming] Programming question

2022-01-22 Thread Skip Cave
Also,

Also, why doesn't this work:

F=.{{{.n#~y=+/\c1 n=.>:i.100}}

F 19

F(19)




Skip Cave
Cave Consulting LLC


On Sat, Jan 22, 2022 at 11:50 PM Skip Cave  wrote:

> Thanks for all the examples. I thought that the solution would be pretty
> straightforward.
>
> c1 gives the number of ones in an integer:
> * c1=.{{+/1=10#.^:_1]y}}"0*
>
>
> Test it:
>
> * c1 211*
>
> *2*
>
>
> So the number of ones from 1 to 81 is:
>
> * +/c1 i.>:81*
>
> *19*
>
> To develop the inverse verb F, we can get a running sum of ones:
>  *  +/\c1 >:i.100*
>
> * 1 1 1 1 1 1 1 1 1 2 4 5 6 7 8 9 10 11 12 12 13 13 13 13 13 13 13 13 13
> 13 14 14 14 14 14 14 14 14 14 14 15 15 15 15 15 15 15 15 15 15 16 16 16 16
> 16 16 16 16 16 16 17 17 17 17 17 17 17 17 17 17 18 18 18 18 18 18 18 18 18
> 18 19 19 19 19 19 19 19 19 19 19 20 20 20 20 20 20 20 20 20 21*
>
>
> So to find the integer where the sum of ones equals 19:
>
> *F=.3 :'{.n#~y=+/\c1 n=.>:i.100'*
>
> * F 19*
>
> *81*
>
> This works great, except that I need to make sure that the running sum
> index n, is larger than the expected answer. In this case, the integers
> from one to 100 were sufficient, but that was discovered by trial and error.
>
>
> Ideally, the running sum could be defined as an iterative process that
> terminates in an integer, when the running sum iteration reaches or exceeds
> the required count. Then the output of F is that integer.
>
>
> So I was mainly wanting to see how to define a verb F that iterates on a
> running sum of one counts until the sum reaches the right argument of F,
> then returns the integer that terminates the ones count.
>
> So I just want to know how to modify:
>
> *F=.3 :'{.n#~y=+/\c1 n=.>:i.100'*
>
> to a running-sum iteration which terminates & returns the final integer
> that matches the ones count input, and does not have to predefine the index
> count.
>
> Skip Cave
> Cave Consulting LLC
>
>
> On Tue, Jan 18, 2022 at 3:58 AM Raul Miller  wrote:
>
>> I should have removed from 'seno' the line that says:
>>  assert. hi<1000
>>
>> The purpose of that line was to save me from having to use jbrk if I
>> hit an infinite loop from getting my conditions backwards. It's not a
>> useful mechanism, and should have been removed before I posted the
>> implementation.
>>
>> FYI,
>>
>> --
>> Raul
>>
>> On Tue, Jan 18, 2022 at 2:27 AM Hauke Rehr 
>> wrote:
>> >
>> > I didn’t do it much differently, conceptually.
>> > But instead of binary search (bisection)
>> > I split it up in ten buckets (dekasect).
>> > Apologies for the bad naming:
>> > another greek-latin hybrid, oh my …
>> >
>> > I split that way because I wanted to evaluate
>> > ones more often on small inputs than large.
>> > Didn’t measure if it atcually helps, though.
>> > And maybe I should have added an M. in order
>> > to memoize?
>> >
>> > But seno definitively reads better.
>> >
>> > Am 18.01.22 um 02:54 schrieb Raul Miller:
>> > > Your 'ones' is a bit more efficient than the routine I had come up
>> > > with, so I'll stick with your implementation here.
>> > >
>> > > Meanwhile, it's perhaps worth noting
>> > >
>> > > I.213=ones i.1000
>> > > 521 522 523 524 525 526 527 528 529 530
>> > >
>> > > So, building the inverse... it's typical for there to be ten numbers
>> > > who had n "one digits in the sequence". But, for example, there's no
>> > > number which has exactly 3 "one digits in the sequence". Ten has 2,
>> > > eleven has four. But we can find the minimum value which had at least
>> > > n preceding one digits.
>> > >
>> > > Personally, I'd use a binary search here:
>> > >
>> > > seno=:{{
>> > > if.y=ones y do.y return.end.hi=.2*lo=.y
>> > > while.y>ones hi do. hi=.2*lo=.hi end.
>> > > while.hi>lo do.
>> > >   assert. hi<1000
>> > >   select.*y-ones mid=.<.-:lo+hi+1
>> > > case._1 do.if.hi=mid do.lo=.hi break.end.hi=.mid
>> > > case.0 do.lo=.hi=.mid break.
>> > > case.1 do.lo=.mid
>> > >  end.
>> > >end.
>> > >while.y <: ones lo do.lo=.<:hi=.lo end. NB.  maybe too crude...
>> > >hi
>> > > }}
>> > >
>> > > seno 213
>> > > 521
>> > > ones 521
>> > > 213
>> > >
>> > > FYI,
>> > >
>> >
>> > --
>> > --
>> > mail written using NEO
>> > neo-layout.org
>> >
>> > --
>> > 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] Programming question

2022-01-22 Thread Skip Cave
Thanks for all the examples. I thought that the solution would be pretty
straightforward.

c1 gives the number of ones in an integer:
* c1=.{{+/1=10#.^:_1]y}}"0*


Test it:

* c1 211*

*2*


So the number of ones from 1 to 81 is:

* +/c1 i.>:81*

*19*

To develop the inverse verb F, we can get a running sum of ones:
 *  +/\c1 >:i.100*

* 1 1 1 1 1 1 1 1 1 2 4 5 6 7 8 9 10 11 12 12 13 13 13 13 13 13 13 13 13 13
14 14 14 14 14 14 14 14 14 14 15 15 15 15 15 15 15 15 15 15 16 16 16 16 16
16 16 16 16 16 17 17 17 17 17 17 17 17 17 17 18 18 18 18 18 18 18 18 18 18
19 19 19 19 19 19 19 19 19 19 20 20 20 20 20 20 20 20 20 21*


So to find the integer where the sum of ones equals 19:

*F=.3 :'{.n#~y=+/\c1 n=.>:i.100'*

* F 19*

*81*

This works great, except that I need to make sure that the running sum
index n, is larger than the expected answer. In this case, the integers
from one to 100 were sufficient, but that was discovered by trial and error.


Ideally, the running sum could be defined as an iterative process that
terminates in an integer, when the running sum iteration reaches or exceeds
the required count. Then the output of F is that integer.


So I was mainly wanting to see how to define a verb F that iterates on a
running sum of one counts until the sum reaches the right argument of F,
then returns the integer that terminates the ones count.

So I just want to know how to modify:

*F=.3 :'{.n#~y=+/\c1 n=.>:i.100'*

to a running-sum iteration which terminates & returns the final integer
that matches the ones count input, and does not have to predefine the index
count.

Skip Cave
Cave Consulting LLC


On Tue, Jan 18, 2022 at 3:58 AM Raul Miller  wrote:

> I should have removed from 'seno' the line that says:
>  assert. hi<1000
>
> The purpose of that line was to save me from having to use jbrk if I
> hit an infinite loop from getting my conditions backwards. It's not a
> useful mechanism, and should have been removed before I posted the
> implementation.
>
> FYI,
>
> --
> Raul
>
> On Tue, Jan 18, 2022 at 2:27 AM Hauke Rehr  wrote:
> >
> > I didn’t do it much differently, conceptually.
> > But instead of binary search (bisection)
> > I split it up in ten buckets (dekasect).
> > Apologies for the bad naming:
> > another greek-latin hybrid, oh my …
> >
> > I split that way because I wanted to evaluate
> > ones more often on small inputs than large.
> > Didn’t measure if it atcually helps, though.
> > And maybe I should have added an M. in order
> > to memoize?
> >
> > But seno definitively reads better.
> >
> > Am 18.01.22 um 02:54 schrieb Raul Miller:
> > > Your 'ones' is a bit more efficient than the routine I had come up
> > > with, so I'll stick with your implementation here.
> > >
> > > Meanwhile, it's perhaps worth noting
> > >
> > > I.213=ones i.1000
> > > 521 522 523 524 525 526 527 528 529 530
> > >
> > > So, building the inverse... it's typical for there to be ten numbers
> > > who had n "one digits in the sequence". But, for example, there's no
> > > number which has exactly 3 "one digits in the sequence". Ten has 2,
> > > eleven has four. But we can find the minimum value which had at least
> > > n preceding one digits.
> > >
> > > Personally, I'd use a binary search here:
> > >
> > > seno=:{{
> > > if.y=ones y do.y return.end.hi=.2*lo=.y
> > > while.y>ones hi do. hi=.2*lo=.hi end.
> > > while.hi>lo do.
> > >   assert. hi<1000
> > >   select.*y-ones mid=.<.-:lo+hi+1
> > > case._1 do.if.hi=mid do.lo=.hi break.end.hi=.mid
> > > case.0 do.lo=.hi=.mid break.
> > > case.1 do.lo=.mid
> > >  end.
> > >end.
> > >while.y <: ones lo do.lo=.<:hi=.lo end. NB.  maybe too crude...
> > >hi
> > > }}
> > >
> > > seno 213
> > > 521
> > > ones 521
> > > 213
> > >
> > > FYI,
> > >
> >
> > --
> > --
> > mail written using NEO
> > neo-layout.org
> >
> > --
> > 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


[Jprogramming] Programming question

2022-01-17 Thread Skip Cave
If I want to find the number of '1' digits in an integer, I can design a
verb c1, (count ones) to do that:

*c1=.{{+/1=10#.^:_1]y}}"0*


Test it:

* c1 10*

*1*

* c1 11*

*2*

* c1 103416*

*2*

* c1 56161764121*

*4*

I can also find the total number of '1' digits in a list of sequential
integers from 1 to n:


* to=:[+i.@:>:@-~ *

* +/c1 1 to n=.30*

*13*

* +/c1 1 to n=.521*

*213*


My question is: Given the total number of 1s in a sequence from 1 to n,
what is n?

A verb F(x) should return the final integer n, in the sequential list 1 to
n, that contains x ones.


Using the previous results as an example:


* F 213 *NB. A sequence 1 to n has 213 ones. What is n?

*521 *NB. The sequence 1 to 521 has 213 ones


What are some options to design the verb F?

1) Explicit

2) Implicit

3) Iteration

4) Recursion

Skip Cave
Cave Consulting LLC
--
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 Skip Cave
Here's my AoC Day 2 solution: https://adventofcode.com/2021/day/2
this problem seemed perfect for running sums (+/\)

n=.'b' freads 'depth2.txt' NB. Read in File
a=.'forward';'up';'down'
s=.;".ea{:ea n NB. Get numeric values (ea = each)
t=.+./@E.&.>  NB. string match mark each.
m=.s*"1[1 _1 1*>((0{a)t n),((1{a)t n),:((2{a)t n) NB. Set up for running
sums
   {:+/\+/1 2{m  NB. Get running depth sums
820
   {:+/\0{m NB. Get running distance sums.
2018

 820*2018
1654760     NB. Answer

Skip Cave
Cave Consulting LLC


On Wed, Dec 22, 2021 at 2:59 PM 'Michael Day' via Programming <
programm...@jsoftware.com> wrote:

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


Re: [Jprogramming] segregation boxing on bitvectors

2021-10-21 Thread Skip Cave
Impressive:

]cap =.(65+i.26){a.

ABCDEFGHIJKLMNOPQRSTUVWXYZ

]alphtest=.(?15#3){cap

CBACABCAACCBBBC

seqbx=.(<;.1~ 1, }.~:}:)

seqbx alphtest

┌─┬─┬─┬─┬─┬─┬─┬──┬──┬───┬─┐

│C│B│A│C│A│B│C│AA│CC│BBB│C│

└─┴─┴─┴─┴─┴─┴─┴──┴──┴───┴─┘


Thanks xash!


Skip Cave
Cave Consulting LLC


On Thu, Oct 21, 2021 at 12:20 PM xash  wrote:

> Oh, or even simpler I guess:
>
> (<;.1~ 1, }.~:}:) 0 1 0 1 1 1 0 0
>
> On Thu Oct 21, 2021 at 7:14 PM CEST, xash wrote:
> > ( >
> > On Thu Oct 21, 2021 at 7:01 PM CEST, Raoul Schorer wrote:
> > > Hi,
> > >
> > > Really trivial question I am stuck on:
> > >
> > > given a bit vector
> > > 0 1 0 1 1 1 0 0
> > >
> > > how to easily sequentially box 1s & 0s? Such as:
> > > |0|1|0|1 1 1|0 0|
> > >
> > > Thanks!
> > > Raoul
> > > --
> > > 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] segregation boxing on bitvectors

2021-10-21 Thread Skip Cave
Or more generally, how do you box sequential items that are identical?

|4|5 5|3 3 3|6|8|6 6|9|2 2 2|

Skip Cave
Cave Consulting LLC


On Thu, Oct 21, 2021 at 12:01 PM Raoul Schorer 
wrote:

> Hi,
>
> Really trivial question I am stuck on:
>
> given a bit vector
> 0 1 0 1 1 1 0 0
>
> how to easily sequentially box 1s & 0s? Such as:
> |0|1|0|1 1 1|0 0|
>
> Thanks!
> Raoul
> --
> 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] Math Problem

2021-10-19 Thread Skip Cave
Thanks Elijah! That's what I was missing.
We could also use J's polynomial solver:

* ] 'x f' =. ; }. p. 4002 _4096 64*

*63.00755956214548803 0.99244043785451341311*


Looks good:

* 4002=64*x*f*

*1*


But only if we rely on J's comparison tolerance.

If we move to rational fractions:


* ] 'x f'=.x: ;}.p. 4002 _4096 64*

*22506410355791r357201747095 8292308694079r8355472406995*

* 4002=64*x*f*

*0*


No luck. There's probably not a true rational solution.


Skip Cave
Cave Consulting LLC


On Tue, Oct 19, 2021 at 3:12 AM Elijah Stone  wrote:

> Ah--that is much clearer!
>
> I am not sure of a good iterative solution, but there is a fairly simple
> analytic solution.
>
> Say we would like to find a solution with a floor of 64; that is, where 64
> = <.x.
>
> Then we have:
>
> 4002 = x * 64 * (x - 64)
> = (64*x*x) + (_4096*x)
>
> which means that:
>
> 0 = (64*x*x) + (_4096*x) + 4002
>
> Which is a quadratic equation.  We may attack it as normal, deriving a
> solution as:
>
> ] x=.(2*64) %~ 4096 + %: (_4096^2) - 4*64*_4002
> 64.9626
> x * (<.x) * (x - <.x)
> 4002
>
> However, I think you asked for a rational answer; this solution is not
> rational because the determinant is not an integer square.
>
> The solution with a floor of k has a determinant of (k^4) + 4*k.  Are
> there any values for k in range such that that value is a perfect square?
>
> 1 e. (= <.) %: (^&4 + 4&*) >:i.150
> 0
>
> It appears not :/
>
>   -E
>
> On Tue, 19 Oct 2021, Skip Cave wrote:
>
> > I made a mistake in the equation in my first post..
> >
> > The three terms that are multiplied are
> > 1. x
> > 2. floor of x  = (<.x)
> > 3. fractional part of x = (x - <.x) This is what I got wrong in my first
> > post.
> >
> > I can get close by manual trial & error:
> >
> > *x=.64.962573478*
> >
> > Floor of x = <.x = 64
> >
> > Fractional part of x = (x -<.x ) = 0.962573478
> >
> > * x: x * (<.x) * (x - <.x)*
> >
> > *213746821r53410*
> >
> >
> > Close, but no cigar.
> >
> >
> > * 4002 = x * (<.x) * (x - <.x)*
> >
> > *0*
> >
> > A closer look - as a decimal fraction:
> >
> > * x * (<.x) * (x-<.x)*
> >
> > *4002.187231198652*
> >
> >
> > Yep. Not close enough.
> >
> >
> > How to design an iterative solution? There should be multiple solutions
> > with (<.x) = 63, 64, 65. 66 ... with the fraction
> >
> > *(x-<.x) *getting smaller & smaller.
> >
> > Skip Cave
> > Cave Consulting LLC
> >
> >
> > On Mon, Oct 18, 2021 at 6:25 PM Skip Cave 
> wrote:
> >
> >> How to solve this problem?
> >>
> >> 4002x = n * (<.n) * (>.n)
> >>
> >>
> >> What is n, where n is a rational fraction greater than 1, and the answer
> >> is a rational fraction? There are likely many answers, so find some
> answers
> >> near 64. The result in J should be a 1:
> >>
> >> 4002x = n * (<.n) * (>.n)
> >> 1
> >>
> >>
> >> 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


[Jprogramming] histogram verb

2021-10-19 Thread Skip Cave
How can I modify the standard implicit histogram verb to produce sequential
categories?

hist =:~.,:#/.~

]n=.?100#20

9 12 3 14 3 13 18 8 12 17 17 14 19 9 18 18 16 12 2 4 4 5 13 16 14 11 9 17 8
4 14 19 2 9 3 9 7 6 15 14 1 13 14 13 13 19 13 1 4 16 11 12 19 4 2 1 3 18 10
15 6 5 10 14 9 3 8 19 14 5 13 8 1 19 2 10 13 3 2 17 18 12 11 9 16 19 11 18
14 5 19 3 10 1 5 5 15 7 16 7


{"0 hist n

┌─┬─┬──┬──┬──┬─┬─┬──┬──┬─┬─┬──┬─┬─┬──┬─┬─┬──┬──┬──┐

│3│7│16│10│19│5│9│18│17│4│0│13│6│2│11│8│1│14│15│12│

├─┼─┼──┼──┼──┼─┼─┼──┼──┼─┼─┼──┼─┼─┼──┼─┼─┼──┼──┼──┤

│3│7│9 │8 │4 │5│6│11│4 │4│2│5 │3│2│3 │4│7│9 │2 │2 │

└─┴─┴──┴──┴──┴─┴─┴──┴──┴─┴─┴──┴─┴─┴──┴─┴─┴──┴──┴──┘


What I want:

{"0 m{~"1 /:{. m=.hist n

┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐

│0│1│2│3│4│5│6│7│8│9│10│11│12│13│14│15│16│17│18│19│

├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤

│2│7│2│3│4│5│3│7│4│6│8 │3 │2 │5 │9 │2 │9 │4 │11│4 │

└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘


How can I do all that within the implicit code of hist?


Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Grammar question: 2: * i.

2021-10-19 Thread Skip Cave
I also often use these two even & odd verbs to extract even or odd integers
from a list:

ev=.]#~0=2|]


od=.]#~2|]

]n=.?15#20

12 6 18 1 7 6 1 12 5 18 5 8 13 16 15


ev n

12 6 18 6 12 18 8 16


od n

1 7 1 5 5 13 15

Skip Cave
Cave Consulting LLC


On Tue, Oct 19, 2021 at 2:33 AM Jon Quant  wrote:

> Thanks Elijah,
>
> That's amazing, such a clear explanation!
> Links and N V V update much appreciated.
>
> Thanks again
> Jon
>
> On Tue, 19 Oct 2021 at 08:14, Elijah Stone  wrote:
>
> > A single digit followed by a colon is a _constant verb_, which always
> > produces the same result no matter its operand.  For example:
> >
> > f=. 2:
> > f 5
> > 2
> > f 7 7
> > 2
> > 3 f 'a'
> > 2
> >
> > So, '2: * i.' is a V V V fork, whereas '2 * i.' is an N V V fork.  I
> guess
> > that the latter were not yet implemented when that entry of the
> phrasebook
> > was written.
> >
> > FWIW the functions are documented in NuVoc; the entry link is titled '_9:
> > to 9:; Constant Functions', and can be read at
> > https://code.jsoftware.com/wiki/Vocabulary/zeroco
> >
> > There is also a dictionary entry:
> > https://www.jsoftware.com/help/dictionary/dconsf.htm
> >
> >   -E
> >
> >
> > On Tue, 19 Oct 2021, Jon Quant wrote:
> >
> > > Hi all,
> > >
> > > The J phrases book has simple uses of colon which I can't find in the
> > NuVoc
> > > grammar.
> > > Could someone help explain the grammar of the following?
> > >
> > > Verb trains:
> > >
> > > even=: 2: * i.
> > > odd=: 1: + 2: * i.
> > >
> > > These seem to work without the colons anyway. What is the grammar rule
> > and
> > > purpose for an integer followed by a colon?
> > >
> > > Great fun so far with J!
> > >
> > > Thanks
> > >
> > > Jon
> > > --
> > > 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] Math Problem

2021-10-19 Thread Skip Cave
I made a mistake in the equation in my first post..

The three terms that are multiplied are
1. x
2. floor of x  = (<.x)
3. fractional part of x = (x - <.x) This is what I got wrong in my first
post.

I can get close by manual trial & error:

*x=.64.962573478*

Floor of x = <.x = 64

Fractional part of x = (x -<.x ) = 0.962573478

* x: x * (<.x) * (x - <.x)*

*213746821r53410*


Close, but no cigar.


* 4002 = x * (<.x) * (x - <.x)*

*0*

A closer look - as a decimal fraction:

* x * (<.x) * (x-<.x)*

*4002.187231198652*


Yep. Not close enough.


How to design an iterative solution? There should be multiple solutions
with (<.x) = 63, 64, 65. 66 ... with the fraction

*(x-<.x) *getting smaller & smaller.

Skip Cave
Cave Consulting LLC


On Mon, Oct 18, 2021 at 6:25 PM Skip Cave  wrote:

> How to solve this problem?
>
> 4002x = n * (<.n) * (>.n)
>
>
> What is n, where n is a rational fraction greater than 1, and the answer
> is a rational fraction? There are likely many answers, so find some answers
> near 64. The result in J should be a 1:
>
> 4002x = n * (<.n) * (>.n)
> 1
>
>
> Skip
>
> Skip Cave
> Cave Consulting LLC
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Math Problem

2021-10-18 Thread Skip Cave
How to solve this problem?

4002x = n * (<.n) * (>.n)


What is n, where n is a rational fraction greater than 1, and the answer is
a rational fraction? There are likely many answers, so find some answers
near 64. The result in J should be a 1:

4002x = n * (<.n) * (>.n)
1


Skip

Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] NYCJUG: Counting pairs in a 3 card poker hand

2021-10-15 Thread Skip Cave
Brute Force probability of a pair in 5 cards:

(+/%#)4=;#&.>~.&.>{(5 comb 52){4#1 to 13

0.422569


Skip Cave
Cave Consulting LLC


On Fri, Oct 15, 2021 at 9:43 AM Devon McCormick  wrote:

> I have not had a chance to look over Thomas's calculations in detail.  To
> check them, I would extend the logic to some other similar problems to see
> how they do.  Come to think of it, I believe I have calculated the chance
> of a pair in five cards and that's something you could look up as well.
>
> The brute force calculations are a good sanity check but fall down for
> larger problems.  As I said in the meeting, I tend to trust my simulations
> more than my calculations.
>
> On Fri, Oct 15, 2021 at 4:52 AM Skip Cave  wrote:
>
> > Brute Force probability of a pair in a flop:
> >
> > (+/%#)2=;#&.>~.&.>{(3 comb 52){4#1 to 13
> >
> > 0.169412
> >
> > Skip Cave
> > Cave Consulting LLC
> >
> >
> > On Thu, Oct 14, 2021 at 12:10 AM Thomas McGuire 
> > wrote:
> >
> > > Devon presented more of his Poker simulations now using Jd (the J
> > > database) at the most recent NYCJUG meeting (
> > > https://code.jsoftware.com/wiki/NYCJUG/2021-10-12 <
> > > https://code.jsoftware.com/wiki/NYCJUG/2021-10-12>)
> > >
> > > He came up with an interesting problem of calculating the expected
> number
> > > of pairs in the initial flop in a game of Omaha.
> > >
> > > 3 cards dealt into the flop. Consider those with only pairs in them,
> > there
> > > would be 3 ways that the pairs could be dealt out.
> > >
> > > X X Y, X Y X, Y X X
> > >
> > > Taking the first configuration the number of different hands you could
> > > make would be:
> > >
> > >*/52 3 48  NB. this matches part of Devon’s calculation
> > > 7488
> > >
> > > NB. anyone of 52 cards can be dealt, once the card is dealt then only 1
> > of
> > > 3 can be dealt to make the pair
> > > NB. then we have to exclude the remaining 2 cards that match and
> > therefore
> > > the third card will be anyone of 48
> > >
> > > NB. since there are 3 configurations the cards can be dealt in, the
> other
> > > 2 would be calculated:
> > >   */52 48 3
> > > 7488
> > >   */48 52 3
> > > 7488
> > >
> > > NB. this makes
> > >3*7488.NB. Different 3 card hands with only pairs in them
> > > 22464
> > >
> > > To calculate the percentage of the total number of hands Devon made the
> > > calculation using only one of the pairs hand configurations. Then used
> > 3!52
> > > for combinations of 52 things taken 3 at a time.
> > >
> > > This was off by a factor of 2 from his simulation, where he enumerated
> > all
> > > the possibilities.
> > >
> > > I finally realized (it took me 2 days of intermittent thought) that the
> > > order in which the cards are dealt matter. Not so much in the scoring
> of
> > a
> > > hand but it does matter for the number of ways the same hand can be
> dealt
> > > out.
> > >
> > > NB. So the total number of 3 card hands from 52 cards is:
> > > */52 51 50
> > > 132600
> > >
> > > NB. which is permutations of 52 things taken 3 at a time
> > > NB. which like the Combinations function in J has a representation
> called
> > > the Stope function:
> > > 52 ^!._1 (3)
> > > 132600
> > >
> > > NB. Devon’s original calculation was:
> > >(*/52 3 48)%3!52
> > > 0.338824
> > >
> > > NB. However based on the analysis above it should be:
> > >(3 * */52 3 48)%52 ^!._1 (3)
> > > 0.169412
> > >
> > > NB. Which is very close to his simulated percentage: 0.169418
> > >
> > > Devon was more concerned with scoring a hand rather than the order they
> > > were dealt in, when dealing with his calculation.
> > > So the best I could come up with to follow what I think was Devon’s
> > > thought process was the following:
> > >
> > > NB. there are 13 different card values
> > > NB. there are 2!4 combinations of pairs due to the different suits
> > > NB. there will be 48 cards left over to make the flop since we exclude
> 3
> > > of a kind (that’s a different type of poker hand than a pair)
> > > NB. So:
> > >(*/13,(2!4),48)%3!52
> > > 0.169412
> > >
> > > So the question is did I calculate these both correctly or did I just
> > come
> > > up with 2 methods that match the simulation and just think my logic is
> > > correct?
> > >
> > >
> > >
> > > --
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> > >
> > --
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
>
>
> --
>
> Devon McCormick, CFA
>
> Quantitative Consultant
> --
> 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] NYCJUG: Counting pairs in a 3 card poker hand

2021-10-15 Thread Skip Cave
Brute Force probability of a pair in a flop:

(+/%#)2=;#&.>~.&.>{(3 comb 52){4#1 to 13

0.169412

Skip Cave
Cave Consulting LLC


On Thu, Oct 14, 2021 at 12:10 AM Thomas McGuire 
wrote:

> Devon presented more of his Poker simulations now using Jd (the J
> database) at the most recent NYCJUG meeting (
> https://code.jsoftware.com/wiki/NYCJUG/2021-10-12 <
> https://code.jsoftware.com/wiki/NYCJUG/2021-10-12>)
>
> He came up with an interesting problem of calculating the expected number
> of pairs in the initial flop in a game of Omaha.
>
> 3 cards dealt into the flop. Consider those with only pairs in them, there
> would be 3 ways that the pairs could be dealt out.
>
> X X Y, X Y X, Y X X
>
> Taking the first configuration the number of different hands you could
> make would be:
>
>*/52 3 48  NB. this matches part of Devon’s calculation
> 7488
>
> NB. anyone of 52 cards can be dealt, once the card is dealt then only 1 of
> 3 can be dealt to make the pair
> NB. then we have to exclude the remaining 2 cards that match and therefore
> the third card will be anyone of 48
>
> NB. since there are 3 configurations the cards can be dealt in, the other
> 2 would be calculated:
>   */52 48 3
> 7488
>   */48 52 3
> 7488
>
> NB. this makes
>3*7488.NB. Different 3 card hands with only pairs in them
> 22464
>
> To calculate the percentage of the total number of hands Devon made the
> calculation using only one of the pairs hand configurations. Then used 3!52
> for combinations of 52 things taken 3 at a time.
>
> This was off by a factor of 2 from his simulation, where he enumerated all
> the possibilities.
>
> I finally realized (it took me 2 days of intermittent thought) that the
> order in which the cards are dealt matter. Not so much in the scoring of a
> hand but it does matter for the number of ways the same hand can be dealt
> out.
>
> NB. So the total number of 3 card hands from 52 cards is:
> */52 51 50
> 132600
>
> NB. which is permutations of 52 things taken 3 at a time
> NB. which like the Combinations function in J has a representation called
> the Stope function:
> 52 ^!._1 (3)
> 132600
>
> NB. Devon’s original calculation was:
>(*/52 3 48)%3!52
> 0.338824
>
> NB. However based on the analysis above it should be:
>(3 * */52 3 48)%52 ^!._1 (3)
> 0.169412
>
> NB. Which is very close to his simulated percentage: 0.169418
>
> Devon was more concerned with scoring a hand rather than the order they
> were dealt in, when dealing with his calculation.
> So the best I could come up with to follow what I think was Devon’s
> thought process was the following:
>
> NB. there are 13 different card values
> NB. there are 2!4 combinations of pairs due to the different suits
> NB. there will be 48 cards left over to make the flop since we exclude 3
> of a kind (that’s a different type of poker hand than a pair)
> NB. So:
>(*/13,(2!4),48)%3!52
> 0.169412
>
> So the question is did I calculate these both correctly or did I just come
> up with 2 methods that match the simulation and just think my logic is
> correct?
>
>
>
> --
> 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] Fibonacci Verbs

2021-09-25 Thread Skip Cave
 JVERSION

Engine: j903/j64avx2/windows

Beta-q: commercial/2021-09-14T15:38:42

Library: 9.03.01

Qt IDE: 1.9.2/5.12.10(5.12.10)

Platform: Win 64

Installer: J903 install

InstallPath: c:/users/skip/j903

Contact: www.jsoftware.com


I tried Elijah's extended precision fix. It didn't help on my machine:


pp=.9!:11

pp 20


f0b=: (-&2 +&$: -&1) ^: (1&<) M.

f0b 98

1.353018523447067607e20

x: f0b 98

135301852344706760704

x: f0b 98x

135301852344706760704

f2a=: 3 : '{. +/\@|.^:y 0 1x'

f2a 98

135301852344706746049

f2a 98x

135301852344706746049

x: f2a 98x

135301852344706746049


Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Fibonacci Verbs

2021-09-25 Thread Skip Cave
From: https://code.jsoftware.com/wiki/Essays/Fibonacci_Sequence

f0b=: (-&2 +&$: -&1) ^: (1&<) M.

f2a=: 3 : '{. +/\@|.^:y 0 1x'

x:f0b 98

135301852344706760704

x:f2a 98

135301852344706746049


(x:f0b 98) -: x:f2a 98

0


Why the discrepancy?


Skip


Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] J903-beta-n

2021-08-23 Thread Skip Cave
Got libomp.dll, put it in the bin dir. jqt came right up!

JVERSION

Engine: j903/j64avx2/windows

Beta-n: commercial/2021-08-23T18:16:42

Library: 9.03.01

Qt IDE: 1.9.2/5.12.10(5.12.10)

Platform: Win 64

Installer: J903 install

InstallPath: c:/users/skip/j903

Contact: www.jsoftware.com

Skip Cave
Cave Consulting LLC


On Mon, Aug 23, 2021 at 8:24 PM bill lam  wrote:

> http://www.jsoftware.com/download/jengine/j903-beta/windows/j64/
>
> On Tue, Aug 24, 2021, 9:10 AM Skip Cave  wrote:
>
> > Where can I get a copy of libomp.dll?
> >
> > Skip
> >
> > Skip Cave
> > Cave Consulting LLC
> >
> >
> > On Mon, Aug 23, 2021 at 3:11 PM Eric Iverson 
> > wrote:
> >
> > > J903-beta-n is available for windows/linux/macos.
> > >
> > > If you already run J903-beta, then upgrade is easy:
> > >load'pacman'
> > >'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
> > >
> > --
> > 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] J903-beta-n

2021-08-23 Thread Skip Cave
Where can I get a copy of libomp.dll?

Skip

Skip Cave
Cave Consulting LLC


On Mon, Aug 23, 2021 at 3:11 PM Eric Iverson 
wrote:

> J903-beta-n is available for windows/linux/macos.
>
> If you already run J903-beta, then upgrade is easy:
>load'pacman'
>'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
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Cut

2021-07-04 Thread Skip Cave
Thanks for all the suggestions. That gave me the general idea.

My take using boxing (slower)

*sep=.10 #.^:_1 ]*

*#a=.n#~+./"1[1=>#&.>~.&.>{3,\"1 sep n=.1e5 to 99*

*33219*


So there are 33,219 six-digit integers that have 3 or more identical
consecutive digits.


* 30 timex '#a=.n#~+./"1[1=>#&.>~.&.>{3,\"1 sep n=.1e5 to 99'*

*2.76304*


Not very fast.

Skip Cave
Cave Consulting LLC


On Sat, Jul 3, 2021 at 6:13 PM Skip Cave  wrote:

> Can I use cut to find all the 6-digit integers that have three consecutive
> identical digits? Or is there a more efficient way?
>
> sep=:10#.^:_1] NB. Separate digits.
>
> to=:[+i.@:>:@-~ NB. Generate integer ranges.
>
>
> $ sn=.sep n=.1e5 to 99 NB. Generate all the 6 digit integers and
> separate their digits.
>
> 90 6
>
> Now what? Can I apply cut to sn to find all 6-digit integers with three
> consecutive identical digits? Or is there a better way?
>
>
> 123334 is correct
>
> 122344 is not correct
>
> 121212 is not correct
>
> 111222 is correct
>
> 112122 is not correct
>
> 555432 is correct
>
>
> NB. Test vector: tv=. 123334 122344 121212 111222 112122 555432
>
> Skip
>
>
> Skip Cave
> Cave Consulting LLC
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Cut

2021-07-03 Thread Skip Cave
Can I use cut to find all the 6-digit integers that have three consecutive
identical digits? Or is there a more efficient way?

sep=:10#.^:_1] NB. Separate digits.

to=:[+i.@:>:@-~ NB. Generate integer ranges.


$ sn=.sep n=.1e5 to 99 NB. Generate all the 6 digit integers and
separate their digits.

90 6

Now what? Can I apply cut to sn to find all 6-digit integers with three
consecutive identical digits? Or is there a better way?


123334 is correct

122344 is not correct

121212 is not correct

111222 is correct

112122 is not correct

555432 is correct


NB. Test vector: tv=. 123334 122344 121212 111222 112122 555432

Skip


Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Groups

2021-03-29 Thread Skip Cave
Wow! Thanks Cliff. I don't understand it all yet, but it does exactly what
I need.
The capability to remove specific elements in a vector is something I have
needed
fairly often:

0-.~2 0 3 1 5 0 0 1

2 3 1 5 1


2 3-.~1 2 3 4 3 5 3 2 6 7 3 3 6

1 4 5 6 7 6


Where is this handy dyadic verb documented in the J doc?


Skip

Skip Cave
Cave Consulting LLC


On Mon, Mar 29, 2021 at 3:41 PM Clifford Reiter 
wrote:

>0-.~#;._2 t,0
> 2 3 1 5 1
>
>
>
>
> On Mon, Mar 29, 2021 at 4:34 PM Skip Cave  wrote:
>
> > Given a vector t of ones and zeros"
> >
> > t=. 1 1 0 0 1 1 1 0 1 0 1 1 1 1 1 0 0 0 1 0
> >
> >
> > How can I code a verb gp that will enumerate the sizes of each
> > zero-delimited group of ones in the vector t?
> >
> > For example:
> >
> >
> > gp t
> >
> > 2 3 1 5 1
> >
> >
> > 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


[Jprogramming] Groups

2021-03-29 Thread Skip Cave
Given a vector t of ones and zeros"

t=. 1 1 0 0 1 1 1 0 1 0 1 1 1 1 1 0 0 0 1 0


How can I code a verb gp that will enumerate the sizes of each
zero-delimited group of ones in the vector t?

For example:


gp t

2 3 1 5 1


Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Quora Problem

2021-03-20 Thread Skip Cave
How do you solve this problem using J (brute force)
n =. >: i. 1000
p =. n^n
How many p are perfect cubes?

Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] how to create + publish a package?

2021-03-07 Thread Skip Cave
 Make a zip file, put it in Google drive (free Gmail account), share the
file with anyone, copy and paste the link in the wiki.

Skip

On Sun, Mar 7, 2021 at 9:45 AM Michal Wallace 
wrote:

> I'd like to make a package for gridpad, the viewmat-with-drawing thing I
> use in my videos, so that other people can easily download and import it.
>
> How do I make that happen?
> --
> 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] JE contributions WAS: J903-beta-c

2021-02-03 Thread Skip Cave
All,
Then there is also John Gustafson's
<http://www.johngustafson.net/bio/current-resume.pdf> Unums & Posits, which
are specifically designed to extend the floating-point range on binary
computers:
The End of (Numeric) Error - John L. Gustafson
<https://ubiquity.acm.org/article.cfm?id=2913029>
The Unum Number Format (Wikipedia)
<https://en.wikipedia.org/wiki/Unum_(number_format)>
Beyond Floating Point: Next-Generation Computer Arithmetic
<https://web.stanford.edu/class/ee380/Abstracts/170201.html>
Beyond Floating Point - Slides
<https://web.stanford.edu/class/ee380/Abstracts/170201-slides.pdf>

Skip Cave
Cave Consulting LLC


On Wed, Feb 3, 2021 at 2:22 PM Henry Rich  wrote:

> The multiplication algorithm is brute-force. FFT methods are orders of
> magnitude faster for large numbers.
>
> Numbers are actually stored in base 1 IIRC.
>
> Extended arithmetic is not a mainstream use, but if we support it we
> might as well do it as well as we can.
>
> Henry Rich
>
> On 2/3/2021 3:05 PM, 'Pascal Jasmin' via Programming wrote:
> > The core performance bottleneck with extended precision numbers in J is
> that they are stored in base 10.  That decision does come with a
> performance advantage of its own:  input and display.  I'd favour the move
> to 32/64 bit storage even if it "broke" the 3!:1 format (although 3!:1
> could convert to old storage style).  J is already shipping with openssl
> that has large integer operations.  Is there that big a case to add GMP as
> a dependency?
> >
> >
> >
> >
> >
> >
> > On Wednesday, February 3, 2021, 09:47:51 a.m. EST, Henry Rich <
> henryhr...@gmail.com> wrote:
> >
> >
> >
> >
> >
> > IF you want to get yourself in shape to make JE changes, I have a
> > starter project for you: replace the extended-integer and rational
> > support with GMP (or some other equally-good library).  The current code
> > is serviceable but sized for 32-bit machines, and lacks fast
> multiplication.
> >
> > The code resides in vx.c and vq.c, which would be replaced with new
> > versions.  There are also bits in k.c (conversions) and d.c (display).
> >
> > I will help as needed.
> >
> > Henry Rich
> >
> > On 2/1/2021 11:25 PM, ethiejiesa via Programming wrote:
> >> Raul Miller  wrote:
> >>> https://github.com/jsoftware/jsource/commits/master might interest
> you...
> >> Indeed, I have the repo cloned locally!
> >>
> >> However, when digging through old bug reports, I find it quite
> challenging to
> >> match up the "fixed" notices with the corresponding code commits. In
> cases with
> >> a clear test case demonstrating the bug, we can use git-bisect to
> sleuth out
> >> the commit that eliminates the failure. However, cases without this
> almost
> >> invariably defeat my investigative skills.
> >>
> >> For posterity's sake, and if it's not too much of a hassle, I thought
> it might
> >> be helpful to have some commits/diffs/comments attached to those "fixed"
> >> messages.
> >>
> >> I will admit to a bit of an ulterior motive here, though.
> >>
> >> Bill, Eric, and Henry have deep domain knowledge about JE. I am
> personally
> >> hoping that sharing the diffs would also spark discussion and give a
> natural
> >> avenue to share and spread such expertise.
> >>
> >> The gory details are exceptionally interesting!
> >>
> >>
> >> Permit me to query a broader point, though.
> >>
> >> It strikes me that the git-shortlog on the repo is very short:
> >>
> >>$ git shortlog --summary
> >>6Chris Burke
> >>231Eric Iverson
> >>1430HenryHRich
> >>1bill
> >>597bill lam
> >>3cdb
> >>3kbi
> >>
> >> For the most part, we only have 3 devs, with all of them part of the
> old guard,
> >> per se. Better yet, Henry has authored over 62% of all commits!
> Granted, this
> >> only reflects the history from 2016 onward, but my question is this: Do
> we have
> >> up and coming JE hackers that can pick up the torch when the time comes?
> >>
> >>
> >> Anyway, maybe JSoftware has a vision for the future that I've failed to
> pick up
> >> on. The ulterior motive behind my "share a bit about the fix" is to
> perhaps
> >> open a channel with the community that sucks in potential JE devs like
> myself!
> >> I was just trying to be sneaky about things by suggesting something
> very simple
> >> and, hopefully, hassle-free.
> >>
> >>
> >> 2!:55
> >> --
> >> 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


[Jprogramming] Insert verb

2021-01-19 Thread Skip Cave
How does one design a verb that inserts specific elements into a vector or
matrix?

For example, an "insertafter" verb would take one left argument, which is
the index of the array that the element is to be inserted after. The right
argument would be two boxed nouns. The first boxed noun is the set to be
inserted. The second boxed noun is the destination of the insertion.

  2 insertafter 10;1 2 3 4 5

1 2 3 10 4 5
2 insertafter 10 11;1 2 3 4 5
1 2 3 10 11 4 5

Also may need insertbefore:
2 insertbefore 10;1 2 3 4 5

1 2 10 3 4 5
2 insertbefore 10 11;1 2 3 4 5
1 2 10 11 3 4 5

 Higher ranks?

]n=.2 5$i.10

0 1 2 3 4

5 6 7 8 9

2 insertafter "1 [ 10;n

0 1 2 10 3 4

5 6 7 10 8 9


What would the code for insertbefore verb look like?


Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Q: How do you eat an elephant? A: bit by bit.

2021-01-02 Thread Skip Cave
Here's a couple of cloud-to cloud transfer services:

https://www.youtube.com/watch?v=6hCBHQVX6OA

https://www.multcloud.com/product


Skip Cave
Cave Consulting LLC


On Sat, Jan 2, 2021 at 4:52 PM Ian Clark  wrote:

> My son has 70 GB of misc data on Google Drive, which he needs to move
> across onto iCloud Drive as a once-off job. With the equipment he's having
> to use, just clicking Download in the Google Drive website takes too long
> and doesn't complete. I had to admit this problem was outside my
> experience, but faced with the task myself I'd set about doing it the dumb
> way: a subfolder at a time.
>
> I know there are folk on this forum who routinely work with large amounts
> of data. Can someone suggest a utility (maybe written in J, bypassing
> commercial browsers) which would do the job a teeny bit smarter than that?
>
> Ian Clark
> --
> 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] All combinations from multiple different-length lists

2020-12-25 Thread Skip Cave
 Devon, Henry,


Devon is right. Henry's proposal has all the answers I wanted. It's just in
a less-convenient form.
If I reshape Henry's proposal ,/>{x  into a y x 8 matrix, it should be the
same as {>,{x
 I just need to find y:

* ]x=.31 16 45;3 19 16 4;30 14 46 14 20;34; 41 39 23;30 9 36 9 32; 46 20 30
44;44 35 49 23*

*┌┬─┬──┬──┬┬┬───┬───┐*

*│31 16 45│3 19 16 4│30 14 46 14 20│34│41 39 23│30 9 36 9 32│46 20 30 44│44
35 49 23│*

*└┴─┴──┴──┴┴┴───┴───┘*

* #x*

*8*


There are 8 lists of various lengths in x. The result I want should be a y
x 8 matrix where y is all possible

combinations of the list items from each x. As Devon pointed out, we can
find the dimension of the combination

matrix thusly:


*]y=.*/_1}.$,/>{x*
*14400*
Now we can reshape Henry's result (,/>{x) to a y x 8 matrix. To do that we
will need y, and Henry's
proposal will need an extra ravel as well:

Test for identity:

*(>,{x)-:(y,8)$,,/>{x*

*1*

Thanks for the input and help.

Skip Cave
Cave Consulting LLC


On Fri, Dec 25, 2020 at 12:27 PM Devon McCormick  wrote:

> > Henry's proposal doesn't work for larger list
> >   $,/>{x
> > 12 5 3 5 4 4 8
> which looks like it does work since 14400 = */12 5 3 5 4 4 .  It's the same
> number of items.
>
> On Sun, Dec 20, 2020 at 5:42 PM Skip Cave  wrote:
>
> > Trying larger lists:
> >
> > ]x=.31 16 45;3 19 16 4;30 14 46 14 20;34; 41 39 23;30 9 36 9 32; 46 20 30
> > 44;44 35 49 23
> >
> >
> > │31 16 45│3 19 16 4│30 14 46 14 20│34│41 39 23│30 9 36 9 32│46 20 30
> 44│44
> > 35 49 23│
> >
> >
> > Henry's proposal doesn't work for larger list
> >
> > $,/>{x
> >
> > 12 5 3 5 4 4 8
> >
> >
> > But Chris' does:
> >
> > $>,{x
> >
> > 14400 8
> >
> >
> > Skip Cave
> >
> >
> >
> > On Sun, Dec 20, 2020 at 12:48 PM Skip Cave 
> > wrote:
> >
> > > I have three lists stored in x:
> > >
> > > ]x=.1 3 5;2;3 4
> > >
> > > ┌─┬─┬───┐
> > >
> > > │1 3 5│2│3 4│
> > >
> > > └─┴─┴───┘
> > >
> > > I want to find all possible combinations of the elements of these lists
> > > (taking one from each list).
> > >
> > > Using the odometer function I can generate all the possible index
> > > combinations of selections from those three lists:
> > >
> > >
> > > odo ;# each x
> > >
> > > 0 0 0
> > >
> > > 0 0 1
> > >
> > > 1 0 0
> > >
> > > 1 0 1
> > >
> > > 2 0 0
> > >
> > > 2 0 1
> > >
> > >
> > > Now I can individually find each selection from the three lists
> > >
> > >
> > > ;0 0 0{ea { >x
> > >
> > > 1 2 3
> > >
> > > ;0 0 1{ea { >x
> > >
> > > 1 2 4
> > >
> > > ;1 0 0{ea { >x
> > >
> > > 3 2 3
> > >
> > > ;1 0 1{ea { >x
> > >
> > > 3 2 4
> > >
> > > ;2 0 0{ea { >x
> > >
> > > 5 2 3
> > >
> > > ;2 0 1{ea { >x
> > >
> > > 5 2 4
> > >
> > >
> > > How can I generate all of the selections in one 6x3 matrix using just
> one
> > > statement, with no explicit looping?
> > >
> > >
> > > Skip
> > >
> > > Skip Cave
> > >
> > >
> > --
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
>
>
> --
>
> Devon McCormick, CFA
>
> Quantitative Consultant
> --
> 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] All combinations from multiple different-length lists

2020-12-20 Thread Skip Cave
Trying larger lists:

]x=.31 16 45;3 19 16 4;30 14 46 14 20;34; 41 39 23;30 9 36 9 32; 46 20 30
44;44 35 49 23


│31 16 45│3 19 16 4│30 14 46 14 20│34│41 39 23│30 9 36 9 32│46 20 30 44│44
35 49 23│


Henry's proposal doesn't work for larger list

$,/>{x

12 5 3 5 4 4 8


But Chris' does:

$>,{x

14400 8


Skip Cave



On Sun, Dec 20, 2020 at 12:48 PM Skip Cave  wrote:

> I have three lists stored in x:
>
> ]x=.1 3 5;2;3 4
>
> ┌─┬─┬───┐
>
> │1 3 5│2│3 4│
>
> └─┴─┴───┘
>
> I want to find all possible combinations of the elements of these lists
> (taking one from each list).
>
> Using the odometer function I can generate all the possible index
> combinations of selections from those three lists:
>
>
> odo ;# each x
>
> 0 0 0
>
> 0 0 1
>
> 1 0 0
>
> 1 0 1
>
> 2 0 0
>
> 2 0 1
>
>
> Now I can individually find each selection from the three lists
>
>
> ;0 0 0{ea { >x
>
> 1 2 3
>
> ;0 0 1{ea { >x
>
> 1 2 4
>
> ;1 0 0{ea { >x
>
> 3 2 3
>
> ;1 0 1{ea { >x
>
> 3 2 4
>
> ;2 0 0{ea { >x
>
> 5 2 3
>
> ;2 0 1{ea { >x
>
> 5 2 4
>
>
> How can I generate all of the selections in one 6x3 matrix using just one
> statement, with no explicit looping?
>
>
> Skip
>
> Skip Cave
>
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] All combinations from multiple different-length lists

2020-12-20 Thread Skip Cave
]x=.1 3 5;2;3 4

┌─┬─┬───┐

│1 3 5│2│3 4│

└─┴─┴───┘

{x

┌─┬─┐

│1 2 3│1 2 4│

├─┼─┤

│3 2 3│3 2 4│

├─┼─┤

│5 2 3│5 2 4│

└─┴─┘


Wow! I had no idea monadic { could do that to an already-boxed array! Till
now I had always used monadic { just to box vectors, just like <

{1 2 3

┌─┐

│1 2 3│

└─┘

<1 2 3

┌─┐

│1 2 3│

└─┘

Thanks Henry & Chris.
Where is the doc describing that monadic { feature?

,/> is nice as well, and this I understand. It's just insert/ravel. Turns a
3x2x3 array into a 3x6 array.

Skip Cave



On Sun, Dec 20, 2020 at 12:51 PM Henry Rich  wrote:

> ,/>{x
>
> Henry Rich
>
> On 12/20/2020 1:48 PM, Skip Cave wrote:
> > I have three lists stored in x:
> >
> > ]x=.1 3 5;2;3 4
> >
> > ┌─┬─┬───┐
> >
> > │1 3 5│2│3 4│
> >
> > └─┴─┴───┘
> >
> > I want to find all possible combinations of the elements of these lists
> > (taking one from each list).
> >
> > Using the odometer function I can generate all the possible index
> > combinations of selections from those three lists:
> >
> >
> > odo ;# each x
> >
> > 0 0 0
> >
> > 0 0 1
> >
> > 1 0 0
> >
> > 1 0 1
> >
> > 2 0 0
> >
> > 2 0 1
> >
> >
> > Now I can individually find each selection from the three lists
> >
> >
> > ;0 0 0{ea { >x
> >
> > 1 2 3
> >
> > ;0 0 1{ea { >x
> >
> > 1 2 4
> >
> > ;1 0 0{ea { >x
> >
> > 3 2 3
> >
> > ;1 0 1{ea { >x
> >
> > 3 2 4
> >
> > ;2 0 0{ea { >x
> >
> > 5 2 3
> >
> > ;2 0 1{ea { >x
> >
> > 5 2 4
> >
> >
> > How can I generate all of the selections in one 6x3 matrix using just one
> > statement, with no explicit looping?
> >
> >
> > Skip
> >
> > Skip Cave
> > --
> > 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


[Jprogramming] All combinations from multiple different-length lists

2020-12-20 Thread Skip Cave
I have three lists stored in x:

]x=.1 3 5;2;3 4

┌─┬─┬───┐

│1 3 5│2│3 4│

└─┴─┴───┘

I want to find all possible combinations of the elements of these lists
(taking one from each list).

Using the odometer function I can generate all the possible index
combinations of selections from those three lists:


odo ;# each x

0 0 0

0 0 1

1 0 0

1 0 1

2 0 0

2 0 1


Now I can individually find each selection from the three lists


;0 0 0{ea { >x

1 2 3

;0 0 1{ea { >x

1 2 4

;1 0 0{ea { >x

3 2 3

;1 0 1{ea { >x

3 2 4

;2 0 0{ea { >x

5 2 3

;2 0 1{ea { >x

5 2 4


How can I generate all of the selections in one 6x3 matrix using just one
statement, with no explicit looping?


Skip

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


Re: [Jprogramming] String replace puzzle

2020-12-18 Thread Skip Cave
n=.'1+(2*3)+(4*(5+6))'

'()'i.n

2 2 0 2 2 2 1 2 0 2 2 0 2 2 2 1 1


Now THAT is cool! I forgot one could use dyadic i. as "first occurrence".
That's a much simpler way to generate the amend indices.

.
Skip Cave
Cave Consulting LLC


On Fri, Dec 18, 2020 at 12:21 PM 'Michael Day' via Programming <
programm...@jsoftware.com> wrote:

> Unlike in the K forum,  the J-wires have been virtually silent on this
> year's Advent of Code...
>
> Anyway,  today's problem,  number 18,  might interest J & APLers as part
> 1 is ALMOST
> plug-it-in to J/APL;  there's just one twist,  so to speak,  namely we
> need to reverse an
> arithmetic expression,  eg
> 1 + (2 * 3) + (4 * (5 + 6))
> needs to be evaluated as
> ((6 + 5) * 4) + (3 * 2) + 1
>
> But, even though all numbers are single-digit,  just reversing the
> string doesn't work,  fairly obviously:
> |.'1 + (2 * 3) + (4 * (5 + 6))'
> ))6 + 5( * 4( + )3 * 2( + 1
>
> So the brackets need swapping.  The data is supplied as strings,  so I
> expected to use stringreplace,
> as found in strings.ijs
>
> But:
> |.(  ')[' , '()' , '[('  ) stringreplace '1 + (2 * 3) + (4 * (5
> + 6))'
> [[6 + 5) * 4) + [3 * 2) + 1
>
> Why don't the intermediate '[' get changed to the final ')'  ?
>
> The second action in stringreplace is on the left hand argument:
> _2 [\ ,(')[' , '()' , '[(' )
> )[
> ()
> [(
>
> The first column should be items of old text and the second column
> their new replacements.  But the third pair seems to be ignored.
>
> I did of course get round this little difficulty,  but would have preferred
> not to reinvent the wheel.
>
> NB. Part 2 is a little more challenging,  as + is defined there as taking
> precedence over * .
>
> Thanks,
>
> 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
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] String replace puzzle

2020-12-18 Thread Skip Cave
Using curlyrt: (amend in place)

n=.'1+(2*3)+(4*(5+6))'


|.(+/1 2*'()'=/n)}n,(17#')'),:(17#'(')

((6+5)*4)+(3*2)+1



Skip Cave
Cave Consulting LLC


On Fri, Dec 18, 2020 at 12:21 PM 'Michael Day' via Programming <
programm...@jsoftware.com> wrote:

> Unlike in the K forum,  the J-wires have been virtually silent on this
> year's Advent of Code...
>
> Anyway,  today's problem,  number 18,  might interest J & APLers as part
> 1 is ALMOST
> plug-it-in to J/APL;  there's just one twist,  so to speak,  namely we
> need to reverse an
> arithmetic expression,  eg
> 1 + (2 * 3) + (4 * (5 + 6))
> needs to be evaluated as
> ((6 + 5) * 4) + (3 * 2) + 1
>
> But, even though all numbers are single-digit,  just reversing the
> string doesn't work,  fairly obviously:
> |.'1 + (2 * 3) + (4 * (5 + 6))'
> ))6 + 5( * 4( + )3 * 2( + 1
>
> So the brackets need swapping.  The data is supplied as strings,  so I
> expected to use stringreplace,
> as found in strings.ijs
>
> But:
> |.(  ')[' , '()' , '[('  ) stringreplace '1 + (2 * 3) + (4 * (5
> + 6))'
> [[6 + 5) * 4) + [3 * 2) + 1
>
> Why don't the intermediate '[' get changed to the final ')'  ?
>
> The second action in stringreplace is on the left hand argument:
> _2 [\ ,(')[' , '()' , '[(' )
> )[
> ()
> [(
>
> The first column should be items of old text and the second column
> their new replacements.  But the third pair seems to be ignored.
>
> I did of course get round this little difficulty,  but would have preferred
> not to reinvent the wheel.
>
> NB. Part 2 is a little more challenging,  as + is defined there as taking
> precedence over * .
>
> Thanks,
>
> 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
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Square root error

2020-12-13 Thread Skip Cave
Strange errors in the root function:


JVERSION

Engine: j902/j64avx2/windows

Beta-n: commercial/2020-11-21T12:09:32

Library: 9.02.06

Qt IDE: 1.8.7/5.12.7(5.12.7)

Platform: Win 64

Installer: J902 install

InstallPath: c:/users/skip/j902

Contact: www.jsoftware.com


9!:11 [20 NB. Set print precision


899^2

808201

%: 808201

899

808201^1r2

898.77263

2%: 808201

898.77263


Cube root


899^3

726572699

3%: 726572699

898.77263

726572699^1r3

898.77263

Why the small error in some forms of square root?



Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Multiple rotations

2020-10-31 Thread Skip Cave
Here's the problem i was trying to solve :

The number 197 is called a circular prime because all rotations of the
digits: 197, 971, and 719, are themselves prime. There are thirteen such
primes below 100. How many circular primes are there below One million? Link
to problem on Quora.
<https://www.quora.com/Number-197-is-called-a-circular-prime-because-all-rotations-of-the-digits-197-971-and-719-are-themselves-prime-There-are-thirteen-such-primes-below-100-How-many-circular-primes-are-there-below-One-million-What-will?__nsrc__=4>

Here's my solution - thanks to ethiejiesa:

*#m=.n#~;*./ea p=.1 p: ea ~. ea 10#.ea(|.~ ,.@i.@#)&.> sep ea n=.1 to 1e6*

*55*

There are 55 circular primes in the integers from 1 to 1e6.

List them:

* m*

* 2 3 5 7 11 13 17 31 37 71 73 79 97 113 131 197 199 311 337 373 719 733
919 971 991 1193 1931 3119 3779 7793 7937 9311 9377 11939 19391 19937 37199
39119 71993 91193 93719 93911 99371 193939 199933 319993 331999 391939
393919 919393 933199 939193 939391 993319 999331*
Skip


On Sat, Oct 31, 2020 at 1:58 AM Skip Cave  wrote:

> Wow! That will take me some studying to understand, but that is exactly
> what I needed. Thanks so much!
>
> Skip
>
>
> Skip Cave
> Cave Consulting LLC
>
>
> On Sat, Oct 31, 2020 at 1:33 AM ethiejiesa via Programming <
> programm...@jsoftware.com> wrote:
>
>> What about something like this?
>>
>>(|.~ ,.@i.@#)&.> n
>> ┌─┬─┬───┬───┐
>> │1 2 3│4 5 6 7 8│8 6│3 5 7 9│
>> │2 3 1│5 6 7 8 4│6 8│5 7 9 3│
>> │3 1 2│6 7 8 4 5│   │7 9 3 5│
>>     │ │7 8 4 5 6│   │9 3 5 7│
>> │ │8 4 5 6 7│   │   │
>> └─┴─┴───┴───┘
>>
>> Skip Cave  wrote:
>> > Is there a more concise way to express m rotations of each of a set of
>> > items?
>> >
>> > ]n=.1 2 3;4 5 6 7 8;8 6;3 5 7 9
>> >
>> > ┌─┬─┬───┬───┐
>> >
>> > │1 2 3│4 5 6 7 8│8 6│3 5 7 9│
>> >
>> > └─┴─┴───┴───┘
>> >
>> > m=. 0, 1, 2, 3, 4 NB. Number of rotations
>> >
>> > ea =. each
>> >
>> >
>> > n,.(1|.ea n),.(2|.ea n),.(3|.ea n),.(4|.ea n)
>> >
>> > ┌─┬─┬─┬─┬─┐
>> >
>> > │1 2 3 │2 3 1 │3 1 2 │1 2 3 │2 3 1 │
>> >
>> > ├─┼─┼─┼─┼─┤
>> >
>> > │4 5 6 7 8│5 6 7 8 4│6 7 8 4 5│7 8 4 5 6│8 4 5 6 7│
>> >
>> > ├─┼─┼─┼─┼─┤
>> >
>> > │8 6 │6 8 │8 6 │6 8 │8 6 │
>> >
>> > ├─┼─┼─┼─┼─┤
>> >
>> > │3 5 7 9 │5 7 9 3 │7 9 3 5 │9 3 5 7 │3 5 7 9 │
>> >
>> > └─┴─┴─┴─┴─┘
>> >
>> >
>> > Or better yet with no duplicated rotations::
>> >
>> > 2 7$~.,n,.(1|.ea n),.(2|.ea n),.(3|.ea n),.(4|.ea n)
>> >
>> > ┌─┬─┬─┬─┬─┬─┬─┐
>> >
>> > │1 2 3 │2 3 1│3 1 2│4 5 6 7 8│5 6 7 8 4│6 7 8 4 5│7 8 4 5 6│
>> >
>> > ├─┼─┼─┼─┼─┼─┼─┤
>> >
>> > │8 4 5 6 7│8 6 │6 8 │3 5 7 9 │5 7 9 3 │7 9 3 5 │9 3 5 7 │
>> >
>> > └─┴─┴─┴─┴─┴─┴─┘
>> >
>> > Can this be done using iteration rather than explicitly listing each
>> > rotation?
>> >
>> > 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


Re: [Jprogramming] Multiple rotations

2020-10-31 Thread Skip Cave
Wow! That will take me some studying to understand, but that is exactly
what I needed. Thanks so much!

Skip


Skip Cave
Cave Consulting LLC


On Sat, Oct 31, 2020 at 1:33 AM ethiejiesa via Programming <
programm...@jsoftware.com> wrote:

> What about something like this?
>
>(|.~ ,.@i.@#)&.> n
> ┌─┬─┬───┬───┐
> │1 2 3│4 5 6 7 8│8 6│3 5 7 9│
> │2 3 1│5 6 7 8 4│6 8│5 7 9 3│
> │3 1 2│6 7 8 4 5│   │7 9 3 5│
> │ │7 8 4 5 6│   │9 3 5 7│
> │ │8 4 5 6 7│   │   │
> └─┴─┴───┴───┘
>
> Skip Cave  wrote:
> > Is there a more concise way to express m rotations of each of a set of
> > items?
> >
> > ]n=.1 2 3;4 5 6 7 8;8 6;3 5 7 9
> >
> > ┌─┬─┬───┬───┐
> >
> > │1 2 3│4 5 6 7 8│8 6│3 5 7 9│
> >
> > └─┴─┴───┴───┘
> >
> > m=. 0, 1, 2, 3, 4 NB. Number of rotations
> >
> > ea =. each
> >
> >
> > n,.(1|.ea n),.(2|.ea n),.(3|.ea n),.(4|.ea n)
> >
> > ┌─┬─┬─┬─┬─┐
> >
> > │1 2 3 │2 3 1 │3 1 2 │1 2 3 │2 3 1 │
> >
> > ├─┼─┼─┼─┼─┤
> >
> > │4 5 6 7 8│5 6 7 8 4│6 7 8 4 5│7 8 4 5 6│8 4 5 6 7│
> >
> > ├─┼─┼─┼─┼─┤
> >
> > │8 6 │6 8 │8 6 │6 8 │8 6 │
> >
> > ├─┼─┼─┼─┼─┤
> >
> > │3 5 7 9 │5 7 9 3 │7 9 3 5 │9 3 5 7 │3 5 7 9 │
> >
> > └─┴─┴─┴─┴─┘
> >
> >
> > Or better yet with no duplicated rotations::
> >
> > 2 7$~.,n,.(1|.ea n),.(2|.ea n),.(3|.ea n),.(4|.ea n)
> >
> > ┌─┬─┬─┬─┬─┬─┬─┐
> >
> > │1 2 3 │2 3 1│3 1 2│4 5 6 7 8│5 6 7 8 4│6 7 8 4 5│7 8 4 5 6│
> >
> > ├─┼─┼─┼─┼─┼─┼─┤
> >
> > │8 4 5 6 7│8 6 │6 8 │3 5 7 9 │5 7 9 3 │7 9 3 5 │9 3 5 7 │
> >
> > └─┴─┴─┴─┴─┴─┴─┘
> >
> > Can this be done using iteration rather than explicitly listing each
> > rotation?
> >
> > 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


[Jprogramming] Multiple rotations

2020-10-31 Thread Skip Cave
Is there a more concise way to express m rotations of each of a set of
items?

]n=.1 2 3;4 5 6 7 8;8 6;3 5 7 9

┌─┬─┬───┬───┐

│1 2 3│4 5 6 7 8│8 6│3 5 7 9│

└─┴─┴───┴───┘

m=. 0, 1, 2, 3, 4 NB. Number of rotations

ea =. each


n,.(1|.ea n),.(2|.ea n),.(3|.ea n),.(4|.ea n)

┌─┬─┬─┬─┬─┐

│1 2 3 │2 3 1 │3 1 2 │1 2 3 │2 3 1 │

├─┼─┼─┼─┼─┤

│4 5 6 7 8│5 6 7 8 4│6 7 8 4 5│7 8 4 5 6│8 4 5 6 7│

├─┼─┼─┼─┼─┤

│8 6 │6 8 │8 6 │6 8 │8 6 │

├─┼─┼─┼─┼─┤

│3 5 7 9 │5 7 9 3 │7 9 3 5 │9 3 5 7 │3 5 7 9 │

└─┴─┴─┴─┴─┘


Or better yet with no duplicated rotations::

2 7$~.,n,.(1|.ea n),.(2|.ea n),.(3|.ea n),.(4|.ea n)

┌─┬─┬─┬─┬─┬─┬─┐

│1 2 3 │2 3 1│3 1 2│4 5 6 7 8│5 6 7 8 4│6 7 8 4 5│7 8 4 5 6│

├─┼─┼─┼─┼─┼─┼─┤

│8 4 5 6 7│8 6 │6 8 │3 5 7 9 │5 7 9 3 │7 9 3 5 │9 3 5 7 │

└─┴─┴─┴─┴─┴─┴─┘

Can this be done using iteration rather than explicitly listing each
rotation?

Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Calculus & Newton's iteration

2020-10-24 Thread Skip Cave
I just realized that I don't need Newton:

2/x + 4.9 = 0?

2/x = 49/10

2 = 49/10 * x

x = 2/(49/10) = 2*(10/49) = 20/49 = 0.4081632653
Skip Cave
Cave Consulting LLC


On Sat, Oct 24, 2020 at 10:12 AM Skip Cave  wrote:

> The Newton Raphson root finder using the new J definition of derivative is:
>
> N=: 1 : '- u % u deriv_jcalculus_ 1'
>
>
> How would I use N to solve for x in the equation 2/x + 4.9 = 0?
>
>
> Skip Cave
> Cave Consulting LLC
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Calculus & Newton's iteration

2020-10-24 Thread Skip Cave
The Newton Raphson root finder using the new J definition of derivative is:

N=: 1 : '- u % u deriv_jcalculus_ 1'


How would I use N to solve for x in the equation 2/x + 4.9 = 0?


Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Strange output.

2020-08-21 Thread Skip Cave
All,
Thanks for all the help!

Hauke reminded me to use <\ to generate increasing length lists,
as well as a more concise way to remove all blanks: rab2 =: -.&'

Xash showed me the power of @, and how to avoid integer overflow to
floating point :
  ]m=:<\ *: >: i.15
(sep @ ". @ (,&'x') @ rab @ ": @ ,)each m

More concise, but this loses the extended integers:
   <@( [: ". @ ,. @ ; <@":"0)\ *: >: i. 15

Bob showed how to eliminate the character/integer conversions altogether:
   

[Jprogramming] Strange output.

2020-08-21 Thread Skip Cave
Definitions:
ea =: each

rab =: ]#~[:-.' '=] NB. Remove all blanks.

sep =:10 #.^:_1 ] NB. separate digits.


NB. Generate increasing lengths of integer squares & store in m:

]m=.1{.ea n,\ ea {sq=.*:n=.>:i.15

│1│1 4│1 4 9│1 4 9 16│1 4 9 16 25│1 4 9 16 25 36│1 4 9 16 25 36 49│1 4 9 16
25 36 49 64│1 4 9 16 25 36 49 64 81│1 4 9 16 25 36 49 64 81 100│1 4 9 16 25
36 49 64 81 100 121│1 4 9 16 25 36 49 64 81 100 121 144│1 4 9 16 25 36 49
64 81 100 121 144 169│1 4 9 16...

datatype each m

│integer│integer│integer│integer│integer│integer│integer│integer│integer│integer│integer│integer│integer│integer│integer│


NB. Convert each box to characters, remove blanks, convert back to
integers, separate the digits, store in p, & display:

]p=.sep ea ". ea rab ea":ea ,ea m

│1│1 4│1 4 9│1 4 9 1 6│1 4 9 1 6 2 5│1 4 9 1 6 2 5 3 6│1 4 9 1 6 2 5 3 6 4
9│1 4 9 1 6 2 5 3 6 4 9 6 4│1 4 9 1 6 2 5 3 6 4 9 6 4 8 1│1 4 9 1 6 2 5 3 6
4 9 6 4 8 1 1 0 0│1 4 9 1 6 2 5 3 6 4 9 6 4 8.11328 0 0 0 0 0 0 0│1 4 9 1 6
2 5 3 6 4 9 6 4 8.11328 0 0 0...


NB. UhOh! there are floating-point numbers in p! should all be integers!

datatype each p

│integer│integer│integer│integer│integer│integer│integer│integer│integer│integer│floating│floating│floating│floating│floating│


NB. What is with the floating point numbers 8.11328 in p? They should be
all integers!


Also, is there a better way to generate increasing length sets of a vector?

JVERSION

Engine: j902/j64avx2/windows

Beta-e: commercial/2020-08-14T11:56:28

Library: 9.02.05

Qt IDE: 1.8.7/5.12.7(5.12.7)

Platform: Win 64

Installer: J902 install

InstallPath: c:/users/skip/j902

Contact: www.jsoftware.com


Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Floor of infinity

2020-08-03 Thread Skip Cave
I created two test vectors:
integer test:
intst=: _1e10 _1 0 0 1 1e10 _1.1 _0.1 0.1 1.1 100.1 __ _ _.
Integer range test:
rgtst=:10^i.20

My original verb:

(=>.)intst

1 1 1 1 1 1 0 0 0 0 0 1 1 0

(=>.)rgtst

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1


This misses both infinities and the range test.


Hauke's verb:

((=<.)*.(~:<:)) intst

1 1 1 1 1 1 0 0 0 0 0 0 0 0

((=<.)*.(~:<:)) rgtst

1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0


This gets the integers right, but misses some of the larger integers before
they turn into floats.


Raul's verb:

MAXINT=: #.1#~31+32*IF64

MININT=: <:-MAXINT

isinteger=:(=<.)*<: * >:

isinteger intst

1 1 1 1 1 1 0 0 0 0 0 0 0 0

isinteger rgtst

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0


This gets both tests right.


Devon, Hauke, & Julian proposed just matching and throwing away the items
we didn't want:

([: ((= <.)) _ __ _. -.~ ])intst

1 1 1 1 1 1 0 0 0 0 0 0

([: ((= <.)) _ __ _. -.~ ])rgtst

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1


This misses the range test just like my original verb.


Raul's proposal is the only one that correctly handles the very large
integers. However, most of my uses for an integer-finding verb don't
involve very large floating point integers. Otoh, in my applications there
will occasionally be a divide by zero, producing an infinity value. So
Hauke's finiteinteger verb does the job I need in a nice, concise way. I'll
keep that in my list of handy verbs, replacing my old (=>.).

Skip

On Sun, Aug 2, 2020 at 1:44 AM Skip Cave  wrote:

> I use the (=<.) verb to find integers in a list:
>
>
> * (=<.)1 2.5 2.7 3 4.5 6*
>
> *1 0 0 1 0 1*
>
> * (#~(=<.))1 2.5 2.7 3 4.5 6*
>
> *1 3 6*
>
> I ran across an interesting result when infinity is in the list:
>
> * (=<.)1 2.5 __ 3 4.5 6*
>
> *1 0 1 1 0 1*
>
> * (#~(=<.))1 2.5 __ 3 4.5 6*
>
> *1 __ 3 6*
>
>
> So J is saying that the floor of infinity is infinity (and the ceiling of
> infinity is also infinity). Since infinity is not a number, it would seem
> that an error should be generated when taking the floor of infinity, or
> perhaps NAN, or a zero? In any case, this messes up my nice integer-finding
> verb. Is the\re a mathematical justification for defining the floor of
> infinity to be infinity?
> https://math.stackexchange.com/questions/981708/limit-of-floor-function-when-x-goes-infinity
>
>
> Skip
>
>
> Skip Cave
> Cave Consulting LLC
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Floor of infinity

2020-08-02 Thread Skip Cave
I see:

(<.= >.) 1 2.5 __ 3 4.5 6

1 0 1 1 0 1


This has the same issue as (=<.)


Skip Cave

On Sun, Aug 2, 2020 at 7:48 AM Skip Cave  wrote:

> Henry said:
>   <. = >.
>
> I'll try it out:
>
> <. = >. 1 2.5 __ 3 4.5 6
>
> 1 0 0 0 0 0
>
> 0 1 0 1 0 0
>
> 0 0 1 0 0 0
>
> 0 0 0 0 1 0
>
> 0 0 0 0 0 1
>
>
> Not sure what this does?
>
>
> Skip
>
>
> On Sun, Aug 2, 2020 at 7:30 AM Henry Rich  wrote:
>
>> <. = >.
>>
>> Henry Rich
>>
>> On 8/2/2020 8:24 AM, Skip Cave wrote:
>> > What I'm really looking for, is a verb that finds integers in a list:
>> >
>> > datatype 2.5
>> >
>> > floating
>> >
>> > datatype 3
>> >
>> > integer
>> >
>> > datatype __
>> >
>> > floating
>> >
>> >
>> > So J considers __ as "floating"
>> >
>> >
>> >   So I want a verb "isinteger" that marks the integers in a vector,
>> where __
>> > is in the list, and is considered floating:
>> >
>> >isinteger 1 2.5 __ 3 4.5 6
>> > 1 0 0 1 0 1
>> >
>> > And maybe the inverse also:
>> >
>> > isfloating 1 2.5 __ 3 4.5 6
>> >
>> > 0 1 1 0 1 0
>> >
>> >
>> > My (=<,) doesn't do it:
>> >
>> > (=<.)1 2.5 __ 3 4.5 6
>> >
>> > 1 0 1 1 0 1
>> >
>> >
>> > So what would "isinteger" look like?
>> >
>> >
>> > Skip
>> >
>> >
>> > Skip Cave
>> > Cave Consulting LLC
>> >
>> >
>> > On Sun, Aug 2, 2020 at 1:44 AM Skip Cave 
>> wrote:
>> >
>> >> I use the (=<.) verb to find integers in a list:
>> >>
>> >>
>> >> * (=<.)1 2.5 2.7 3 4.5 6*
>> >>
>> >> *1 0 0 1 0 1*
>> >>
>> >> * (#~(=<.))1 2.5 2.7 3 4.5 6*
>> >>
>> >> *1 3 6*
>> >>
>> >> I ran across an interesting result when infinity is in the list:
>> >>
>> >> * (=<.)1 2.5 __ 3 4.5 6*
>> >>
>> >> *1 0 1 1 0 1*
>> >>
>> >> * (#~(=<.))1 2.5 __ 3 4.5 6*
>> >>
>> >> *1 __ 3 6*
>> >>
>> >>
>> >> So J is saying that the floor of infinity is infinity (and the ceiling
>> of
>> >> infinity is also infinity). Since infinity is not a number, it would
>> seem
>> >> that an error should be generated when taking the floor of infinity, or
>> >> perhaps NAN, or a zero? In any case, this messes up my nice
>> integer-finding
>> >> verb. Is the\re a mathematical justification for defining the floor of
>> >> infinity to be infinity?
>> >>
>> https://math.stackexchange.com/questions/981708/limit-of-floor-function-when-x-goes-infinity
>> >>
>> >>
>> >> Skip
>> >>
>> >>
>> >> Skip Cave
>> >> Cave Consulting LLC
>> >>
>> > --
>> > 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


Re: [Jprogramming] Floor of infinity

2020-08-02 Thread Skip Cave
Henry said:
  <. = >.

I'll try it out:

<. = >. 1 2.5 __ 3 4.5 6

1 0 0 0 0 0

0 1 0 1 0 0

0 0 1 0 0 0

0 0 0 0 1 0

0 0 0 0 0 1


Not sure what this does?


Skip


On Sun, Aug 2, 2020 at 7:30 AM Henry Rich  wrote:

> <. = >.
>
> Henry Rich
>
> On 8/2/2020 8:24 AM, Skip Cave wrote:
> > What I'm really looking for, is a verb that finds integers in a list:
> >
> > datatype 2.5
> >
> > floating
> >
> > datatype 3
> >
> > integer
> >
> > datatype __
> >
> > floating
> >
> >
> > So J considers __ as "floating"
> >
> >
> >   So I want a verb "isinteger" that marks the integers in a vector,
> where __
> > is in the list, and is considered floating:
> >
> >isinteger 1 2.5 __ 3 4.5 6
> > 1 0 0 1 0 1
> >
> > And maybe the inverse also:
> >
> > isfloating 1 2.5 __ 3 4.5 6
> >
> > 0 1 1 0 1 0
> >
> >
> > My (=<,) doesn't do it:
> >
> > (=<.)1 2.5 __ 3 4.5 6
> >
> > 1 0 1 1 0 1
> >
> >
> > So what would "isinteger" look like?
> >
> >
> > Skip
> >
> >
> > Skip Cave
> > Cave Consulting LLC
> >
> >
> > On Sun, Aug 2, 2020 at 1:44 AM Skip Cave 
> wrote:
> >
> >> I use the (=<.) verb to find integers in a list:
> >>
> >>
> >> * (=<.)1 2.5 2.7 3 4.5 6*
> >>
> >> *1 0 0 1 0 1*
> >>
> >> * (#~(=<.))1 2.5 2.7 3 4.5 6*
> >>
> >> *1 3 6*
> >>
> >> I ran across an interesting result when infinity is in the list:
> >>
> >> * (=<.)1 2.5 __ 3 4.5 6*
> >>
> >> *1 0 1 1 0 1*
> >>
> >> * (#~(=<.))1 2.5 __ 3 4.5 6*
> >>
> >> *1 __ 3 6*
> >>
> >>
> >> So J is saying that the floor of infinity is infinity (and the ceiling
> of
> >> infinity is also infinity). Since infinity is not a number, it would
> seem
> >> that an error should be generated when taking the floor of infinity, or
> >> perhaps NAN, or a zero? In any case, this messes up my nice
> integer-finding
> >> verb. Is the\re a mathematical justification for defining the floor of
> >> infinity to be infinity?
> >>
> https://math.stackexchange.com/questions/981708/limit-of-floor-function-when-x-goes-infinity
> >>
> >>
> >> Skip
> >>
> >>
> >> Skip Cave
> >> Cave Consulting LLC
> >>
> > --
> > 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


Re: [Jprogramming] Floor of infinity

2020-08-02 Thread Skip Cave
What I'm really looking for, is a verb that finds integers in a list:

datatype 2.5

floating

datatype 3

integer

datatype __

floating


So J considers __ as "floating"


 So I want a verb "isinteger" that marks the integers in a vector, where __
is in the list, and is considered floating:

  isinteger 1 2.5 __ 3 4.5 6
1 0 0 1 0 1

And maybe the inverse also:

isfloating 1 2.5 __ 3 4.5 6

0 1 1 0 1 0


My (=<,) doesn't do it:

(=<.)1 2.5 __ 3 4.5 6

1 0 1 1 0 1


So what would "isinteger" look like?


Skip


Skip Cave
Cave Consulting LLC


On Sun, Aug 2, 2020 at 1:44 AM Skip Cave  wrote:

> I use the (=<.) verb to find integers in a list:
>
>
> * (=<.)1 2.5 2.7 3 4.5 6*
>
> *1 0 0 1 0 1*
>
> * (#~(=<.))1 2.5 2.7 3 4.5 6*
>
> *1 3 6*
>
> I ran across an interesting result when infinity is in the list:
>
> * (=<.)1 2.5 __ 3 4.5 6*
>
> *1 0 1 1 0 1*
>
> * (#~(=<.))1 2.5 __ 3 4.5 6*
>
> *1 __ 3 6*
>
>
> So J is saying that the floor of infinity is infinity (and the ceiling of
> infinity is also infinity). Since infinity is not a number, it would seem
> that an error should be generated when taking the floor of infinity, or
> perhaps NAN, or a zero? In any case, this messes up my nice integer-finding
> verb. Is the\re a mathematical justification for defining the floor of
> infinity to be infinity?
> https://math.stackexchange.com/questions/981708/limit-of-floor-function-when-x-goes-infinity
>
>
> Skip
>
>
> Skip Cave
> Cave Consulting LLC
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Floor of infinity

2020-08-02 Thread Skip Cave
I use the (=<.) verb to find integers in a list:


* (=<.)1 2.5 2.7 3 4.5 6*

*1 0 0 1 0 1*

* (#~(=<.))1 2.5 2.7 3 4.5 6*

*1 3 6*

I ran across an interesting result when infinity is in the list:

* (=<.)1 2.5 __ 3 4.5 6*

*1 0 1 1 0 1*

* (#~(=<.))1 2.5 __ 3 4.5 6*

*1 __ 3 6*


So J is saying that the floor of infinity is infinity (and the ceiling of
infinity is also infinity). Since infinity is not a number, it would seem
that an error should be generated when taking the floor of infinity, or
perhaps NAN, or a zero? In any case, this messes up my nice integer-finding
verb. Is the\re a mathematical justification for defining the floor of
infinity to be infinity?
https://math.stackexchange.com/questions/981708/limit-of-floor-function-when-x-goes-infinity


Skip


Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Standard library version of statistical "mode"?

2020-07-24 Thread Skip Cave
Raul,
I was thinking more along the lines of:

hsbc=:[:(]{"1~[:\:1{])~.,:#/.~

hsbc n

13 9 14 6 10 7

3 2 2 1 1 1

box hsbc n
┌──┬─┬──┬─┬──┬─┐
│13│9│14│6│10│7│
│3 │2│2 │1│1 │1│
└──┴─┴──┴─┴──┴─┘
How could the box verb be made?

Skip Cave
Cave Consulting LLC


On Fri, Jul 24, 2020 at 6:20 PM Raul Miller  wrote:

> Well... first off, there's a trivial conversion to tacit available here:
>
>13 :'h{"1~\:1{h=.(~.,:#/.~)n=.y'
> [: (] {"1~ [: \: 1 { ]) ~. ,: #/.~
>
> And I guess that's good enough, so let's just name it:
>
>hsbc=: 13 :'h{"1~\:1{h=.(~.,:#/.~)n=.y'
>n=: 9 13 6 9 13 13 10 14 7 14
>
> As for vertical boxes, maybe something like this would be close enough
> to what you want?
>
>vbox=: ]each@{.,:'#' ,.@#each~ {:
>vbox hsbc n
> +--+-+--+-+--+-+
> |13|9|14|6|10|7|
> +--+-+--+-+--+-+
> |# |#|# |#|# |#|
> |# |#|# | |  | |
> |# | |  | |  | |
> +--+-+--+-+--+-+
>
> Though personally, I might be more inclined towards horizontal boxes
> (partially because the proportional font I see used in email contexts
> messes up vertical boxes so badly, but also see my hbar suggestion)
>
>hbox=: ]each@{.,.'#' #each~ {:
>hbox hsbc n
>
> Or, getting rid of the boxes:
>
>hbar=: ":@,.@{. ,.' ' ,. '#' #every~ {:
>hbar hsbc n
> 13 ###
>  9 ##
> 14 ##
>  6 #
> 10 #
>  7 #
>
> (This sort of thing still looks better with a fixed width font, in my
> opinion.)
>
> Thanks,
>
>
> --
> Raul
>
> On Fri, Jul 24, 2020 at 6:45 PM Skip Cave  wrote:
> >
> > I find that a histogram of the data sorted by count, is useful in many
> > cases, in place of the mode:
> >
> > ]n=.?10#15
> >
> > 9 13 6 9 13 13 10 14 7 14
> >
> > h{"1~\:1{h=.(~.,:#/.~)n
> >
> > 13 9 14 6 10 7
> >
> > 3 2 2 1 1 1
> >
> >
> > I'm sure there are more concise ways to express this, and it would be
> nice
> > to have vertical boxes for each quantity, but this gets what I need done.
> >
> >
> > Skip
> >
> > Skip Cave
> > Cave Consulting LLC
> >
> >
> > On Fri, Jul 24, 2020 at 1:47 PM Raul Miller 
> wrote:
> >
> > >
> https://en.wikipedia.org/wiki/Mode_(statistics)#Uniqueness_and_definedness
> > >
> > > "Finally, as said before, the mode is not necessarily unique. Certain
> > > pathological distributions (for example, the Cantor distribution) have
> > > no defined mode at all."
> > >
> > > That said, just as we can redefine median to be the mean of the two
> > > median values when the length of the sequence is even, we could
> > > redefine mode as the median of the candidate mode values when there is
> > > more than one "most frequently occuring value".
> > >
> > > Thanks,
> > >
> > > --
> > > Raul
> > >
> > > On Fri, Jul 24, 2020 at 2:36 PM Devon McCormick 
> > > wrote:
> > > >
> > > > Hi - I've started reading "Fun Q" which is a book on machine learning
> > > using
> > > > the q language.  Early on, the author points out that his "mode"
> > > function -
> > > > where "mode" is stats-talk for "the most frequent observation" - is
> > > > order-dependent.
> > > >
> > > > I checked my own "mode" and found that this is true of mine as well:
> > > > mode
> > > >~. {~ [: (i. >./) #/.~
> > > >mode 1 2 2 3 3
> > > > 2
> > > >mode 1 3 3 2 2
> > > > 3
> > > >
> > > > This might be an ill-defined statistical concept but does anyone
> have any
> > > > insight based on practice?  Is this order-dependence just a weakness
> of
> > > the
> > > > definition of "mode"?
> > > >
> > > > I could not find "mode" defined in any of the J standard libraries.
> > > >
> > > > Thanks,
> > > >
> > > > Devon
> > > >
> > > > --
> > > >
> > > > Devon McCormick, CFA
> > > >
> > > > Quantitative Consultant
> > > >
> --
> > > > 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


Re: [Jprogramming] Standard library version of statistical "mode"?

2020-07-24 Thread Skip Cave
I find that a histogram of the data sorted by count, is useful in many
cases, in place of the mode:

]n=.?10#15

9 13 6 9 13 13 10 14 7 14

h{"1~\:1{h=.(~.,:#/.~)n

13 9 14 6 10 7

3 2 2 1 1 1


I'm sure there are more concise ways to express this, and it would be nice
to have vertical boxes for each quantity, but this gets what I need done.


Skip

Skip Cave
Cave Consulting LLC


On Fri, Jul 24, 2020 at 1:47 PM Raul Miller  wrote:

> https://en.wikipedia.org/wiki/Mode_(statistics)#Uniqueness_and_definedness
>
> "Finally, as said before, the mode is not necessarily unique. Certain
> pathological distributions (for example, the Cantor distribution) have
> no defined mode at all."
>
> That said, just as we can redefine median to be the mean of the two
> median values when the length of the sequence is even, we could
> redefine mode as the median of the candidate mode values when there is
> more than one "most frequently occuring value".
>
> Thanks,
>
> --
> Raul
>
> On Fri, Jul 24, 2020 at 2:36 PM Devon McCormick 
> wrote:
> >
> > Hi - I've started reading "Fun Q" which is a book on machine learning
> using
> > the q language.  Early on, the author points out that his "mode"
> function -
> > where "mode" is stats-talk for "the most frequent observation" - is
> > order-dependent.
> >
> > I checked my own "mode" and found that this is true of mine as well:
> > mode
> >~. {~ [: (i. >./) #/.~
> >mode 1 2 2 3 3
> > 2
> >mode 1 3 3 2 2
> > 3
> >
> > This might be an ill-defined statistical concept but does anyone have any
> > insight based on practice?  Is this order-dependence just a weakness of
> the
> > definition of "mode"?
> >
> > I could not find "mode" defined in any of the J standard libraries.
> >
> > Thanks,
> >
> > Devon
> >
> > --
> >
> > Devon McCormick, CFA
> >
> > Quantitative Consultant
> > --
> > 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] fixed pseudorandom ?. very pseudo on powers of 2

2020-07-19 Thread Skip Cave
It's clear that the statistical properties of ?. are repeatable, but they
are are
significantly different than ?

mean"1(?."0,:?)2^i.50

3.98766e12 1.46478e13

mean"1(?."0,:?)2^i.50

3.98766e12 1.29535e13

mean"1(?."0,:?)2^i.50

3.98766e12 1.67325e13

mean"1(?."0,:?)2^i.50

3.98766e12 1.50923e13

mean"1(?."0,:?)100#1e3

194 494.96

mean"1(?."0,:?)100#1e3

194 538.78

mean"1(?."0,:?)100#1e3

194 527.15

mean"1(?."0,:?)100#1e3

194 513.06

The issue is whether that is a problem that needs to be fixed or not:


Skip Cave
Cave Consulting LLC


On Sun, Jul 19, 2020 at 11:02 AM Raul Miller  wrote:

> Well... I think we can agree that if ?. were replaced with 0: that
> that would not be random enough.
>
> So there has to be a better way of talking about this issue.
>
> If the current test suite is looking for hard coded results from ?. --
> and I think it does -- then of course changing the ?. implementation
> would require careful update of the test suite, and this would become
> an ongoing future issue if the underlying implementation changed. So I
> think that that level of effort is what you are talking about??
>
> Thanks,
>
> --
> Raul
>
> On Sun, Jul 19, 2020 at 11:58 AM bill lam  wrote:
> >
> > Even ?. is not good, it won't change. Its purpose is to provide
> repeatable
> > random data for testing, it doesn't matter if it is not random enough.
> >
> > On Sun, Jul 19, 2020 at 11:41 PM Julian Fondren <
> jfond...@minimaltype.com>
> > wrote:
> >
> > > On 2020-07-19 10:31, Brian Schott wrote:
> > > > Yes, I see the problem you are describing better now.
> > > > This behavior for powers of 2 is dissimilar with other power bases.
> > > > It suggests a flaw in the algorithm for ?. .
> > > >
> > > >
> > > >?.2^11
> > > > 1826
> > > >?.2^12
> > > > 1826
> > > >?.2^13
> > > > 1826
> > > > NB. compared to the following
> > > >?.3^11
> > > > 35532
> > > >?.3^12
> > > > 212679
> > > >?.3^13
> > > > 1275561
> > >
> > > #@~."1 (?."0 ,: ?.) 2^i.20
> > > 7 18
> > > #@~."1 (?."0 ,: ?.) 3^i.20
> > > 13 20
> > >
> > > It's only not as obvious with powers of 3.
> > > --
> > > 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] Variable length permutations

2020-07-17 Thread Skip Cave
Raul,  Perfect!

4 16$1 2 3 4 mulperm 2 3 4 5

2 3 4 5 32 23 42 24 52 25 43 34 53 35 54 45

432 342 423 243 324 234 532 352 523 253 325 235 542 452 524 254

425 245 543 453 534 354 435 345 5432 4532 5342 3542 4352 3452 5423 4523

5243 2543 4253 2453 5324 3524 5234 2534 3254 2354 4325 3425 4235 2435 3245
2345

Or sorted:

4 16$/:~1 2 3 4 mulperm 2 3 4 5

2 3 4 5 23 24 25 32 34 35 42 43 45 52 53 54

234 235 243 245 253 254 324 325 342 345 352 354 423 425 432 435

452 453 523 524 532 534 542 543 2345 2354 2435 2453 2534 2543 3245 3254

3425 3452 3524 3542 4235 4253 4325 4352 4523 4532 5234 5243 5324 5342 5423
5432


Thanks!


Skip Cave
Cave Consulting LLC


On Fri, Jul 17, 2020 at 11:26 PM Raul Miller  wrote:

> Is this what you are after (the order is slightly different)?
>
>mulperm=: [: ; (perm&.> #) (10 p.~ {)L:0 ]
>1 2 3 mulperm 2 4 5
> 2 4 5 42 24 52 25 54 45 542 452 524 254 425 245
>1 3 mulperm 2 4 5
> 2 4 5 542 452 524 254 425 245
>
> Thanks,
>
> --
> Raul
>
> On Fri, Jul 17, 2020 at 11:35 PM Skip Cave 
> wrote:
> >
> > Thanks Raul & Bob for the excellent & concise solutions to my problem.
> > I would like to generalise the verb a bit more to a dyadic verb where the
> > lengths of the multiple permutations
> > and the permuted items are the x & y of the dyad are adjustable:
> >
> > 1 2 3  mulperm 2 4 5
> >
> > 2 4 5 24 25 42 45 52 54 245 254 425 452 524 542
> >
> >
> > 1 3  mulperm 2 4 5 2 4 5 245 254 425 452 524 542
> >
> >
> > Here's as far as I have gotten:
> >
> > >10#.ea~.(1{.ea n),(2{.ea n),n=.{(]{~[:perm #) 2 4 5
> >
> > 2 4 5 24 25 42 45 52 54 245 254 425 452 524 542
> >
> >
> > Skip Cave
> > Cave Consulting LLC
> >
> >
> > On Fri, Jul 17, 2020 at 4:46 PM Skip Cave 
> wrote:
> >
> > > Is there a more efficient and/or concise way to generate this sequence?
> > >
> > > 4 16$>10#.each >: each ({1 perm 4),({2 perm 4),({3 perm 4),({4 perm 4)
> > >
> > > 1 2 3 4 12 21 13 31 14 41 23 32 24 42 34 43
> > >
> > > 123 132 213 231 312 321 124 142 214 241 412 421 134 143 314 341
> > >
> > > 413 431 234 243 324 342 423 432 1234 1243 1324 1342 1423 1432 2134 2143
> > >
> > > 2314 2341 2413 2431 3124 3142 3214 3241 3412 3421 4123 4132 4213 4231
> 4312
> > > 4321
> > >
> > >
> > > Something like :
> > >
> > > 1 2 3 4 each perm 4 NB. I know this doesn't work :-)
> > >
> > > Or:
> > >
> > > 1 2 3 4 {."1 each perm 4 NB. This doesn't work either :-)
> > >
> > > 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


Re: [Jprogramming] Variable length permutations

2020-07-17 Thread Skip Cave
Thanks Raul & Bob for the excellent & concise solutions to my problem.
I would like to generalise the verb a bit more to a dyadic verb where the
lengths of the multiple permutations
and the permuted items are the x & y of the dyad are adjustable:

1 2 3  mulperm 2 4 5

2 4 5 24 25 42 45 52 54 245 254 425 452 524 542


1 3  mulperm 2 4 5 2 4 5 245 254 425 452 524 542


Here's as far as I have gotten:

>10#.ea~.(1{.ea n),(2{.ea n),n=.{(]{~[:perm #) 2 4 5

2 4 5 24 25 42 45 52 54 245 254 425 452 524 542


Skip Cave
Cave Consulting LLC


On Fri, Jul 17, 2020 at 4:46 PM Skip Cave  wrote:

> Is there a more efficient and/or concise way to generate this sequence?
>
> 4 16$>10#.each >: each ({1 perm 4),({2 perm 4),({3 perm 4),({4 perm 4)
>
> 1 2 3 4 12 21 13 31 14 41 23 32 24 42 34 43
>
> 123 132 213 231 312 321 124 142 214 241 412 421 134 143 314 341
>
> 413 431 234 243 324 342 423 432 1234 1243 1324 1342 1423 1432 2134 2143
>
> 2314 2341 2413 2431 3124 3142 3214 3241 3412 3421 4123 4132 4213 4231 4312
> 4321
>
>
> Something like :
>
> 1 2 3 4 each perm 4 NB. I know this doesn't work :-)
>
> Or:
>
> 1 2 3 4 {."1 each perm 4 NB. This doesn't work either :-)
>
> Skip Cave
> Cave Consulting LLC
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Variable length permutations

2020-07-17 Thread Skip Cave
Is there a more efficient and/or concise way to generate this sequence?

4 16$>10#.each >: each ({1 perm 4),({2 perm 4),({3 perm 4),({4 perm 4)

1 2 3 4 12 21 13 31 14 41 23 32 24 42 34 43

123 132 213 231 312 321 124 142 214 241 412 421 134 143 314 341

413 431 234 243 324 342 423 432 1234 1243 1324 1342 1423 1432 2134 2143

2314 2341 2413 2431 3124 3142 3214 3241 3412 3421 4123 4132 4213 4231 4312
4321


Something like :

1 2 3 4 each perm 4 NB. I know this doesn't work :-)

Or:

1 2 3 4 {."1 each perm 4 NB. This doesn't work either :-)

Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Boxing Issues

2020-07-13 Thread Skip Cave
Arthur's nobar:
   nobar=: (((1&|.@ (_1 0&,@ (((9{ 9!:6 '')&=@ ({."1))# i.@ #))) {"2 ])@
":)
David's nobar:
nobar1=: ({. , _2 {:\])@:":

Test:

]r=.;/(30?30){?10#10 100 1000

┌───┬─┬──┬─┬───┬───┬───┬──┬─┬───┬──┬─┬─┬──┬───┬───┬──┬─┬───┬───┬─┬──┬──┬──┬───┬─┬──┬─┬─┬─┐

│716│1│53│7│337│488│565│87│8│508│49│3│8│68│978│504│10│4│946│921│9│47│96│13│985│6│59│3│3│2│

└───┴─┴──┴─┴───┴───┴───┴──┴─┴───┴──┴─┴─┴──┴───┴───┴──┴─┴───┴───┴─┴──┴──┴──┴───┴─┴──┴─┴─┴─┘

nobar r

┌───┬─┬──┬─┬───┬───┬───┬──┬─┬───┬──┬─┬─┬──┬───┬───┬──┬─┬───┬───┬─┬──┬──┬──┬───┬─┬──┬─┬─┬─┐

│716│1│53│7│337│488│565│87│8│508│49│3│8│68│978│504│10│4│946│921│9│47│96│13│985│6│59│3│3│2│

└───┴─┴──┴─┴───┴───┴───┴──┴─┴───┴──┴─┴─┴──┴───┴───┴──┴─┴───┴───┴─┴──┴──┴──┴───┴─┴──┴─┴─┴─┘

nobar1 r

┌───┬─┬──┬─┬───┬───┬───┬──┬─┬───┬──┬─┬─┬──┬───┬───┬──┬─┬───┬───┬─┬──┬──┬──┬───┬─┬──┬─┬─┬─┐

│716│1│53│7│337│488│565│87│8│508│49│3│8│68│978│504│10│4│946│921│9│47│96│13│985│6│59│3│3│2│

└───┴─┴──┴─┴───┴───┴───┴──┴─┴───┴──┴─┴─┴──┴───┴───┴──┴─┴───┴───┴─┴──┴──┴──┴───┴─┴──┴─┴─┴─┘


Lots of wrapped horizontal bars & lots of extra vertical spaces caused by
line wrap when copy/paste from JQT.


What about rank 2 arrays?

nobar 3 10$r

┌───┬───┬──┬───┬──┬───┬───┬───┬──┬───┐

│2 │71 │1 │146│87│55 │39 │38 │94│391│

│689│99 │11│6 │64│8 │9 │699│8 │0 │

│82 │172│91│1 │7 │699│773│9 │3 │81 │

└───┴───┴──┴───┴──┴───┴───┴───┴──┴───┘

nobar1 3 10$r

┌───┬───┬──┬───┬──┬───┬───┬───┬──┬───┐

│2 │71 │1 │146│87│55 │39 │38 │94│391│

│689│99 │11│6 │64│8 │9 │699│8 │0 │

│82 │172│91│1 │7 │699│773│9 │3 │81 │

└───┴───┴──┴───┴──┴───┴───┴───┴──┴───┘.


Extra vertical spaces added when I copy/paste from JQT

What I would like (nobar2):


nobar2 r

│716│1│53│7│337│488│565│87│8│508│49│3│8│68│978│504│10│4│946│921│9│47│96│13│985│6│59│3│3│2│


nobar2 3 10$r

│2 │71 │1 │146│87│55 │39 │38 │94│391│

│689│99 │11│6 │64│8 │9 │699│8 │0 │

│82 │172│91│1 │7 │699│773│9 │3 │81 │


or even with no fixed-width characters (Tahoma font) it still isn't bad:

nobar2 3 10$r

│2 │71 │1 │146│87│55 │39 │38 │94│391│

│689│99 │11│6 │64│8 │9 │699│8 │0 │

│82 │172│91│1 │7 │699│773│9 │3 │81 │


So what would the nobar2 verb code look like?



Skip Cave
Cave Consulting LLC


On Mon, Jul 13, 2020 at 10:36 AM David Lambert  wrote:

> nobar simplified?
>
> nobar=: ({. , _2 {:\ ])@:":
>
> |Date: Sun, 12 Jul 2020 16:07:11 -0400
> |From: Arthur Anger 
> |To: programm...@jsoftware.com
> |Subject: Re: [Jprogramming] Boxing Issues
> |Message-ID: 
> |Content-Type: text/plain;charset=us-ascii
> |
> |Skip--
> |For some years,I have been deleting horizontal separators when
> displaying tall arrays.  This verb displays boxed values without
> top-level horizontal separators:
> |
> |nobar=: (((1&|.@ (_1 0&,@ (((9{ 9!:6 '')&=@ ({."1))# i.@ #))) {"2 ])@ ":)
> |
> |You could also provide for deletion of first and last rows.
> |
> |This will not enforce alignment of vertical bars when using
> variable-width characters, nor deal with second-level horizontals which
> would still appear, or take up space if replaced by blanks..
> |--Art
>
> --
> 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] Boxing Issues

2020-07-07 Thread Skip Cave
Thanks Hauke for your reply. That helped me see how to proceed.

I mentioned that it would still be nice to have a simple way to remove the
horizontal and corner box characters for times when presenting J in venues
where fixed-width or unicode fonts are not available.


Here's what i mean:

m=.'abc';'rtyuio';'b';'asdf';'wdrtybji';'ee';'nuko';'n'

Not this:

m

┌───┬──┬─┬┬┬──┬┬─┐

│abc│rtyuio│b│asdf│wdrtybji│ee│nuko│n│

└───┴──┴─┴┴┴──┴┴─┘


But this:

m

│abc│rtyuio│b│asdf│wdrtybji│ee│nuko│n│



Not this:

2 4$m

┌┬──┬┬┐

│abc │rtyuio│b │asdf│

├┼──┼┼┤

│wdrtybji│ee │nuko│n │

└┴──┴┴┘


But this:

2 4$m

│abc│rtyuio│b│asdf│

│wdrtybji│ee│nuko│n│


As a format option.


Skip Cave
Cave Consulting LLC


On Tue, Jul 7, 2020 at 12:44 PM Hauke Rehr  wrote:

> Hi Skip,
>
> this is how I would try to achieve what you’re after
>
> ] suits =: u: 9824 9827 9829 9830
> ♠♣♥♦
> ;/ values =: (3 2 $ ' J Q K') , ": >: i. 10 1
> ┌──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐
> │ J│ Q│ K│ 1│ 2│ 3│ 4│ 5│ 6│ 7│ 8│ 9│10│
> └──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘
> deck =: ,/ values ,"1/ ":"0 suits
> _4 <\ deck
> ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
> │ J♠│ Q♠│ K♠│ 1♠│ 2♠│ 3♠│ 4♠│ 5♠│ 6♠│ 7♠│ 8♠│ 9♠│10♠│
> │ J♣│ Q♣│ K♣│ 1♣│ 2♣│ 3♣│ 4♣│ 5♣│ 6♣│ 7♣│ 8♣│ 9♣│10♣│
> │ J♥│ Q♥│ K♥│ 1♥│ 2♥│ 3♥│ 4♥│ 5♥│ 6♥│ 7♥│ 8♥│ 9♥│10♥│
> │ J♦│ Q♦│ K♦│ 1♦│ 2♦│ 3♦│ 4♦│ 5♦│ 6♦│ 7♦│ 8♦│ 9♦│10♦│
> └───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
>
> deck is pretty much your all in
> 4 13$(52?52){all
> As long as you don’t do any boxing, you won’t
> need to get rid of boxing characters.
> You can always insert | characters manually, though.
> If you feel like they make the dealt hands more readable.
>
> Am 07.07.20 um 18:45 schrieb Skip Cave:
> > The four suit symbols I was using were from a. 3 4 5 6{a.
> >
> > These symbols are not the same width as the character symbols in a. so
> they
> > mess up the boxing characters.
> >
> > ;/3 4 5 6{a.
> >
> > (My email fonts don't have the a. symbols)
> >
> > ┌─┬─┬─┬─┐
> >
> > │ │ │ │ │
> >
> > └─┴─┴─┴─┘
> >
> > I discovered that the unicode suit symbols u: 9824 9827 9829 9830
> >
> > are smaller, and seem to have the standard width:
> >
> > ;/u:9824 9827 9829 9830
> >
> > ┌─┬─┬─┬─┐
> >
> > │♠│♣│♥│♦│
> >
> > └─┴─┴─┴─┘
> >
> > So that solves the width problem when boxing.
> >
> >
> > The other issue I had with seemingly random spaces in the cards in a
> random
> > deal was caused by my four 10 cards (10 of spades, hearts. etc) having
> > three characters instead of two. J cleverly distributes spaces across
> each
> > boxes' content to make the boxes align. However, the seemingly random
> > distribution of spaces confused my diagnosis.
> >
> > J distributes spaces across all the cells to make the boxes align for
> > variable width contents. This exacerbates the issue with the non-standard
> > widths of the a. font. However, the fixed-width unicode symbols
> eliminates
> > the issue, though it might be better if the spaces were inserted before
> or
> > after the characters, rather than placed in the middle.
> >
> >
> > 4 13$(52?52){all
> >
> > ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
> >
> > │10♠│9 ♣│K ♥│3 ♣│J ♦│4 ♠│4 ♦│2 ♠│6 ♥│3 ♠│K ♦│Q ♥│J ♣│
> >
> > ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
> >
> > │5 ♥│5 ♠│9 ♥│Q ♠│7 ♦│5 ♣│3 ♥│10♦│8 ♦│J ♥│4 ♣│9 ♦│6 ♣│
> >
> > ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
> >
> > │8 ♣│J ♠│A ♣│7 ♣│Q ♦│6 ♦│10♣│K ♣│A ♥│2 ♥│A ♠│4 ♥│9 ♠│
> >
> > ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
> >
> > │7 ♠│3 ♦│5 ♦│Q ♣│8 ♥│2 ♦│10♥│A ♦│K ♠│7 ♥│2 ♣│8 ♠│6 ♠│
> >
> > └───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
> >
> > It would probably be better for me to use the character 'T' instead of
> 10,
> > so all the cards would have two characters.
> >
> >
> > Finally, it would still be nice to have a simple way to remove the
> > horizontal and corner box characters for times when presenting J in
> venues
> > where fixed-width or unicode fonts are not available.
> >
> >
> > Skip Cave
> >
> > On Tue, Jul 7, 2020 at 10:20 AM Raul Miller 
> wrote:
> >
> >> If the fixed width font has variable width characters, that's not a
> >> bug in J, that's a problem with the font.
> >>
> >> One approach would be to rebu

Re: [Jprogramming] Boxing Issues

2020-07-07 Thread Skip Cave
The four suit symbols I was using were from a. 3 4 5 6{a.

These symbols are not the same width as the character symbols in a. so they
mess up the boxing characters.

;/3 4 5 6{a.

(My email fonts don't have the a. symbols)

┌─┬─┬─┬─┐

│ │ │ │ │

└─┴─┴─┴─┘

I discovered that the unicode suit symbols u: 9824 9827 9829 9830

are smaller, and seem to have the standard width:

;/u:9824 9827 9829 9830

┌─┬─┬─┬─┐

│♠│♣│♥│♦│

└─┴─┴─┴─┘

So that solves the width problem when boxing.


The other issue I had with seemingly random spaces in the cards in a random
deal was caused by my four 10 cards (10 of spades, hearts. etc) having
three characters instead of two. J cleverly distributes spaces across each
boxes' content to make the boxes align. However, the seemingly random
distribution of spaces confused my diagnosis.

J distributes spaces across all the cells to make the boxes align for
variable width contents. This exacerbates the issue with the non-standard
widths of the a. font. However, the fixed-width unicode symbols eliminates
the issue, though it might be better if the spaces were inserted before or
after the characters, rather than placed in the middle.


4 13$(52?52){all

┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐

│10♠│9 ♣│K ♥│3 ♣│J ♦│4 ♠│4 ♦│2 ♠│6 ♥│3 ♠│K ♦│Q ♥│J ♣│

├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤

│5 ♥│5 ♠│9 ♥│Q ♠│7 ♦│5 ♣│3 ♥│10♦│8 ♦│J ♥│4 ♣│9 ♦│6 ♣│

├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤

│8 ♣│J ♠│A ♣│7 ♣│Q ♦│6 ♦│10♣│K ♣│A ♥│2 ♥│A ♠│4 ♥│9 ♠│

├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤

│7 ♠│3 ♦│5 ♦│Q ♣│8 ♥│2 ♦│10♥│A ♦│K ♠│7 ♥│2 ♣│8 ♠│6 ♠│

└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘

It would probably be better for me to use the character 'T' instead of 10,
so all the cards would have two characters.


Finally, it would still be nice to have a simple way to remove the
horizontal and corner box characters for times when presenting J in venues
where fixed-width or unicode fonts are not available.


Skip Cave

On Tue, Jul 7, 2020 at 10:20 AM Raul Miller  wrote:

> If the fixed width font has variable width characters, that's not a
> bug in J, that's a problem with the font.
>
> One approach would be to rebuild the font's characters, enforcing a
> fixed width format. Doing this requires access to either suitable
> tools, or sufficient documentation on the font's data structures so
> that you can build your own tools.
>
> --
> Raul
>
> On Tue, Jul 7, 2020 at 11:10 AM Skip Cave  wrote:
> >
> > When working in JQT with some of the non-standard-width characters in a.,
> > the boxing formatting is incorrect.
> > Here's a link to a screenshot (.png) of my code in JQT attempting to
> create
> > all the 13 playing cards in 4 suits. https://bit.ly/2BD6LEQ
> >
> >
> > As you can see, the horizontal boxing characters are incorrect, and don't
> > adjust for the wider characters, even though I'm using a fixed-width
> font.
> >
> > In the second part of the example, I randomly deal 4 hands from the deck
> > labeled 'all'.
> >
> > At this point, we have 4 hands of 13 cards, but there are random spaces
> > scattered in the boxed cards.
> >
> > Something went wrong, adding spaces after the random deal.
> >
> > In the third part, I remove all the horizontal boxing, making the display
> > look much neater, but the extra spaces are even more visible.
> >
> >
> > Two issues:
> >
> > 1. Something is inserting random spaces when randomly selecting boxed
> items.
> >
> > 2. It would be nice to have the boxing auto-adjust for variable width
> > characters. If that isn't possible, it would be useful to have a boxing
> > format option to remove horizontal boxing & corner characters for
> > environments that don't have fixed-with fonts, that use
> non-standard-width
> > characters, or that force double-spaced lines (Quora). After posting J
> > problems and solutions in various venues, it turns out that the vertical
> > bar (│) without horizontal bars or corners, is quite enough to clearly
> > delineate separate items in most cases.
> >
> >
> >
> > 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


[Jprogramming] Boxing Issues

2020-07-07 Thread Skip Cave
When working in JQT with some of the non-standard-width characters in a.,
the boxing formatting is incorrect.
Here's a link to a screenshot (.png) of my code in JQT attempting to create
all the 13 playing cards in 4 suits. https://bit.ly/2BD6LEQ


As you can see, the horizontal boxing characters are incorrect, and don't
adjust for the wider characters, even though I'm using a fixed-width font.

In the second part of the example, I randomly deal 4 hands from the deck
labeled 'all'.

At this point, we have 4 hands of 13 cards, but there are random spaces
scattered in the boxed cards.

Something went wrong, adding spaces after the random deal.

In the third part, I remove all the horizontal boxing, making the display
look much neater, but the extra spaces are even more visible.


Two issues:

1. Something is inserting random spaces when randomly selecting boxed items.

2. It would be nice to have the boxing auto-adjust for variable width
characters. If that isn't possible, it would be useful to have a boxing
format option to remove horizontal boxing & corner characters for
environments that don't have fixed-with fonts, that use non-standard-width
characters, or that force double-spaced lines (Quora). After posting J
problems and solutions in various venues, it turns out that the vertical
bar (│) without horizontal bars or corners, is quite enough to clearly
delineate separate items in most cases.



Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Generating multiple length vectors from a single vector

2020-06-23 Thread Skip Cave
Box infix. Doh! I should have known.
I'm so used to using infix for sliding windows:


3,\1 2 3 4 5 6

1 2 3

2 3 4

3 4 5

4 5 6


I forgot infix's other property using a verb left argument, instead of a
noun.


Thanks to Bob & Hauke for reminding me.


Skip



On Tue, Jun 23, 2020 at 7:05 PM Hauke Rehr  wrote:

> But this does:
>
> tt =: 3 : 0
> <\ y
> :
> (<: x) { <\ y
> )
>
> tt >: i.6
> ┌─┬───┬─┬───┬─┬───┐
> │1│1 2│1 2 3│1 2 3 4│1 2 3 4 5│1 2 3 4 5 6│
> └─┴───┴─┴───┴─┴───┘
> 2 4 5 tt >: i.6
> ┌───┬───┬─┐
> │1 2│1 2 3 4│1 2 3 4 5│
> └───┴───┴─┘
> tt"1 n
> ┌─┬───┬─┐
> │1│1 2│1 2 3│
> ├─┼───┼─┤
> │1│1 3│1 3 2│
> ├─┼───┼─┤
> │2│2 1│2 1 3│
> ├─┼───┼─┤
> │2│2 3│2 3 1│
> ├─┼───┼─┤
> │3│3 1│3 1 2│
> ├─┼───┼─┤
> │3│3 2│3 2 1│
> └─┴───┴─┘
>
>
> Am 24.06.20 um 01:58 schrieb 'robert therriault' via Programming:
> > Hey Skip,
> >
> > f =. <\
> >
> > should work if you are willing to do f"1
> >
> > or f1=. <\"1 if you want to lock in the rank.
> >
> > Is that what you are looking for?
> >
> > Cheers, bob
> >
> >> On Jun 23, 2020, at 16:50, Skip Cave  wrote:
> >>
> >> ]n=.>:perm 3
> >
> > --
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
>
> --
> --
> mail written using NEO
> neo-layout.org
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Generating multiple length vectors from a single vector

2020-06-23 Thread Skip Cave
I want to generate all-length subsets of a vector, always starting from the
left-most integer:

We need to define a verb f, that does the following:

f 1 2 3 4 5 6

┌─┬───┬─┬───┬─┬───┐

│1│1 2│1 2 3│1 2 3 4│1 2 3 4 5│1 2 3 4 5 6│

└─┴───┴─┴───┴─┴───┘

It would be handy if it took a left argument as an option (partition count
for each partition), but that's not critical if that is too complex,

2 4 5 f 1 2 3 4 5 6

┌───┬───┬─┐

│1 2│1 2 3 4│1 2 3 4 5│

└───┴───┴─┘

More importantly, f needs to work on rank 2 arrays:

]n=.>:perm 3

1 2 3

1 3 2

2 1 3

2 3 1

3 1 2

3 2 1


f"1 n

┌─┬───┬─┐

│1│1 2│1 2 3│

├─┼───┼─┤

│1│1 3│1 3 2│

├─┼───┼─┤

│2│2 1│2 1 3│

├─┼───┼─┤

│2│2 3│2 3 1│

├─┼───┼─┤

│3│3 1│3 1 2│

├─┼───┼─┤

│3│3 2│3 2 1│

└─┴───┴─┘

I know I can do this by brute force:


Build dyadic verb t that takes the first x elements from y & boxes them:

t=.4 :'x {."1 ea {y'


(1 t n),.(2 t n),.(3 t n)

┌─┬───┬─┐

│1│1 2│1 2 3│

├─┼───┼─┤

│1│1 3│1 3 2│

├─┼───┼─┤

│2│2 1│2 1 3│

├─┼───┼─┤

│2│2 3│2 3 1│

├─┼───┼─┤

│3│3 1│3 1 2│

├─┼───┼─┤

│3│3 2│3 2 1│

└─┴───┴─┘

Is there a more elegant (and efficient) way to do this?


Skip

Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Reshape error?

2020-05-29 Thread Skip Cave
Wow! Thanks to Michael, Stefan, and Henry for the various solutions to my
tiling problem.
Henry's explanation using tetrahedral numbers was quite interesting, and
was easier for me to parse.
I'm still not very good at unravelling lengthy tacit code, and Henry's
extensive comments
made his process very clear.

Skip


Skip Cave
Cave Consulting LLC


On Thu, May 28, 2020 at 12:43 PM Henry Rich  wrote:

> I put 2 lines of commentary for every line of J I write.  I should do
> the same in posts to the Forum.  Here's my solution:
>
> NB. tetrahedral number y in x dimensions (generalization of triangle
> numbers)
> tetra =: ([ ! <:@:+)
>
> NB. number of ways to position y intervals of length 2 in length x
> NB. Think of it as deciding how many spaces to leave in front of each
> tile (could be 0).
> NB. This is equivalent to finding the number of ways to select y
> nonnegative
> NB. integers that add up to no more than (y-2x), which is the same as the
> NB. number of ways to select up to y positive integers that add to no
> more than (y-2x+1),
> NB. which is a tetrahedral number of dimension y.
> nhoriz =: ] tetra >:@:(- +:)
>
> NB. number of ways to position y tiles vertically.  Each has 2 positions.
> nvert =: 2&^
>
> NB. number of ways to place y tiles in a 3-by-x grid.  The dimensions
> are independent.
> npos =: nvert@] * nhoriz
>
> NB. number of ways to place up to y tiles in a 3-by-x grid.  Add up for
> each number
> NB. of tiles.  0 is a possible number, meaning all 1x1s were used.
> totalpos =: +/ @: (npos i.@>:)
>
> 8 totalpos 4
> 171
> 12 totalpos 4
> 1995
> 12 totalpos 6
> 2731
>
> Henry Rich
>
> On 5/28/2020 12:44 PM, 'Michael Day' via Programming wrote:
> > Thanks - and Thank Goodness you arrive at the same result, for 3x8!
> >
> > I considered programming the cases for 1 and 2 2-tiles,  but also
> > considered the
> >
> > mini-essay sufficient to demonstrate them for Skip!
> >
> > Cheers,
> >
> > Mike
> >
> >
> >
> > On 28/05/2020 11:14, Stefan Baumann wrote:
> >> Trying to directly calculate the number of solutions and ending up up
> >> with
> >> this - x length of grid, y number of 2-tiles:
> >>
> >> n=: 4 : '(2^y)* # ([: ~.@,/ [: |:"2 +"_ 1)/ (] $~ (x-2*y),#) e.@i. >:
> y'
> >>
> >>
> >> Starts with an identity matrix corresponding to the possible gaps
> >> next to
> >> the 2-tiles and tries to find the number of ways filling the gaps with
> >> 1-tile columns.
> >>
> >> It doesn't work for when the 2 tiles span all the columns so to get your
> >> result you have to:
> >>
> >>
> >> (2&^ + [: +/ (8"0)@i.) 4
> >>
> >> 171
> >>
> >> Ciao. Stefan.
> >>
> >> On Wed, May 27, 2020 at 12:57 PM 'Michael Day' via Programming <
> >> programm...@jsoftware.com> wrote:
> >>
> >>> Another "oops" - main analysis is ok below - I'll correct a few entries
> >>> in line
> >>>
> >>>
> >>> On 27/05/2020 08:13, 'Michael Day' via Programming wrote:
> >>>> OK, thanks - more interesting!
> >>>>
> >>>> So youcan regard this as 5 sub-problems - ie using 0 1 2 3 or 4 2x2s.
> >>>> It's not quite clear
> >>>>
> >>>> whether you need to identify the different tiles or not, eg by colour
> >>>> or name or number.
> >>>>
> >>>> If you don't need to do so,  then sub-problems 0 and 4 are still
> >>>> trivial.
> >>>>
> >>>> 0 - fill all 24 slots with 1x1s
> >>> ===> 1 solution for 0 2x2s
> >>>> 4 - use 4 2x2s and 8 1x1s, as in my graphic, earlier, with 4 "[]"
> >>>> symbols,  and 8 "."s
> >>>> The other 3 cases are somewhat more complicated,  but I think it's
> >>>> still a matter of
> >>>>
> >>>> placing the 2x2s and regarding the 1x1s as space-fillers.
> >>>>
> >>>> [As for the other 3: ]
> >>>>
> >>>> In a 3 x w grid,  there are  2 x (w-1) placings for just 1 2x2 tile:
> >>>>
> >>>> 1 - there are 14 = 2x7 possible locations for 1 2x2 tile
> >>>>
> >>>> 2 - If the first 2x2 tile is in columns 0 1,  there are 10=2x5
> >>>> placings for the 2nd 2x2,
> >>>>
> >>>>  so 20 = 2x2x5 for both,
> >>>>
> >

Re: [Jprogramming] Reshape error?

2020-05-26 Thread Skip Cave
Actually the tiling problem I was working on is more complex than my basic
explanation.
You have a large pile of 1x1 tiles and a pile of 2x2 tiles, as many as you
need. The question is:
How many ways are there to tile a 3x8 grid completely, using 1x1 & 2x2
tiles.
Of course, you can cover the whole grid with 24-1x1 tiles, which is one way
to tile the grid.
The most 2x2s you can get in the grid will be 4, but then you must fill up
the remaining holes with 8-1x1s
However, there are several ways to arrange the 4-2x2s, along with the
8-1x1s.
If you only use 1, 2, or 3 of the 4x4s, the number of tiling possibilities
goes up dramatically.
The answer is a count of all the ways. That is the problem.

Skip



On Tue, May 26, 2020 at 5:58 PM 'Michael Day' via Programming <
programm...@jsoftware.com> wrote:

> In that case,  it seems a bit of over-kill to use 2^24,
>
> In your 3x8 grid,  you can fit exactly 4 2x2 tiles in a row.
>
> (It's surely equivalent to placing 4 2x1 tiles in a 3x4 grid.)
>
> To make the graphics easier, I'll consider 4 1x2 tiles in a vertical 4x3
> grid.
>
> Each tile "[]" can then be "left" or "right",  so there are 2^4
> patterns: (best in fixed width!)
>
> [m =: 4#,:'.[]' NB. Each tile is [],  spaces are 
> .[]
> .[]
> .[]
> .[]
>
> 0 1 0 1 |."0 1 m  NB. two patterns out of the 16
> .[]
> [].
> .[]
> [].
> 0 1 1 1 |."0 1 m
> .[]
> [].
> [].
> [].
>
> So #: i. 16 will generate all patterns.
>
> Or have I missed something?
>
> Mike
>
>
> On 26/05/2020 22:14, Skip Cave wrote:
> > Ooops. You are right. I mis-copied the last dimension. :-(
> > Sorry for the confusion.
> >
> > The problem I was working on, was to try to find all the ways to place
> 2"x
> > 2" tiles non-overlapping on a 3"x 8" grid.
> > I know there's a technique called linear difference equations that can
> > solve this problem, but I wanted to try to
> > model it by brute force. So I generated all 16777216 possible 3x8 grids
> of
> > 1s & 0s.
> >
> > odo=:#: i.@(*/)
> >
> > $n=.odo 24#2
> >
> > 16777216 24
> >
> > $ns=.16777216 3 8$,n
> >
> > 16777216 3 8
> >
> > _3{.ns
> >
> > 1 1 1 1 1 1 1 1
> >
> > 1 1 1 1 1 1 1 1
> >
> > 1 1 1 1 1 1 0 1
> >
> >
> > 1 1 1 1 1 1 1 1
> >
> > 1 1 1 1 1 1 1 1
> >
> > 1 1 1 1 1 1 1 0
> >
> >
> > 1 1 1 1 1 1 1 1
> >
> > 1 1 1 1 1 1 1 1
> >
> > 1 1 1 1 1 1 1 1
> >
> > That fixed my problem, with the right dimensions. Now comes the hard
> part.
> > The problem now is to find all the 3x8 grids that only
> >
> > have 2x2 blocks of non-overlapping 1s in them, and no isolated 1s or
> > non-2x2 groups of 1s.
> >
> > Skip
> >
> >
> > On Tue, May 26, 2020 at 12:34 PM Skip Cave 
> wrote:
> >
> >> odo=:#: i.@(*/)
> >>
> >> $n=.odo 24#2
> >>
> >> 16777216 24
> >>
> >> _3{. n
> >>
> >> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1
> >>
> >> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
> >>
> >> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> >>
> >> _48{. ,n
> >>
> >> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1
> 1
> >> 1 1 1 1 1 1 1 1 1 1 1
> >>
> >> $ns=.16777224 3 8$,n
> >>
> >> 16777224 3 8
> >>
> >> _3{.ns
> >>
> >> 0 0 0 0 0 0 0 0
> >>
> >> 0 0 0 0 0 0 0 0
> >>
> >> 0 0 0 0 0 1 0 1
> >>
> >>
> >> 0 0 0 0 0 0 0 0
> >>
> >> 0 0 0 0 0 0 0 0
> >>
> >> 0 0 0 0 0 1 1 0
> >>
> >>
> >> 0 0 0 0 0 0 0 0
> >>
> >> 0 0 0 0 0 0 0 0
> >>
> >> 0 0 0 0 0 1 1 1
> >>
> >>
> >> Shouldn't the last few 3x8 arrays in ns be almost all ones, and the last
> >> array definitely all ones?
> >>
> >>
> >>
> >> Skip Cave
> >> Cave Consulting LLC
> >>
> > --
> > 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


Re: [Jprogramming] Reshape error?

2020-05-26 Thread Skip Cave
Ooops. You are right. I mis-copied the last dimension. :-(
Sorry for the confusion.

The problem I was working on, was to try to find all the ways to place 2"x
2" tiles non-overlapping on a 3"x 8" grid.
I know there's a technique called linear difference equations that can
solve this problem, but I wanted to try to
model it by brute force. So I generated all 16777216 possible 3x8 grids of
1s & 0s.

odo=:#: i.@(*/)

$n=.odo 24#2

16777216 24

$ns=.16777216 3 8$,n

16777216 3 8

_3{.ns

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 0 1


1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 0


1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

That fixed my problem, with the right dimensions. Now comes the hard part.
The problem now is to find all the 3x8 grids that only

have 2x2 blocks of non-overlapping 1s in them, and no isolated 1s or
non-2x2 groups of 1s.

Skip


On Tue, May 26, 2020 at 12:34 PM Skip Cave  wrote:

> odo=:#: i.@(*/)
>
> $n=.odo 24#2
>
> 16777216 24
>
> _3{. n
>
> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1
>
> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
>
> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
>
> _48{. ,n
>
> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1
> 1 1 1 1 1 1 1 1 1 1 1
>
> $ns=.16777224 3 8$,n
>
> 16777224 3 8
>
> _3{.ns
>
> 0 0 0 0 0 0 0 0
>
> 0 0 0 0 0 0 0 0
>
> 0 0 0 0 0 1 0 1
>
>
> 0 0 0 0 0 0 0 0
>
> 0 0 0 0 0 0 0 0
>
> 0 0 0 0 0 1 1 0
>
>
> 0 0 0 0 0 0 0 0
>
> 0 0 0 0 0 0 0 0
>
> 0 0 0 0 0 1 1 1
>
>
> Shouldn't the last few 3x8 arrays in ns be almost all ones, and the last
> array definitely all ones?
>
>
>
> Skip Cave
> Cave Consulting LLC
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Reshape error?

2020-05-26 Thread Skip Cave
odo=:#: i.@(*/)

$n=.odo 24#2

16777216 24

_3{. n

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

_48{. ,n

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1

$ns=.16777224 3 8$,n

16777224 3 8

_3{.ns

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 1 0 1


0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 1 1 0


0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 1 1 1


Shouldn't the last few 3x8 arrays in ns be almost all ones, and the last
array definitely all ones?



Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] restricting permutations

2020-05-25 Thread Skip Cave
The perm in the addon library is dyadic:

2 perm 4

0 1

1 0

0 2

2 0

0 3

3 0

1 2

2 1

1 3

3 1

2 3

3 2

Skip Cave
Cave Consulting LLC


On Mon, May 25, 2020 at 4:23 PM Skip Cave  wrote:

> Actually you can just say load 'stats' and get perm, comb, and much more.
>
> When I do a Google search on: site:jsoftware.com perm
> I get: https://code.jsoftware.com/wiki/Addons/stats/base/sampledesign
>
>
> Skip Cave
> Cave Consulting LLC
>
>
> On Mon, May 25, 2020 at 4:05 PM Ric Sherlock  wrote:
>
>> Skip, that seems like a very old version of the stats/base addon?
>> According to GitHub the sampledesign script was renamed to combinatorial
>> back in 2008.
>> perm is currently available in ~addons/stats/base/combinatorial.ijs
>> (stats/base/combinatorial)
>>
>> On Tue, May 26, 2020 at 8:45 AM Skip Cave 
>> wrote:
>>
>> > Perm is in Addons/stats/base/sampledesign.
>> >
>> > perm
>> >
>> > 3 : 0
>> >
>> > z=. i.1 0
>> >
>> > for. i.y do. z=. ,/ (0 ,. 1 + z) {"2 1 \:"1 = i. 1 + {: $z end.
>> >
>> > :
>> >
>> > ,/ ({~ perm@#)"1 x comb y
>> >
>> > )
>> >
>> >
>> >
>> > Skip Cave
>> > Cave Consulting LLC
>> >
>> >
>> > On Mon, May 25, 2020 at 3:23 PM Brian Schott 
>> > wrote:
>> >
>> > > Skip,
>> > > I am having trouble finding perm.
>> > > I tried using A. in its place, but did not succeed.
>> > > But I think I see where you were going. Good idea.
>> > >
>> > > On Mon, May 25, 2020 at 2:54 PM Skip Cave 
>> > wrote:
>> > >
>> > > > ssmb=:+./@E.
>> > > >
>> > > > l21=.-.1 1 ssmb"1+./"2]1 2=/"1 n=.perm 4
>> > > >
>> > > > l30=.-.1 1 ssmb"1+./"2]0 3=/"1 n
>> > > >
>> > > > n#~l30*.l21
>> > > >
>> > > >
>> > > --
>> > > 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] restricting permutations

2020-05-25 Thread Skip Cave
Actually you can just say load 'stats' and get perm, comb, and much more.

When I do a Google search on: site:jsoftware.com perm
I get: https://code.jsoftware.com/wiki/Addons/stats/base/sampledesign


Skip Cave
Cave Consulting LLC


On Mon, May 25, 2020 at 4:05 PM Ric Sherlock  wrote:

> Skip, that seems like a very old version of the stats/base addon?
> According to GitHub the sampledesign script was renamed to combinatorial
> back in 2008.
> perm is currently available in ~addons/stats/base/combinatorial.ijs
> (stats/base/combinatorial)
>
> On Tue, May 26, 2020 at 8:45 AM Skip Cave  wrote:
>
> > Perm is in Addons/stats/base/sampledesign.
> >
> > perm
> >
> > 3 : 0
> >
> > z=. i.1 0
> >
> > for. i.y do. z=. ,/ (0 ,. 1 + z) {"2 1 \:"1 = i. 1 + {: $z end.
> >
> > :
> >
> > ,/ ({~ perm@#)"1 x comb y
> >
> > )
> >
> >
> >
> > Skip Cave
> > Cave Consulting LLC
> >
> >
> > On Mon, May 25, 2020 at 3:23 PM Brian Schott 
> > wrote:
> >
> > > Skip,
> > > I am having trouble finding perm.
> > > I tried using A. in its place, but did not succeed.
> > > But I think I see where you were going. Good idea.
> > >
> > > On Mon, May 25, 2020 at 2:54 PM Skip Cave 
> > wrote:
> > >
> > > > ssmb=:+./@E.
> > > >
> > > > l21=.-.1 1 ssmb"1+./"2]1 2=/"1 n=.perm 4
> > > >
> > > > l30=.-.1 1 ssmb"1+./"2]0 3=/"1 n
> > > >
> > > > n#~l30*.l21
> > > >
> > > >
> > > --
> > > 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] restricting permutations

2020-05-25 Thread Skip Cave
Perm is in Addons/stats/base/sampledesign.

perm

3 : 0

z=. i.1 0

for. i.y do. z=. ,/ (0 ,. 1 + z) {"2 1 \:"1 = i. 1 + {: $z end.

:

,/ ({~ perm@#)"1 x comb y

)



Skip Cave
Cave Consulting LLC


On Mon, May 25, 2020 at 3:23 PM Brian Schott  wrote:

> Skip,
> I am having trouble finding perm.
> I tried using A. in its place, but did not succeed.
> But I think I see where you were going. Good idea.
>
> On Mon, May 25, 2020 at 2:54 PM Skip Cave  wrote:
>
> > ssmb=:+./@E.
> >
> > l21=.-.1 1 ssmb"1+./"2]1 2=/"1 n=.perm 4
> >
> > l30=.-.1 1 ssmb"1+./"2]0 3=/"1 n
> >
> > n#~l30*.l21
> >
> >
> --
> 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] restricting permutations

2020-05-25 Thread Skip Cave
ssmb=:+./@E.

l21=.-.1 1 ssmb"1+./"2]1 2=/"1 n=.perm 4

l30=.-.1 1 ssmb"1+./"2]0 3=/"1 n

n#~l30*.l21

0 1 3 2

0 2 3 1

1 0 2 3

1 3 2 0

2 0 1 3

2 3 1 0

3 1 0 2

3 2 0 1


Skip Cave
Cave Consulting LLC


On Mon, May 25, 2020 at 6:48 AM Brian Schott  wrote:

> I want all permutations of  i. 4 for which 0 and 3 cannot be adjacent, nor
> can 1 and 2. My idea is to create a as follows to describe my situation.
>
>]a =. 0 1 1 0,:i. 4
>
> 0 1 1 0
>
> 0 1 2 3
>
>
> Next I created b and rotations on b to list the possibilities I can think
> of. So I can think of 6 permutations. Are there more and is there a better
> way to generate the real qualifying permutations?
>]b =. 0 1 3 2 ,:1 0 2 3
> 0 1 3 2
> 1 0 2 3
>1|."1 b
> 1 3 2 0
> 0 2 3 1
>_1|."1 b
> 2 0 1 3
> 3 1 0 2
> --
> (B=)
> --
> 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] How to convert list of phrases to list of boxed phrases?

2020-05-20 Thread Skip Cave
Rob,

Another way to solve the same house number problem is the odometer verb:

odo =:#:i.@(*/)

3 9${3+odo 3#3

┌─┬─┬─┬─┬─┬─┬─┬─┬─┐

│3 3 3│3 3 4│3 3 5│3 4 3│3 4 4│3 4 5│3 5 3│3 5 4│3 5 5│

├─┼─┼─┼─┼─┼─┼─┼─┼─┤

│4 3 3│4 3 4│4 3 5│4 4 3│4 4 4│4 4 5│4 5 3│4 5 4│4 5 5│

├─┼─┼─┼─┼─┼─┼─┼─┼─┤

│5 3 3│5 3 4│5 3 5│5 4 3│5 4 4│5 4 5│5 5 3│5 5 4│5 5 5│

└─┴─┴─┴─┴─┴─┴─┴─┴─┘


or,

3 9${(odo 3#3){3 4 5

┌─┬─┬─┬─┬─┬─┬─┬─┬─┐

│3 3 3│3 3 4│3 3 5│3 4 3│3 4 4│3 4 5│3 5 3│3 5 4│3 5 5│

├─┼─┼─┼─┼─┼─┼─┼─┼─┤

│4 3 3│4 3 4│4 3 5│4 4 3│4 4 4│4 4 5│4 5 3│4 5 4│4 5 5│

├─┼─┼─┼─┼─┼─┼─┼─┼─┤

│5 3 3│5 3 4│5 3 5│5 4 3│5 4 4│5 4 5│5 5 3│5 5 4│5 5 5│

└─┴─┴─┴─┴─┴─┴─┴─┴─┘



Skip Cave
Cave Consulting LLC


On Wed, May 20, 2020 at 1:30 AM 'Rob Hodgkinson' via Programming <
programm...@jsoftware.com> wrote:

> Skip, I was asked this just the other day by my son in Primary Math, it is
> a beautiful solution for this (common) math question.
>
> “How many different 3 digit house numbers can you produce if the hardware
> shop has no other supplies than unlimited quantities of 3’s, 4’s and 5’s
> and what are those numbers”
>
> A math/statistics person says “1st number any of 3 4 5, 2nd number any of
> 3 4 5, 3rd number any of 3 4 5” so there are 3 x 3 x 3 (or 27) house
> numbers.
>
> But to produce the list, the beauty of “catalogue” (as its name implies)
> is a very elegant solution to these types of problems.
>
>{ 3 4 5;3 4 5;3 4 5
> ┌─┬─┬─┐
> │3 3 3│3 3 4│3 3 5│
> ├─┼─┼─┤
> │3 4 3│3 4 4│3 4 5│
> ├─┼─┼─┤
> │3 5 3│3 5 4│3 5 5│
> └─┴─┴─┘
>
> ┌─┬─┬─┐
> │4 3 3│4 3 4│4 3 5│
> ├─┼─┼─┤
> │4 4 3│4 4 4│4 4 5│
> ├─┼─┼─┤
> │4 5 3│4 5 4│4 5 5│
> └─┴─┴─┘
>
> ┌─┬─┬─┐
> │5 3 3│5 3 4│5 3 5│
> ├─┼─┼─┤
> │5 4 3│5 4 4│5 4 5│
> ├─┼─┼─┤
> │5 5 3│5 5 4│5 5 5│
> └─┴─┴─┘
>
>$,{ 3 4 5;3 4 5;3 4 5
> 27
>
> > On 20 May 2020, at 4:08 pm, Skip Cave  wrote:
> >
> > Harvey,
> >
> > ...
> > If not, you get a very different result:
> >
> > 1 2 3;4 5 6;7 8 9
> >
> > ┌─┬─┬─┐
> >
> > │1 2 3│4 5 6│7 8 9│
> >
> > └─┴─┴─┘
> >
> > {1 2 3;4 5 6;7 8 9
> >
> > ┌─┬─┬─┐
> >
> > │1 4 7│1 4 8│1 4 9│
> >
> > ├─┼─┼─┤
> >
> > │1 5 7│1 5 8│1 5 9│
> >
> > ├─┼─┼─┤
> >
> > │1 6 7│1 6 8│1 6 9│
> >
> > └─┴─┴─┘
> >
> >
> > ┌─┬─┬─┐
> >
> > │2 4 7│2 4 8│2 4 9│
> >
> > ├─┼─┼─┤
> >
> > │2 5 7│2 5 8│2 5 9│
> >
> > ├─┼─┼─┤
> >
> > │2 6 7│2 6 8│2 6 9│
> >
> > └─┴─┴─┘
> >
> > ┌─┬─┬─┐
> >
> > │3 4 7│3 4 8│3 4 9│
> >
> > ├─┼─┼─┤
> >
> > │3 5 7│3 5 8│3 5 9│
> >
> > ├─┼─┼─┤
> >
> > │3 6 7│3 6 8│3 6 9│
> >
> > └─┴─┴─┘
> >
> >
> > Skip Cave
> > Consulting LLC
> >
> >
> > On Mon, May 18, 2020 at 3:38 AM HH PackRat  wrote:
> >
> >> On 5/17/20, HH PackRat  wrote:
> >>> I need to convert the following list of 5 (in reality, far more)
> >>> 11-character dates: ...
> >>> to a list of 5 boxed dates: ...
> >>
> >> Many THANK YOU's to those who responded!  As usual with J, there's
> >> often more than one way to accomplish something--in this case, 5
> >> completely different ways that I can choose to add to my personal J
> >> vocabulary.
> >>
> >> The shortest was Skip Cave's response, but, Skip, I have a question
> >> about how/why yours works.  When I read the Vocabulary and NuVoc to
> >> see how and why this works, I could not figure out how I would even
> >> think to use "{" (catalogue) based on the information in those two
> >> sources.  The NuVoc definition/description is "Combines ITEMS from the
> >> ATOMS inside a BOXED LIST to form a catalogue."  My original list was
> >> NOT boxed, so that description would automatically dismiss my example
> >> from using "{".  Can you please clarify why "{" can be used to box an
> >> unboxed list?
> >

Re: [Jprogramming] How to convert list of phrases to list of boxed phrases?

2020-05-20 Thread Skip Cave
Harvey,

I will have to admit, I stumbled on the effect of { (catalogue) on rank 2
arrays by accident.
I was looking for ways to box the rows in a 2-d matrix, and just tried { to
see what happens
since I knew it would box a single vector.

{1 2 3 4 5 6

┌───┐

│1 2 3 4 5 6│

└───┘


Then I tried a rank 2 array:

3,\1 2 3 4 5 6

1 2 3

2 3 4

3 4 5

4 5 6

{3,\1 2 3 4 5 6

┌─┬─┬─┬─┐

│1 2 3│2 3 4│3 4 5│4 5 6│

└─┴─┴─┴─┘


Then a rank 3 array:

i.3 3 3

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

{i.3 3 3

┌┬┬┐

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

└┴┴┘

I use this quite a lot. The Vocabulary probably needs to at least

show an example of this kind of use of catalogue, as it often

comes in quite handy.


The key issue is that the arrays must be unboxed to start with.

If not, you get a very different result:

1 2 3;4 5 6;7 8 9

┌─┬─┬─┐

│1 2 3│4 5 6│7 8 9│

└─┴─┴─┘

{1 2 3;4 5 6;7 8 9

┌─┬─┬─┐

│1 4 7│1 4 8│1 4 9│

├─┼─┼─┤

│1 5 7│1 5 8│1 5 9│

├─┼─┼─┤

│1 6 7│1 6 8│1 6 9│

└─┴─┴─┘


┌─┬─┬─┐

│2 4 7│2 4 8│2 4 9│

├─┼─┼─┤

│2 5 7│2 5 8│2 5 9│

├─┼─┼─┤

│2 6 7│2 6 8│2 6 9│

└─┴─┴─┘

┌─┬─┬─┐

│3 4 7│3 4 8│3 4 9│

├─┼─┼─┤

│3 5 7│3 5 8│3 5 9│

├─┼─┼─┤

│3 6 7│3 6 8│3 6 9│

└─┴─┴─┘


Skip Cave
Consulting LLC


On Mon, May 18, 2020 at 3:38 AM HH PackRat  wrote:

> On 5/17/20, HH PackRat  wrote:
> > I need to convert the following list of 5 (in reality, far more)
> > 11-character dates: ...
> > to a list of 5 boxed dates: ...
>
> Many THANK YOU's to those who responded!  As usual with J, there's
> often more than one way to accomplish something--in this case, 5
> completely different ways that I can choose to add to my personal J
> vocabulary.
>
> The shortest was Skip Cave's response, but, Skip, I have a question
> about how/why yours works.  When I read the Vocabulary and NuVoc to
> see how and why this works, I could not figure out how I would even
> think to use "{" (catalogue) based on the information in those two
> sources.  The NuVoc definition/description is "Combines ITEMS from the
> ATOMS inside a BOXED LIST to form a catalogue."  My original list was
> NOT boxed, so that description would automatically dismiss my example
> from using "{".  Can you please clarify why "{" can be used to box an
> unboxed list?
>
> And, by the way, in my programming, I like to do things small step by
> small step so that I can be sure everything works correctly at each
> point.  My original goal in this case was to get the unboxed list
> first boxed in the correct manner and then transpose it from a column
> to a row.  (It's part of stock market data from a particular vendor
> which is out of "standard" order and format.)  Three of the five
> responses did both aspects (box and transpose) in a single
> command--for which I am quite grateful.  It showed me again how
> amazing J is!
>
> 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


Re: [Jprogramming] Finding rotational duplicates

2020-05-19 Thread Skip Cave
Testing Roger's rotational duplicate finder:

ts=:6!:2 , 7!:2@]

$x=.odo 8#8

16777216 8

ts 't0=.llr0 x'

37.0263 2.14749e9

ts 't1=.llr1 x'

26.6041 2.14749e9

ts 't3=.llr3 x'

34.1857 1.28849e10

ts 't2=.llr2 x'

|out of memory: llr2

| (c*i.n){}."1/:~(c#i.n),.((n*c)$i.c) |."_1 c#y

ts=:6!:2 , 7!:2@]


Fairly lengthy runtimes for 8 integers. It looks like that for more than
8-10 elements we'll need a more efficient algorithm.


Skip Cave
Cave Consulting LLC



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


Re: [Jprogramming] Finding rotational duplicates

2020-05-19 Thread Skip Cave
Testing Roger's rotational duplicate finder:

ts=:6!:2 , 7!:2@]

$x=.odo 8#8

16777216 8

ts 't0=.llr0 x'

37.0263 2.14749e9

ts 't1=.llr1 x'

26.6041 2.14749e9

ts 't3=.llr3 x'

34.1857 1.28849e10

ts 't2=.llr2 x'

|out of memory: llr2

| (c*i.n){}."1/:~(c#i.n),.((n*c)$i.c) |."_1 c#y

ts=:6!:2 , 7!:2@]


It looks like fairly lengthy runtimes for 8 integers. For more than 8-10
elements we may need a more efficient algorithm.


Skip Cave
Cave Consulting LLC


On Tue, May 19, 2020 at 9:14 PM Roger Hui  wrote:

> I think in such cases you ought to do i.!.0~x first (as the write-up points
> out).  Then you'd be working with small-range integers and the maximum
> element shouldn't cause a problem.  Unless you are working with a huge x.
> In which case you have other problems.
>
> On Tue, May 19, 2020 at 6:32 PM Raul Miller  wrote:
>
> > Perhaps worth noting that the "radius limit" is calculable based on
> > the type of the numbers in the argument.
> >
> > For integer values, on a 64 bit machine, radius*#y should not exceed
> > 9223372036854775807
> >
> >datatype 9223372036854775807
> > integer
> >datatype 9223372036854775807+1
> > floating
> >
> > It gets a little more complicated with floating point values, because
> > there the minimum difference between elements in a row is essential
> > for the calculation. If this is deemed to be worth to bother, it can
> > be calculated using 0 -.~ 2 -/\ \:~ row and finding the minimum
> > non-zero value. (If this is an empty list, all rows are already in
> > their canonical configuration.) If this value is available,
> > radius*mindiff*#y should not exceed 9007199254740991. (A convservative
> > approximation would be to verify that there are no fractional values
> > and use mindiff=.1)
> >
> > Not sure that this is worth the effort, but... anyways...
> >
> > FYI,
> >
> > --
> > Raul
> >
> > On Tue, May 19, 2020 at 11:37 AM Roger Hui 
> > wrote:
> > >
> > > I have written a lengthier description
> > > <https://forums.dyalog.com/viewtopic.php?f=30=1642> of the solutions
> > in
> > > the Dyalog APL Chat Forum.  It is in APL rather than J notation, but
> may
> > be
> > > helpful.  The main thing to remember is that " (the rank operator) is ⍤
> > in
> > > Dyalog APL.
> > >
> > >
> > >
> > > On Sun, May 17, 2020 at 10:44 PM Skip Cave 
> > wrote:
> > >
> > > > Roger,
> > > > The llr versions you provided are interesting and useful. I expect to
> > learn
> > > > much by analysing them.
> > > >
> > > > Skip Cave
> > > >
> > > >
> > > >
> > > > On Sun, May 17, 2020 at 3:09 PM Roger Hui  >
> > > > wrote:
> > > >
> > > > > (I posted the following msg which appears not to be distributed.
> > Not yet
> > > > > in the archive, at least.  Sorry if you receive this more than
> once.)
> > > > >
> > > > > llr0=: {.@(/:~)@(i.@# |."0 1 ])"1
> > > > >
> > > > > llr1=: {.@(/:~)@(([: I. ] = <./)|."0 1 ])"1
> > > > >
> > > > > llr2=: 3 : 0
> > > > >  c=. {: $ y
> > > > >  n=. # y
> > > > >  (c*i.n) { }."1 /:~ (c#i.n) ,. ((n*c)$i.c) |."_1 c # y
> > > > > )
> > > > >
> > > > > llr3=: 3 : 0
> > > > >  c=. {: $ y NB. # columns
> > > > >  n=. # yNB. # rows
> > > > >  r=. >:+:>./|,y NB. the "radius"
> > > > >  q=. y + r*i.n  NB. increase each row by the radius
> > > > >  e=. <./"1 qNB. minimum in each row
> > > > >  b=. q=eNB. where elements equal the minimum
> > > > >  s=. +/"1 b NB. # times that happens for each row
> > > > >  (r*i.n) -~ (}:+/\0,s) { /:~ (c|I.,b) |."_1 s#q
> > > > > )
> > > > >
> > > > > llr0 computes the lexicographically least rotation of all the
> > rotations
> > > > of
> > > > > each row.
> > > > >
> > > > > llr1 computes the LLR of, each row rotated so that every minimal
> > element
> > > > > gets the chance to be the first element.
> > > > >
> > > > > llr2 is llr0 reworked so that the code works on the entire matrix
> at
> > > > o

Re: [Jprogramming] Finding rotational duplicates

2020-05-19 Thread Skip Cave
Roger,

It has been many years since I programmed in APL. My last APL work project
was in 1976-77 designing character recognition algorithms on a Harris
terminal (IBM selectric mechanisms) with an acoustic coupler, using
University Computing Company's IBM Mainframe timesharing in Dallas Texas.
When I discovered J, I was very happy that I could stop having to paste APL
symbol stickers on my keyboard.

It will be interesting to see if I can still remember enough of the APL
symbols to understand your post in the APL chat forum.

Skip Cave
Cave Consulting LLC


On Tue, May 19, 2020 at 10:37 AM Roger Hui 
wrote:

> I have written a lengthier description
> <https://forums.dyalog.com/viewtopic.php?f=30=1642> of the solutions in
> the Dyalog APL Chat Forum.  It is in APL rather than J notation, but may be
> helpful.  The main thing to remember is that " (the rank operator) is ⍤ in
> Dyalog APL.
>
>
>
> On Sun, May 17, 2020 at 10:44 PM Skip Cave 
> wrote:
>
> > Roger,
> > The llr versions you provided are interesting and useful. I expect to
> learn
> > much by analysing them.
> >
> > Skip Cave
> >
> >
> >
> > On Sun, May 17, 2020 at 3:09 PM Roger Hui 
> > wrote:
> >
> > > (I posted the following msg which appears not to be distributed.  Not
> yet
> > > in the archive, at least.  Sorry if you receive this more than once.)
> > >
> > > llr0=: {.@(/:~)@(i.@# |."0 1 ])"1
> > >
> > > llr1=: {.@(/:~)@(([: I. ] = <./)|."0 1 ])"1
> > >
> > > llr2=: 3 : 0
> > >  c=. {: $ y
> > >  n=. # y
> > >  (c*i.n) { }."1 /:~ (c#i.n) ,. ((n*c)$i.c) |."_1 c # y
> > > )
> > >
> > > llr3=: 3 : 0
> > >  c=. {: $ y NB. # columns
> > >  n=. # yNB. # rows
> > >  r=. >:+:>./|,y NB. the "radius"
> > >  q=. y + r*i.n  NB. increase each row by the radius
> > >  e=. <./"1 qNB. minimum in each row
> > >  b=. q=eNB. where elements equal the minimum
> > >  s=. +/"1 b NB. # times that happens for each row
> > >  (r*i.n) -~ (}:+/\0,s) { /:~ (c|I.,b) |."_1 s#q
> > > )
> > >
> > > llr0 computes the lexicographically least rotation of all the rotations
> > of
> > > each row.
> > >
> > > llr1 computes the LLR of, each row rotated so that every minimal
> element
> > > gets the chance to be the first element.
> > >
> > > llr2 is llr0 reworked so that the code works on the entire matrix at
> > once,
> > > rather than one row at a time.
> > >
> > > llr3 likewise, llr2 reworked to work on the entire matrix at once.  It
> > > assumes that the maximal element in the entire matrix (needed for the
> > > "radius") is no so large as to consume all available precision.
> > >
> > >odo=: #: i.@(*/)
> > >x=: ,.~ ,~ odo 5$5
> > >$x
> > > 6250 10
> > >
> > >(llr0 -: llr1) x
> > > 1
> > >(llr0 -: llr2) x
> > > 1
> > >(llr0 -: llr3) x
> > > 1
> > >
> > >timer=: 6!:2
> > >timer&> 'llr0 x'; 'llr1 x'; 'llr2 x'; 'llr3 x'
> > > 0.0434449 0.0141476 0.0207071 0.00634583
> > >
> > >
> > > On Sat, May 16, 2020 at 4:44 PM Skip Cave 
> > wrote:
> > >
> > > > I have run across this issue a few times in the past.
> > > > The following 8x4 array has several rows that are 'rotational
> > > duplicates'.
> > > >
> > > > ]n=.8 4$2 4 1 3 2 3 4 1 3 4 1 2 3 2 4 1 1 3 2 4 4 1 2 3 1 2 3 4 4 1
> 3 2
> > > >
> > > > 2 4 1 3
> > > >
> > > > 2 3 4 1
> > > >
> > > > 3 4 1 2
> > > >
> > > > 3 2 4 1
> > > >
> > > > 1 3 2 4
> > > >
> > > > 4 1 2 3
> > > >
> > > > 1 2 3 4
> > > >
> > > > 4 1 3 2
> > > >
> > > >
> > > > Is it possible to develop a verb that would find the rows that are
> > > > rotational duplicates of each other. That is, find all the rows that
> > > would
> > > > be the same, if each row was rotated some integer value in the first
> > > > dimension. The output of the verb would be the same shape array, but
> > with
> > > > each duplicate row rotated such that they show as identical. Picking
> > the
> > > > 'standard' rotation for a set of rotational duplicates is up to the
> > > > implementer.
> > > >
> > > >
> > > > Skip
> > > >
> --
> > > > 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


Re: [Jprogramming] Deleting?

2020-05-19 Thread Skip Cave
Use copy (#) or from ({)


tst

┌──┬──┐

│May 08│May 07│

├──┼──┤

│2020 │2020 │

├──┼──┤

│664.35│652.35│

├──┼──┤

│660.21│653.00│

├──┼──┤

│664.56│657.12│

├──┼──┤

│657.67│651.29│

├──┼──┤

│- │- │

├──┼──┤

│1.84% │1.19% │

└──┴──┘

0 0 1 1 1 1 1 0#tst

┌──┬──┐

│664.35│652.35│

├──┼──┤

│660.21│653.00│

├──┼──┤

│664.56│657.12│

├──┼──┤

│657.67│651.29│

├──┼──┤

│- │- │

└──┴──┘


or

2 3 4 5 6{tst

┌──┬──┐

│664.35│652.35│

├──┼──┤

│660.21│653.00│

├──┼──┤

│664.56│657.12│

├──┼──┤

│657.67│651.29│

├──┼──┤

│- │- │

└──┴──┘


Skip Cave



On Tue, May 19, 2020 at 8:36 AM Michael Dykman  wrote:

> I have also found {:: to be very useful and under appreciated.
>
>
>
>
> On Tue, May 19, 2020, 07:56 HH PackRat  wrote:
>
> > On 5/19/20, Michael Dykman  wrote:
> > > In functional languages, you don't really delete so much as you make a
> > > fresh copy absent of the undesirable elements.
> > > Where you looking for this?
> > >
> > >  ] a=. <"0 'abcdef'
> > > ┌─┬─┬─┬─┬─┬─┐
> > > │a│b│c│d│e│f│
> > > └─┴─┴─┴─┴─┴─┘
> > >0 0 1 1 0 1 # a
> > > ┌─┬─┬─┐
> > > │c│d│f│
> > > └─┴─┴─┘
> >
> > That kind of thing is what gave me the idea of a boolean mask of some
> > type.  However, can this be carried over, applying to rows of a table
> > instead?  I'm thinking that it probably does in some way, but I want
> > confirmation on that.  Thanks for your response!
> >
> > 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


Re: [Jprogramming] Finding rotational duplicates

2020-05-17 Thread Skip Cave
Roger,
The llr versions you provided are interesting and useful. I expect to learn
much by analysing them.

Skip Cave



On Sun, May 17, 2020 at 3:09 PM Roger Hui  wrote:

> (I posted the following msg which appears not to be distributed.  Not yet
> in the archive, at least.  Sorry if you receive this more than once.)
>
> llr0=: {.@(/:~)@(i.@# |."0 1 ])"1
>
> llr1=: {.@(/:~)@(([: I. ] = <./)|."0 1 ])"1
>
> llr2=: 3 : 0
>  c=. {: $ y
>  n=. # y
>  (c*i.n) { }."1 /:~ (c#i.n) ,. ((n*c)$i.c) |."_1 c # y
> )
>
> llr3=: 3 : 0
>  c=. {: $ y NB. # columns
>  n=. # yNB. # rows
>  r=. >:+:>./|,y NB. the "radius"
>  q=. y + r*i.n  NB. increase each row by the radius
>  e=. <./"1 qNB. minimum in each row
>  b=. q=eNB. where elements equal the minimum
>  s=. +/"1 b NB. # times that happens for each row
>  (r*i.n) -~ (}:+/\0,s) { /:~ (c|I.,b) |."_1 s#q
> )
>
> llr0 computes the lexicographically least rotation of all the rotations of
> each row.
>
> llr1 computes the LLR of, each row rotated so that every minimal element
> gets the chance to be the first element.
>
> llr2 is llr0 reworked so that the code works on the entire matrix at once,
> rather than one row at a time.
>
> llr3 likewise, llr2 reworked to work on the entire matrix at once.  It
> assumes that the maximal element in the entire matrix (needed for the
> "radius") is no so large as to consume all available precision.
>
>odo=: #: i.@(*/)
>x=: ,.~ ,~ odo 5$5
>$x
> 6250 10
>
>(llr0 -: llr1) x
> 1
>    (llr0 -: llr2) x
> 1
>(llr0 -: llr3) x
> 1
>
>timer=: 6!:2
>timer&> 'llr0 x'; 'llr1 x'; 'llr2 x'; 'llr3 x'
> 0.0434449 0.0141476 0.0207071 0.00634583
>
>
> On Sat, May 16, 2020 at 4:44 PM Skip Cave  wrote:
>
> > I have run across this issue a few times in the past.
> > The following 8x4 array has several rows that are 'rotational
> duplicates'.
> >
> > ]n=.8 4$2 4 1 3 2 3 4 1 3 4 1 2 3 2 4 1 1 3 2 4 4 1 2 3 1 2 3 4 4 1 3 2
> >
> > 2 4 1 3
> >
> > 2 3 4 1
> >
> > 3 4 1 2
> >
> > 3 2 4 1
> >
> > 1 3 2 4
> >
> > 4 1 2 3
> >
> > 1 2 3 4
> >
> > 4 1 3 2
> >
> >
> > Is it possible to develop a verb that would find the rows that are
> > rotational duplicates of each other. That is, find all the rows that
> would
> > be the same, if each row was rotated some integer value in the first
> > dimension. The output of the verb would be the same shape array, but with
> > each duplicate row rotated such that they show as identical. Picking the
> > 'standard' rotation for a set of rotational duplicates is up to the
> > implementer.
> >
> >
> > Skip
> > --
> > 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] Finding Perfect Squares

2020-05-17 Thread Skip Cave
Roger,

I don't understand your last post.  I'm trying to find a way to search for
perfect squares.

For smaller integers the plan is easy.
1. Generate a list of integers (eg. 1 to 30):
   ]n=.>:i.30

2. Take the square root of each one (%:)
%:n

1 1.4142 1.7321 2 2.2361 2.4495 2.6458 2.8284 3 3.1623 3.3166 3.4641 3.6056
3.7417 3.873 4 4.1231 4.2426 4.3589 4.4721 4.5826 4.6904 4.7958 4.899 5
5.099 5.1962 5.2915 5.3852 5.4772


3. Find and mark the square roots of n that are integers (=>.)

(=>.)%:n

1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0


4. Use the marks to select the integers in n that are perfect squares (n#~):

n#~(=>.)%:n

1 4 9 16 25


So we are able to find the perfect squares in the range 1 to 30.


Now I want to find the perfect squares in the range of factorial 1 to 30:

Actually I know that factorials of integers *can't* have square roots
(except !1), but I want to check. See https://bit.ly/3fXevkr


So we generate the factorials of the integers 1 to 30 and store them in n:

]n=.!>:i.30x

1 2 6 24 120 720 5040 40320 362880 3628800 39916800 479001600 6227020800
87178291200 1307674368000 20922789888000 355687428096000 6402373705728000
121645100408832000 243290200817664 5109094217170944
11240007260768 2585201673888497664 62044840173323943936
1551121004333098598400 40329146112660563558400
106945041835216076800 30488834461171386050150400
884176199373970195454361600 26525285981219105863630848000


Now take the square roots of those 30 factorials, then find & mark any of
the square roots that are integers. We know that only the first square root
(%:!1) should be an integer, since 1 is a perfect square. all the square
roots of the other factorials should not be integers, as they are not
perfect squares.


(=>.)%:n

1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1

Uh oh! J is telling me that factorials of the last 5 integers (n=.26 27 28
29 30) are perfect squares! This is clearly not true. Roger showed this in
his response to me, but he didn't propose a solution.


How can I take the square root of large integers such as !26 27 28 29 30 in
J, and get an accurate floating point or rational number?


Skip Cave



On Sun, May 17, 2020 at 4:18 PM Roger Hui  wrote:

> Use <.@%:
>
>s=: <.@%: !26x
>s
> 20082117944245
>s*s
> 403291461126567024928620025
>!26x
> 40329146112660563558400
>
>
> On Sun, May 17, 2020 at 2:00 PM Skip Cave  wrote:
>
> > We can find perfect squares in a list by taking the square root (%:) of a
> > number, and checking to see if it is an integer:
> >
> > * n#~(=>.)%:n=.>:i.30*
> >
> > *1 4 9 16 25*
> >
> >
> > Now we can try larger integers by taking the square root of the factorial
> > of some small integers:
> >
> > * n#~(=>.)%:!n=.>:i.30*
> >
> > *1 26 27 28 29 30*
> >
> >
> > Hmm. This says that !26 and up, are perfect squares.
> >
> > * !26x*
> >
> > *40329146112660563558400*
> >
> > * %:!26x*
> >
> > *20082117944246*
> >
> >
> > Well it looks like %:!26x is an integer, making !26x a perfect square.
> > Let's check:
> >
> > * 20082117944246x^2*
> >
> > *403291461126607189164508516*
> >
> > * !26x*
> >
> > *40329146112660563558400*
> >
> >
> >  *  (!26x)-:20082117944246x^2 *
> > *0*
> > Clearly, !26x is not a perfect square.
> >
> > Looks like J has precision issues with the square root of large extended
> > integers. How can I fix this, to find accurate square roots of large
> > integers?
> >
> > Skip Cave
> > --
> > 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


[Jprogramming] Finding Perfect Squares

2020-05-17 Thread Skip Cave
We can find perfect squares in a list by taking the square root (%:) of a
number, and checking to see if it is an integer:

* n#~(=>.)%:n=.>:i.30*

*1 4 9 16 25*


Now we can try larger integers by taking the square root of the factorial
of some small integers:

* n#~(=>.)%:!n=.>:i.30*

*1 26 27 28 29 30*


Hmm. This says that !26 and up, are perfect squares.

* !26x*

*40329146112660563558400*

* %:!26x*

*20082117944246*


Well it looks like %:!26x is an integer, making !26x a perfect square.
Let's check:

* 20082117944246x^2*

*403291461126607189164508516*

* !26x*

*40329146112660563558400*


 *  (!26x)-:20082117944246x^2 *
*0*
Clearly, !26x is not a perfect square.

Looks like J has precision issues with the square root of large extended
integers. How can I fix this, to find accurate square roots of large
integers?

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


  1   2   3   4   5   6   >