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

2020-05-16 Thread bill lam
explicit code using loop. Sometimes explicit code is more memory and space efficient but not sure for this simple case. a=. 5 11$'May 04 2020May 01 2020Apr 30 2020Apr 29 2020Apr 28 2020' t1=: 3 : 0 z=. '' for_i. y do. z=. z, wrote: > I need to convert the following list of 5 (in reality, far more

Re: [Jprogramming] Finding rotational duplicates

2020-05-16 Thread Skip Cave
Roger's phrase 'lexicographically least rotation' was new to me, so i looked it up in Wikipedia . That article described several methods for finding the "lexicographical minimum string rotation." I will try to understand Roger

Re: [Jprogramming] Finding rotational duplicates

2020-05-16 Thread Roger Hui
Since the lexicographically least rotation necessarily begins with the least element of a row, llr=: {. @ (/:~) @ (([: I. ] = <./) |."0 1 ])"1 Less computation if the least element doesn't occur many times in a row. On Sat, May 16, 2020 at 10:59 PM Roger Hui wrote: > Find the lexicographically

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

2020-05-16 Thread Skip Cave
]a=.|:'May 04 2020',.'May 01 2020',.'Apr 30 2020',.'Apr 29 2020',.'Apr 28 2020' May 04 2020 May 01 2020 Apr 30 2020 Apr 29 2020 Apr 28 2020 bx=.3 :'((#{y),1)${y' NB. Vertical boxing verb. bx a ┌───┐ │May 04 2020│ ├───┤ │May 01 2020│ ├───┤ │Apr 30 2020│ ├──

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

2020-05-16 Thread 'Bo Jacoby' via Programming
   5 1$<"1]5 11$'May 04 2020May 01 2020Apr 30 2020Apr 29 2020Apr 28 2020' ┌───┐ │May 04 2020│ ├───┤ │May 01 2020│ ├───┤ │Apr 30 2020│ ├───┤ │Apr 29 2020│ ├───┤ │Apr 28 2020│ └───┘ Bo Den søndag den 17. maj 2020 08.02.20 CEST skre

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

2020-05-16 Thread Roger Hui
<"1 or 3 : '<"1 y' On Sat, May 16, 2020 at 10:56 PM HH PackRat wrote: > I need to convert the following list of 5 (in reality, far more) > 11-character dates: > > May 04 2020 > May 01 2020 > Apr 30 2020 > Apr 29 2020 > Apr 28 2020 > $ --> 5 11 > > to a list of 5 boxed dates: > > +---

Re: [Jprogramming] Finding rotational duplicates

2020-05-16 Thread Roger Hui
Find the lexicographically least of all the rotations of each row. Not very efficient, but works. llr=: {.@(/:~)@(i.@# |."0 1 ])"1 $ odo 3#5 125 3 $ llr odo 3#5 125 3 $ ~. llr odo 3#5 45 3 On Sat, May 16, 2020 at 10:50 PM Skip Cave wrote: > The acid test is to find all the rotation

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

2020-05-16 Thread HH PackRat
I need to convert the following list of 5 (in reality, far more) 11-character dates: May 04 2020 May 01 2020 Apr 30 2020 Apr 29 2020 Apr 28 2020 $ --> 5 11 to a list of 5 boxed dates: +-+ |May 04 2020| +-+ |May 01 2020| +-+ |Apr 30 2020| +-

Re: [Jprogramming] Finding rotational duplicates

2020-05-16 Thread 'Bo Jacoby' via Programming
   (|.~i.&1@(= <./))"1 n 1 3 2 4 1 2 3 4 1 2 3 4 1 3 2 4 1 3 2 4 1 2 3 4 1 2 3 4 1 3 2 4 Well, that is everybody else's idea. Bo Den søndag den 17. maj 2020 03.21.43 CEST skrev Roger Hui : > I could be wrong. Right.  I was wrong. On Sat, May 16, 2020 at 6:18 PM Rau

Re: [Jprogramming] Finding rotational duplicates

2020-05-16 Thread Skip Cave
The acid test is to find all the rotational duplicates of a full odometer sequence: *odo=:#:i.@(*/)* NB. Odometer verb * $n=.odo 3#5 * *125 3* *rd=:3 :'(y i."_1 <./"1 y)|."_1 y'* NB. Roger's rotational duplication verb *$rdn=.rd n* NB. Return all rows to key form. *125 3* * $rdn1=.~. rdn* NB

Re: [Jprogramming] reshaping a list to a table

2020-05-16 Thread bill lam
in the context of explicit definition. y is always there, so it should be harmless. I thought you had already done that. My memory no longer serve me? On Sun, May 17, 2020, 9:16 AM Henry Rich wrote: > No, because if y, a, and b are deleted, you are left holding y when all > you need is c. > > He

Re: [Jprogramming] Finding rotational duplicates

2020-05-16 Thread Roger Hui
> I could be wrong. Right. I was wrong. On Sat, May 16, 2020 at 6:18 PM Raul Miller wrote: > For example: > >A=: 2 3 1 2 1,: 2 1 2 3 1 >2 1 |.("_1) A > 1 2 1 2 3 > 1 2 3 1 2 >2 4 |.("_1) A > 1 2 1 2 3 > 1 2 1 2 3 > > Thanks, > > -- > Raul > > On Sat, May 16, 2020 at 9:11 PM Roger

Re: [Jprogramming] reshaping a list to a table

2020-05-16 Thread Henry Rich
What I meant was, rather than b =. , a c =. +/ b you would do c =. +/ , a Generally, avoid needless assignments.  They destroy both inplacing and virtual nouns. Henry Rich On 5/16/2020 8:24 PM, bill lam wrote: What's the difference or (,a) ? which form should I use? On Sun, May 17, 2020,

Re: [Jprogramming] Finding rotational duplicates

2020-05-16 Thread Raul Miller
For example: A=: 2 3 1 2 1,: 2 1 2 3 1 2 1 |.("_1) A 1 2 1 2 3 1 2 3 1 2 2 4 |.("_1) A 1 2 1 2 3 1 2 1 2 3 Thanks, -- Raul On Sat, May 16, 2020 at 9:11 PM Roger Hui wrote: > > The question is, do you get a unique key (signature) if you rotate a row so > that the first occurrence of

Re: [Jprogramming] reshaping a list to a table

2020-05-16 Thread Henry Rich
No, because if y, a, and b are deleted, you are left holding y when all you need is c. Henry Rich On 5/16/2020 8:52 PM, bill lam wrote: but then the indirect assignment 'a b c'=. y should use up entire y, just increasing usecount shouldn't be a problem. I think this is already implemented, am

Re: [Jprogramming] Finding rotational duplicates

2020-05-16 Thread Roger Hui
The question is, do you get a unique key (signature) if you rotate a row so that the first occurrence of the minimum value is first? I thought the answer was yes after thinking about it for a minute. I could be wrong. On Sat, May 16, 2020 at 5:53 PM Raul Miller wrote: > A critical question he

Re: [Jprogramming] Finding rotational duplicates

2020-05-16 Thread Raul Miller
A critical question here is whether the minimum value can appear more than once in each row, or whether the examples (where each value is has a unique appearance in each row) are adequately complex. Thanks, -- Raul On Sat, May 16, 2020 at 8:15 PM Roger Hui wrote: > > Hmm, you just want the key

Re: [Jprogramming] reshaping a list to a table

2020-05-16 Thread bill lam
but then the indirect assignment 'a b c'=. y should use up entire y, just increasing usecount shouldn't be a problem. I think this is already implemented, am I right? On Sun, May 17, 2020, 8:13 AM Henry Rich wrote: > c =. 1 { a is problematic because if a is deleted, you are left holding > the e

Re: [Jprogramming] Finding rotational duplicates

2020-05-16 Thread Skip Cave
Thanks Roger! That's exactly what I needed. The boxed solution is also useful in a couple of instances. Skip On Sat, May 16, 2020 at 7:15 PM Roger Hui wrote: > Hmm, you just want the keys: rotate each row so that the minimum item is > first. > >(n i."_1 <./"1 n)|."_1 n > 1 3 2 4 > 1 2 3 4

Re: [Jprogramming] reshaping a list to a table

2020-05-16 Thread Michael Dykman
I have only fiddled around with the J source code a bit enough to make it work on an Android but I have implemented a few compilers for languages with functional properties. Bill, your observation made me rethink my entire approach yet again. I am reminded of a colleague who once explained to me

Re: [Jprogramming] reshaping a list to a table

2020-05-16 Thread bill lam
What's the difference or (,a) ? which form should I use? On Sun, May 17, 2020, 8:13 AM Henry Rich wrote: > c =. 1 { a is problematic because if a is deleted, you are left holding > the entire a just to make one item available. That would waste space. > > b =. , a could perhaps increase the usec

Re: [Jprogramming] reshaping a list to a table

2020-05-16 Thread Henry Rich
Virtual blocks started in 8.07 and were finished in 9.01; not so many years. Look at https://code.jsoftware.com/wiki/Vocabulary/SpecialCombinations#Virtual_Nouns and https://code.jsoftware.com/wiki/Vocabulary/SpecialCombinations#Execution_In_Place_.28EIP.29 for some rules that will save time

Re: [Jprogramming] Finding rotational duplicates

2020-05-16 Thread Roger Hui
Hmm, you just want the keys: rotate each row so that the minimum item is first. (n i."_1 <./"1 n)|."_1 n 1 3 2 4 1 2 3 4 1 2 3 4 1 3 2 4 1 3 2 4 1 2 3 4 1 2 3 4 1 3 2 4 On Sat, May 16, 2020 at 5:11 PM Roger Hui wrote: >((n i."_1 <./"1 n)|."_1 n) ┌───┬───┐ > │2 4 1 3│2 3 4 1│ >

Re: [Jprogramming] reshaping a list to a table

2020-05-16 Thread Henry Rich
c =. 1 { a is problematic because if a is deleted, you are left holding the entire a just to make one item available.  That would waste space. b =. , a could perhaps increase the usecount of the backer, but I didn't implement it that way, and I think I decided it wouldn't work to, but I can't

Re: [Jprogramming] Finding rotational duplicates

2020-05-16 Thread Roger Hui
((n i."_1 <./"1 n)|."_1 n) 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 > >

[Jprogramming] Finding rotational duplicates

2020-05-16 Thread Skip Cave
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 devel

Re: [Jprogramming] Bug: +./4.57 4.34 4.44

2020-05-16 Thread Devon McCormick
Bo wrote: > Devon, your solution > 9!:19]1e_11 This was not intended as a solution but a demonstration that +. is sensitive to comparison tolerance. "9!:19" sets comparison tolerance but does not allow an argument greater than 1e_11. On Sat, May 16, 2020 at 11:25 AM Raul Miller wrote: > In an

Re: [Jprogramming] reshaping a list to a table

2020-05-16 Thread 'Michael Day' via Programming
So have we all (mostly) been wrong over all the years in reporting, and comparing, ts,  and the like,  to assess which is the "best" version of some verb?  We had all, mostly?, learnt to assign the input outside the ts argument,  but that's only the foothills, apparently. I don't think i

Re: [Jprogramming] reshaping a list to a table

2020-05-16 Thread bill lam
Shouldn't assignment like b=. , a c=. 1{a just increase reference count of the mother instead of deep copy? On Sun, May 17, 2020, 6:27 AM Henry Rich wrote: > I wouldn't say so. Reshape takes virtually no time/space, but boxing or > assigning the reshaped result does. If you do something like

Re: [Jprogramming] reshaping a list to a table

2020-05-16 Thread Henry Rich
I wouldn't say so.  Reshape takes virtually no time/space, but boxing or assigning the reshaped result does.  If you do something like +/ @: (,/) y the result of ,/ is never realized and it would be wrong to charge it with time/space not used. Similarly (}. - }:) y the }. and }: create vir

Re: [Jprogramming] reshaping a list to a table

2020-05-16 Thread 'Pascal Jasmin' via Programming
This is the main way to do it, but as a "self contained" adverb that uses reshape  bycol =: 1 : '$~ (m |~ #) ,~ m <.@%~ #' NB. cuts off any incomplete rows  3 bycol i.8 0 1 2 3 4 5 On Saturday, May 16, 2020, 10:57:38 a.m. EDT, 'Rob Hodgkinson' via Programming wrote: You could

Re: [Jprogramming] reshaping a list to a table

2020-05-16 Thread 'Mike Day' via Programming
Oh... so one needs to, say, assign the result to see the real t/s? Thanks, Mike Sent from my iPad > On 16 May 2020, at 17:05, Henry Rich wrote: > > The time/space numbers are telling you that (x $ y) produces a virtual result > when it can, while (_2 ]\ y) doesn't (yet). If you use the resu

Re: [Jprogramming] reshaping a list to a table

2020-05-16 Thread Henry Rich
The time/space numbers are telling you that (x $ y) produces a virtual result when it can, while (_2 ]\ y) doesn't (yet).  If you use the result immediately, the space saving is real.  If you box the result or save it in a name, the value will be realized and the space saving will vanish. Hen

Re: [Jprogramming] Bug: +./4.57 4.34 4.44

2020-05-16 Thread Raul Miller
In an expression like +./&.:(1p1&*)12 30 6 we should note that 12 and 30 are both [small] integers (and, thus, exact). Also, 1p1 is a value close to pi, and while it's true that it's not exactly pi, it's a common factor in this context. So it comes through in the gcd result. Basically it's j

Re: [Jprogramming] reshaping a list to a table

2020-05-16 Thread 'Michael Day' via Programming
Much neater than what I was about to offer,  unless Raoul needs to specify the fill, in which case,  this alternative rather minimal amendment is worth consideration:    ($!._ ~2,~>.@-:@#) i.7 0 1 2 3 4 5 6 _ cf    _2]\ i.7 0 1 2 3 4 5 6 0 Also, the time and space performance _might_ be im

Re: [Jprogramming] reshaping a list to a table

2020-05-16 Thread 'Rob Hodgkinson' via Programming
You could try Infix … here with NuVoc link… https://code.jsoftware.com/wiki/Vocabulary/bslash#dyadic x u\ y where x is eg _2 means apply very b to successive pairs (_ for non-overlapping). _2 ]\ 1 2 3 4 5 6 1 2 3 4 5 6 _2 ]\ 1 2 3 4 5 6 7 1 2 3 4 5 6 7 0 _2 <\ 1 2 3 4 5 6 ┌───┬

[Jprogramming] reshaping a list to a table

2020-05-16 Thread Raoul Schorer
Hello, I am convinced that this must be trivial, but I wasn't able to find in the documentation how to reshape a list to a table without manually extracting the length. in summary, is there a more direct way of doing: lst =. i. 6 ((2,~2%~#) $ ]) lst for a list of arbitrary length? Thanks!

Re: [Jprogramming] no Bug, try to find your own error before accusing: +./4.57 4.34 4.44

2020-05-16 Thread bill lam
3!:3 (100&*)4.57 4.34 4.44 e300 0800 0300 0100 0300 00907c40 00207b40 01c07b40 3!:3 (-~1.1)+457 434 444 e300 0800 0300 0100 0300 00907c40 0

Re: [Jprogramming] Bug: +./4.57 4.34 4.44

2020-05-16 Thread 'Bo Jacoby' via Programming
Raul, note that this works:    (+.&.(*&1p1))/2 3 1 even though  the numbers     0j16":(*&1p1)2 3 6.2831853071795862 9.4247779607693793 do not satisfy your demands of being exactly represented. Thanks! Bo Den lørdag den 16. maj 2020 13.03.21 CEST skrev Hauke Rehr : The answe

Re: [Jprogramming] no Bug, try to find your own error before accusing: +./4.57 4.34 4.44

2020-05-16 Thread Don Guinn
0j16":,.(100&*)4.57 4.34 4.44 457. 434. 444.0600 On Sat, May 16, 2020 at 12:34 AM 'Bo Jacoby' via Programming < programm...@jsoftware.com> wrote: > >(100&*)4.57 4.34 4.44 > > 457 434 444 > >+./(100&*)4.57 4.34 4.44 > 2.63185e_11 > >(+./&.

Re: [Jprogramming] Bug: +./4.57 4.34 4.44

2020-05-16 Thread Hauke Rehr
The answer 3j2 looks sane. 3j2 * 0j1 0j_1 and the only one in the first quadrant. Nice! Am 16.05.20 um 12:32 schrieb Raul Miller: Oh, I see -- or, I think I see what you were trying to illustrate now. That said, this is kind of interesting: +./(,-)2j_3 3j2 But I also noticed that +/(,-) se

Re: [Jprogramming] Bug: +./4.57 4.34 4.44

2020-05-16 Thread Raul Miller
Any expression involving !: is documented in the "Foreigns" section of the vocabulary: https://www.jsoftware.com/help/dictionary/vocabul.htm leads (via the "Foreigns" link) to https://www.jsoftware.com/help/dictionary/xmain.htm which leads (via the "9!:" link) to https://www.jsoftware.com/help/dic

Re: [Jprogramming] Bug: +./4.57 4.34 4.44

2020-05-16 Thread Raul Miller
Oh, I see -- or, I think I see what you were trying to illustrate now. That said, this is kind of interesting: +./(,-)2j_3 3j2 But I also noticed that +/(,-) seems to bring back associativity (we already had commutativity with +.): (i.6) A."0 1]4.57 4.34 4.44 4.57 4.34 4.44 4.57 4.44 4.34

Re: [Jprogramming] Bug: +./4.57 4.34 4.44

2020-05-16 Thread 'Bo Jacoby' via Programming
Thanks everyone! Devon, your solution   9!:19]1e_11   +./4.57 4.34 4.44 0.01 looks palatable! I didn't know of 9!:19. Where to read more about it? But      +./18.457 18.434 18.444 1.93197e_11 and    9!:19]1e_10 |domain error | 9!:19]1e_10 so it doesn't really solve the problem. I agre

Re: [Jprogramming] Bug: +./4.57 4.34 4.44

2020-05-16 Thread bill lam
Thanks! This caught a real bug in J +./(,-) _. loops forever. On Sat, May 16, 2020 at 5:51 PM Hauke Rehr wrote: > sorry, I was not sufficiently precise about my example > I meant to talk about atomic a only > > if $ a is empty, then > +./ (, -) a > will work > > Thanks for pointing out the la

Re: [Jprogramming] Bug: +./4.57 4.34 4.44

2020-05-16 Thread Hauke Rehr
sorry, I was not sufficiently precise about my example I meant to talk about atomic a only if $ a is empty, then +./ (, -) a will work Thanks for pointing out the lack of precision. Am 16.05.20 um 11:46 schrieb Raul Miller: I was talking about the implementation. These are different results:

Re: [Jprogramming] Bug: +./4.57 4.34 4.44

2020-05-16 Thread Raul Miller
I was talking about the implementation. These are different results: +./@(,-)4.57 4.34 4.44 8.88178e_16 +./@(,-)&.x:4.57 4.34 4.44 0.01 +./@(,-)&.:(*&1p1)4.57 4.34 4.44 5.65432e_16 The reason is that binary floating point cannot represent 5^_1 nor 5^_2 accurately. Thanks, -- Raul On

Re: [Jprogramming] Bug: +./4.57 4.34 4.44

2020-05-16 Thread Devon McCormick
If you search for something like "GCD non-integer", you will probably get ten or more pages of integer-only results. The one non-integer result I found was a query about using Excel to do this that was closed for lack of response. Not that should deter us who seek to extend the concept but we are

Re: [Jprogramming] Bug: +./4.57 4.34 4.44

2020-05-16 Thread Hauke Rehr
Maybe we have a naming (referencing) issue here. You may call an algorithm gcd that is working on whole numbers only but is used for determining what I call the gcd on rationals, the aforementioned √2*ℚ, polynomials, whathaveyou. other than that, sapere aude you can see it will work on those numb

Re: [Jprogramming] Bug: +./4.57 4.34 4.44

2020-05-16 Thread bill lam
Do you have any reference that gcd is applicable beyond the context of inregers? On Sat, May 16, 2020 at 5:19 PM Hauke Rehr wrote: > wrong. > > first, gcd is a general concept, it’s nothing crafted but found > it was always there and not meant for anything in the first place > it applies to rati

Re: [Jprogramming] Bug: +./4.57 4.34 4.44

2020-05-16 Thread Hauke Rehr
wrong. first, gcd is a general concept, it’s nothing crafted but found it was always there and not meant for anything in the first place it applies to rational numbers just as fine and to any scaling thereof. Mathematically, you get sane results working with gcd on √2*ℚ, for example. second, the