Re: [Jprogramming] Matrix of functions

2020-12-18 Thread Roger Hui
> R =: ((cos , -@sin) ,: sin , cos) I am curious why the definition isn't (cos , -@sin) ,: (sin , cos) It seems prettier (more balanced, more symmetric). On Fri, Dec 18, 2020 at 3:56 AM Ben Gorte wrote: > Perhaps I'm missing the point, but I would say: > > R =: ((cos , -@sin) ,: sin , co

Re: [Jprogramming] Matrix of functions

2020-12-18 Thread Francesco Pedulla'
Thanks to all who presented their ideas on how to address this issue with J. As usual, I learn a lot from the users of this Forum! F. On Fri, Dec 18, 2020 at 8:58 AM Francesco Pedulla' wrote: > Dear all, > I need to represent the 2D rotation matrix 'R' > > R = |cos(t) -sin(t)| >|sin(t)

Re: [Jprogramming] Matrix of functions

2020-12-18 Thread Francesco Pedulla'
Your solution is simple but does not easily generalize to more complex cases (infact, a requirement I did not express...). Thanks, Francesco On Fri, Dec 18, 2020 at 6:18 PM Raul Miller wrote: > I would be tempted to use something like: >R=: (2 1,:1 2) o. _1 1&* > > For example: >R"0(0 3

Re: [Jprogramming] Matrix of functions

2020-12-18 Thread Francesco Pedulla'
Hi Ben, in fact you got the point. I thought you needed a gerund to build a structure of functions. Your solution is very clean and I like it a lot. Thanks! Francesco On Fri, Dec 18, 2020 at 12:56 PM Ben Gorte wrote: > Perhaps I'm missing the point, but I would say: > > R =: ((cos , -@sin) ,: s

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 <

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread xash
|. ('()'i.n)} ')','(',: n or tacit ([:|. ('()'&i.)`(')','(',:])}) n On Fri Dec 18, 2020 at 10:35 PM CET, Skip Cave wrote: > 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 > > > O

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread Jimmy Gauvin
Hi, " amend in place " , that's very cool Thanks for demonstrating a practical use case. Jimmy PS you can use #.(base 2 decode) to replace +/1 2* On Fri, Dec 18, 2020 at 4:36 PM Skip Cave wrote: > Using curlyrt: (amend in place) > > n=.'1+(2*3)+(4*(5+6))' > > > |.(+/1 2*'()'=/n)}n,(17#'

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

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread 'robert therriault' via Programming
Slightly different approach by converting over and back from integers and doing some arithmetic |.@:(+ (+/ @: (1 _1 * 40 41 =/ ]))) &. (3&u:) '1 + (2 * 3) + (4 * (5 + 6))' ((6 + 5) * 4) + (3 * 2) + 1 Cheers, bob > On Dec 18, 2020, at 12:12, 'Michael Day' via Programming > wrote: > > Yes

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread Joseph Novakovich
Right! 0 1 =/ '()' i. y is just '()' =/ y... Yes, day 15/2 is unfortunately similarly slow for me, where I update a length 3e7 array to track times. An equivalent scheme version manages in <600ms. The gap in performance is odd... Joseph On 12/18/20, 'Michael Day' via Programming wrote: > Yes, I

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread 'Michael Day' via Programming
Yes, I ended up indexing brackets with    I. '()' =/ y ,  assuming that the left & right brackets were balanced! Part 2 was long-winded, recursive,  but evaluated quickly, luckily. My slowest routine for any of these posers is for part 2 of Day 15; best I managed was ~ 40 seconds. Cheers, M

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread Joseph Novakovich
For part 1 I used pretty much the same approach, eval by way of reversing (|.&.;:): +/ {{".'('c}')'o}y['o c'=. I. 0 1=/'()'i.y=.|.&.;:y}}&> in Mine differs mostly in avoiding library definitions, amending parens by index. For part 2 I used ;: to calculate a depth vector for the tokens and then

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread 'Michael Day' via Programming
Thanks, Brian - I thought I needed to put in a temporary intermediate value to avoid reversing the first change,  hence the three pairs rather than two. But the enigma remains, doesn't it:  what stops ']' becoming ')' ? Do rplc and/or stringreplace only work on a maximum of two pairs of before

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread Brian Schott
What about the following? ( '()',')(' ) stringreplace|. '1 + (2 * 3) + (4 * (5 + 6))' ((6 + 5) * 4) + (3 * 2) + 1 On Fri, Dec 18, 2020 at 1: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

Re: [Jprogramming] String replace puzzle

2020-12-18 Thread Peter Vernigorov
For the first part you can use charsub - https://www.jsoftware.com/help/user/lib_strings.htm#charsub '())('charsub |.'1*2+(3*4)' (4*3)+2*1 On Fri, Dec 18, 2020 at 19:21 'Michael Day' via Programming < programm...@jsoftware.com> wrote: > Unlike in the K forum, the J-wires have been virtually

[Jprogramming] String replace puzzle

2020-12-18 Thread 'Michael Day' via Programming
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,

Re: [Jprogramming] Matrix of functions

2020-12-18 Thread Raul Miller
I would be tempted to use something like: R=: (2 1,:1 2) o. _1 1&* For example: R"0(0 30p1 45p1 60p1%180) 1 0 0 1 0.866025 _0.5 0.5 0.866025 0.707107 _0.707107 0.707107 0.707107 0.5 _0.866025 0.866025 0.5 FYI, -- Raul On Fri, Dec 18

Re: [Jprogramming] A sorting surprise

2020-12-18 Thread Jimmy Gauvin
Hi, bitten by shape (again) : $&.>x ┌┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐ ││1│1│1│1│1│1│1│1│1│1│1│1│1│1│1│1│1│1│1│ └┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘ Thanks, Jimmy On Fri, Dec 18, 2020 at 11:38 AM Hauke Rehr wrote: > yes, I suspect there must be shape issues > >] x =: ;/

Re: [Jprogramming] A sorting surprise

2020-12-18 Thread Hauke Rehr
yes, I suspect there must be shape issues ] x =: ;/ 18 8 13 15 16 9 14 5 2 1 3 0 4 6 12 10 7 17 11 19 ┌──┬─┬──┬──┬──┬─┬──┬─┬─┬─┬─┬─┬─┬─┬──┬──┬─┬──┬──┬──┐ │18│8│13│15│16│9│14│5│2│1│3│0│4│6│12│10│7│17│11│19│ └──┴─┴──┴──┴──┴─┴──┴─┴─┴─┴─┴─┴─┴─┴──┴──┴─┴──┴──┴──┘ /: x 11 9 8 10 12 7 13 16 1 5 15 1

Re: [Jprogramming] A sorting surprise

2020-12-18 Thread Roger Hui
I would like to know what $&.>x looks like. On Fri, Dec 18, 2020 at 8:30 AM Jimmy Gauvin wrote: > Hi all, > > I am failing at understanding the difference between sorting a boxed > numeric vector and the unboxed vector : > >x > ┌──┬─┬──┬──┬──┬─┬──┬─┬─┬─┬─┬─┬─┬─┬──┬──┬─┬──┬──┬──┐ > │18│8

[Jprogramming] A sorting surprise

2020-12-18 Thread Jimmy Gauvin
Hi all, I am failing at understanding the difference between sorting a boxed numeric vector and the unboxed vector : x ┌──┬─┬──┬──┬──┬─┬──┬─┬─┬─┬─┬─┬─┬─┬──┬──┬─┬──┬──┬──┐ │18│8│13│15│16│9│14│5│2│1│3│0│4│6│12│10│7│17│11│19│ └──┴─┴──┴──┴──┴─┴──┴─┴─┴─┴─┴─┴─┴─┴──┴──┴─┴──┴──┴──┘ 3!:0 each x NB.

Re: [Jprogramming] Matrix of functions

2020-12-18 Thread Hauke Rehr
Perhaps we have both been missing the point. I hastily said “you won’t be able to ‘matrix multiply gerund matrices’” In J, you can actually achieve that. And if that’s what OP wanted, we indeed missed the point. A solution would then keep R as-is in order to let the user make good use of Js funct

Re: [Jprogramming] Matrix of functions

2020-12-18 Thread Ben Gorte
Perhaps I'm missing the point, but I would say: R =: ((cos , -@sin) ,: sin , cos) R 1r6p1 0.866025 _0.5 0.5 0.866025 Ben On Fri, 18 Dec 2020 at 18:59, Francesco Pedulla' wrote: > Dear all, > I need to represent the 2D rotation matrix 'R' > > R = |cos(t) -sin(t)| >|sin(t) cos(t)|

Re: [Jprogramming] Matrix of functions

2020-12-18 Thread Lippu Esa
Hello I played some years ago with 2D rotation as part of general linear mappnigs with complex numbers. A small demo below. Esa NB. ID rotdemo.ijs v0.0 28.06.17 NB. NO rotate some points load 'graph' tographcoord=:[:_0.98&+1.96&* randompts=. 3 : 0 (y,2) $ tographcoord ?(+:y) #0 ) rot=: 4

Re: [Jprogramming] Matrix of functions

2020-12-18 Thread Hauke Rehr
Sorry, I made a mistake: the order of the entries is wrong. And what your code does is compute (R pi)%4 rather than R(pi%4) so I guess my solution (with swapped sin entries) is what you wanted. Am 18.12.20 um 09:09 schrieb Hauke Rehr: > First of all, I wonder which result you expect. > Is the resu

Re: [Jprogramming] Matrix of functions

2020-12-18 Thread Hauke Rehr
First of all, I wonder which result you expect. Is the result of “R mf pi%4” what you want? Personally, I woldn’t mind if R’s shape reflects what we call a matrix as long as its result does (after all, you won’t be able to “matrix multiply gerund matrices”) So my solution would look like this: R