Re: [Jprogramming] Removing annihilating pairs

2019-12-07 Thread Louis de Forcrand
First some bad news:

   s=: ,`(}.@])@.(= -@{:)/
   s 1 _1 0
1 _1 0
   s=: ,`(}.@])@.(= -@{.)/
   s 1 _1 0
0
   s 0 1 _1


So our solutions don't work if the accumulator array goes empty before the end. 
Fortunately this can be fixed (see below).
Now some good news:

   s=: ,`(}.@])@.(0:`(= -@{.)@.(*@#@]))/
   s=: , `(}.@])@.(0:`(= -@{.)@.(*@#@]))/
   d=: ,~`(}:@])@.(0:`(= -@{:)@.(*@#@]))/@|.
   k=: 1 _1 2 _2 {~ 100 ?.@# 4
   
   s 1 _1 0
0
   s 0 1 _1
0
   s k
2 1 2 1 _2 _1 2 1 1 2 2 2 _1 2 _1 2 1 2 2 2 1 1 _2 _1 2 1 _2 _1 _2 _2 _2 _2 _1 
_2 _1 _1 _2 _2 1 1 1 2 1 _2 1 _2 _1 _1 _1 2
   d k
2 1 2 1 _2 _1 2 1 1 2 2 2 _1 2 _1 2 1 2 2 2 1 1 _2 _1 2 1 _2 _1 _2 _2 _2 _2 _1 
_2 _1 _1 _2 _2 1 1 1 2 1 _2 1 _2 _1 _1 _1 2
   
   K1=: 1 _1 2 _2 {~ 1  ?.@# 4
   K2=: 1 _1 2 _2 {~ 10 ?.@# 4
   timespacex 'd K1'
0.006343 233024
   timespacex 'd K2'
0.055919 1.83866e6

Linear as it should be.
Moral: Always append to the end of arrays.
Or: We aren't using linked lists!

Cheers,
Louis

Original Message
From : r.e.b...@outlook.com
Date : 07/12/2019 - 12:33 (CEST)
To : programm...@jsoftware.com
Subject : Re: [Jprogramming] Removing annihilating pairs

Forcrand's solution is more or less the version I came up with, unfortunately, 
it's far from linear (what is not compensated by its elegance).
   foo=: ,`(}.@])@.(0=(+{.))/
  ts'foo 1 _1 2 _2{~1?.@#4'
0.0166915 854720
  ts'foo 1 _1 2 _2{~10?.@#4'
1.9109807 6818496

Miller's solution is better in that respect (and much faster)
  ts'an2 1 _1 2 _2{~1?.@#4'
0.0024111 722816
  ts'an2 1 _1 2 _2{~10?.@#4'
0.0281419 6293376

ddup from Rich also seems to be linear but is a factor 10 slower than an2
  ts'ddup 1 _1 2 _2{~1?.@#4'
0.0219618 395264
  ts'ddup 1 _1 2 _2{~10?.@#4'
0.2124874 3147776

Jasmin's solution is far too slow
   ts'(delitemG~ 2, 0 i.~ 2&(+/\))(^:_) 1 _1 2 _2{~1?.@#4'
1.2363434 1585408

Thanks for all the contributions


R.E. Boss


> -Oorspronkelijk bericht-
> Van: Programming 
> Namens Louis de Forcrand
> Verzonden: zaterdag 7 december 2019 00:26
> Aan: programm...@jsoftware.com
> Onderwerp: Re: [Jprogramming] Removing annihilating pairs
> 
> Not particularly J-ish, but (array-shuffling aside) linear solution:
> 
>s=: ,`(1}.])@.(= -@{.)/
>s 1 _1 2 _2{~100?.@#4
> 2 1 2 1 _2 _1 2 1 1 2 2 2 _1 2 _1 2 1 2 2 2 1 1 _2 _1 2 1 _2 _1 _2 _2 _2 _2 
> _1 _2 _1
> _1 _2 _2 1 1 1 2 1 _2 1 _2 _1 _1 _1 2
> 
> Since the reduced form of the input list is unique, we are free to perform
> reductions in any order we please; in particular, we can start simplifying 
> from
> the back, which is what s does.
> Might do strange stuff on an empty input list.
> 
> Cheers,
> Louis
> 
> Original Message
> From : ol...@bluewin.ch
> Date : 06/12/2019 - 23:51 (CEST)
> To : programm...@jsoftware.com
> Subject : Re: [Jprogramming] Removing annihilating pairs
> 
> If the answer to Jimmy's question is no, then the uniqueness of the resulting
> array has to do (surprisingly) with free groups
> (https://en.wikipedia.org/wiki/Free_group).
> Indeed we can view a vector of numbers as a word over the alphabet [0,∞)
> of positive real numbers (where negative numbers / zero are inverses of
> letters in our alphabet). The fact that all maximal reductions (reductions
> which contain no adjacent inverses) of a given word are equal means exactly
> that our reduced list is unique.
> For a proof see:
> https://math.stackexchange.com/a/2425147
> 
> I'll look into this problem, it's interesting!
> Cheers,
> Louis
> 
> Original Message
> From : jimmy.gau...@gmail.com
> Date : 06/12/2019 - 23:36 (CEST)
> To : programm...@jsoftware.com
> Subject : Re: [Jprogramming] Removing annihilating pairs
> 
> Hi,
> 
> is the expected output of transforming 1 3 _3 3 5 to be 1 3 5 or 1 5 ?
> 
> On Fri, Dec 6, 2019 at 7:15 AM R.E. Boss  wrote:
> 
> > Given an array with zero or more annihilating pairs, i.e., two
> > subsequent numbers which add up to zero, the question is to clean up
> > the array by deleting all annihilating pairs such that no such pairs are 
> > left.
> > I do have a solution that is both elegant and efficient (I believe),
> > but I am curious about other thoughts.
> >
> >foo  2 1 1 _1 2 _2 _1
> > 2
> >
> >foo 1 _1 2 _2{~100?.@#4  NB. Notice (?.)
> > 2 1 2 1 _2 _1 2 1 1 2 2 2 _1 2 _1 2 1 2 2 2 1 1 _2 _1 2 1 _2 _1 _2 _2
> > _2
> > _2 _1 _2 _1 _1 _2 _2 1 1 1 2 1 _2 1 _2 _1 _1 _1 2
> >
> >
> > R.E. Boss
> > --
> > For information about J forums see
> http://www.jsoftware.com/forums.htm
> &

Re: [Jprogramming] Removing annihilating pairs

2019-12-06 Thread Louis de Forcrand
Not particularly J-ish, but (array-shuffling aside) linear solution:

   s=: ,`(1}.])@.(= -@{.)/
   s 1 _1 2 _2{~100?.@#4
2 1 2 1 _2 _1 2 1 1 2 2 2 _1 2 _1 2 1 2 2 2 1 1 _2 _1 2 1 _2 _1 _2 _2 _2 _2 _1 
_2 _1 _1 _2 _2 1 1 1 2 1 _2 1 _2 _1 _1 _1 2

Since the reduced form of the input list is unique, we are free to perform 
reductions in any order we please; in particular, we can start simplifying from 
the back, which is what s does.
Might do strange stuff on an empty input list.

Cheers,
Louis

Original Message
From : ol...@bluewin.ch
Date : 06/12/2019 - 23:51 (CEST)
To : programm...@jsoftware.com
Subject : Re: [Jprogramming] Removing annihilating pairs

If the answer to Jimmy's question is no, then the uniqueness of the resulting 
array has to do (surprisingly) with free groups 
(https://en.wikipedia.org/wiki/Free_group).
Indeed we can view a vector of numbers as a word over the alphabet [0,∞) of 
positive real numbers (where negative numbers / zero are inverses of letters in 
our alphabet). The fact that all maximal reductions (reductions which contain 
no adjacent inverses) of a given word are equal means exactly that our reduced 
list is unique.
For a proof see:
https://math.stackexchange.com/a/2425147

I'll look into this problem, it's interesting!
Cheers,
Louis
 
Original Message
From : jimmy.gau...@gmail.com
Date : 06/12/2019 - 23:36 (CEST)
To : programm...@jsoftware.com
Subject : Re: [Jprogramming] Removing annihilating pairs

Hi,

is the expected output of transforming 1 3 _3 3 5 to be 1 3 5 or 1 5 ?

On Fri, Dec 6, 2019 at 7:15 AM R.E. Boss  wrote:

> Given an array with zero or more annihilating pairs, i.e., two subsequent
> numbers which add up to zero, the question is to clean up the array by
> deleting all annihilating pairs such that no such pairs are left.
> I do have a solution that is both elegant and efficient (I believe), but I
> am curious about other thoughts.
>
>foo  2 1 1 _1 2 _2 _1
> 2
>
>foo 1 _1 2 _2{~100?.@#4  NB. Notice (?.)
> 2 1 2 1 _2 _1 2 1 1 2 2 2 _1 2 _1 2 1 2 2 2 1 1 _2 _1 2 1 _2 _1 _2 _2 _2
> _2 _1 _2 _1 _1 _2 _2 1 1 1 2 1 _2 1 _2 _1 _1 _1 2
>
>
> R.E. Boss
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm

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

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


Re: [Jprogramming] Removing annihilating pairs

2019-12-06 Thread Louis de Forcrand
If the answer to Jimmy's question is no, then the uniqueness of the resulting 
array has to do (surprisingly) with free groups 
(https://en.wikipedia.org/wiki/Free_group).
Indeed we can view a vector of numbers as a word over the alphabet [0,∞) of 
positive real numbers (where negative numbers / zero are inverses of letters in 
our alphabet). The fact that all maximal reductions (reductions which contain 
no adjacent inverses) of a given word are equal means exactly that our reduced 
list is unique.
For a proof see:
https://math.stackexchange.com/a/2425147

I'll look into this problem, it's interesting!
Cheers,
Louis
 
Original Message
From : jimmy.gau...@gmail.com
Date : 06/12/2019 - 23:36 (CEST)
To : programm...@jsoftware.com
Subject : Re: [Jprogramming] Removing annihilating pairs

Hi,

is the expected output of transforming 1 3 _3 3 5 to be 1 3 5 or 1 5 ?

On Fri, Dec 6, 2019 at 7:15 AM R.E. Boss  wrote:

> Given an array with zero or more annihilating pairs, i.e., two subsequent
> numbers which add up to zero, the question is to clean up the array by
> deleting all annihilating pairs such that no such pairs are left.
> I do have a solution that is both elegant and efficient (I believe), but I
> am curious about other thoughts.
>
>foo  2 1 1 _1 2 _2 _1
> 2
>
>foo 1 _1 2 _2{~100?.@#4  NB. Notice (?.)
> 2 1 2 1 _2 _1 2 1 1 2 2 2 _1 2 _1 2 1 2 2 2 1 1 _2 _1 2 1 _2 _1 _2 _2 _2
> _2 _1 _2 _1 _1 _2 _2 1 1 1 2 1 _2 1 _2 _1 _1 _1 2
>
>
> R.E. Boss
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm

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


Re: [Jprogramming] Explicit vs tacit with assignment

2019-11-23 Thread Louis de Forcrand
To follow up on all this, while I am a member of the generation which might 
write off "lie", I find that correct grammar and spelling are qualities 
necessary (although certainly not sufficient) for writing clearly and with good 
style, and in learning the former one inevitably improves on the latter.

To break the rules deliberately one must first know where to swing!

Cheers,
Louis

> On 21 Nov 2019, at 18:21, Jose Mario Quintana  
> wrote:
> 
> "By all means break the rules, and break them beautifully, deliberately and
> well."
> 
> Bringhurst, Robert (2005). The Elements of Typographic Style
> 
> PS.  I try to keep that in mind when writing (particularly in J).
> 
> 
>> On Thu, Nov 21, 2019 at 4:26 AM R.E. Boss  wrote:
>> 
>> AMEN.
>> 
>> When you try to uphold the rules of a language (which is done only by
>> older people), you are fighting a lost battle.
>> 
>> 
>> R.E. Boss
>> 
>> 
>>> -Oorspronkelijk bericht-
>>> Van: Programming 
>>> Namens Henry Rich
>>> Verzonden: donderdag 21 november 2019 04:02
>>> Aan: programm...@jsoftware.com
>>> Onderwerp: Re: [Jprogramming] Explicit vs tacit with assignment
>>> 
>>> Think nothing of it.  I was back in the highschool today, talking linear
>> algebra
>>> to the very top layer of the high-performing students, having them write
>>> proofs on the board. It is obvious that the distinction between "its"
>> and "it's"
>>> is not observed in practice, even among these kids who are tomorrow's
>>> elite.  It will be gone in another 100 years.
>>> 
>>> Back when I was teaching Latin, I tried to give examples of the
>> difference
>>> between transitive and intransitive verbs in English. I started,
>>> 
>>> We say "I lay the book on the table: I lay it, I laid it yesterday, I
>> have laid it
>>> there many times."
>>> 
>>> We say "I lie down for a nap.  I lie down, I lay down yesterday, I have
>> lain
>>> down..."
>>> 
>>> the rest of the sentence was drowned out by cries of "No!".  They had
>> never
>>> heard such a thing.  My conclusion: "lie" is dead. Write it off.
>>> 
>>> I have already written off "whom".  The language evolves.
>>> 
>>> Henry Rich
>>> 
>>>> On 11/20/2019 9:52 PM, Louis de Forcrand wrote:
>>>> Just to correct a mistake that I always hate making:
>>>> 
>>>> "... for use after _its_ application ..."
>>>> 
>>>> Sorry for the noise,
>>>> Louis
>>>> 
>>>>> On 21 Nov 2019, at 03:49, Louis de Forcrand  wrote:
>>>>> 
>>>>> (a,a=.?@#) is a verb, namely (?@# , ?@#). In this expression a is set
>> to the
>>> _verb_ ?@# and then train (a,a) is evaluated.
>>>>> 
>>>>> In the second case a is set to the _result_ of ?@# and then (a,a) is
>>> evaluated. To do this tacitly:
>>>>> 
>>>>> (] , ]) @ (?@#)
>>>>> 
>>>>> or more concisely
>>>>> 
>>>>> ,~@?@#
>>>>> 
>>>>> or equivalently (how I would write it)
>>>>> 
>>>>> 2 $ ?@#
>>>>> 
>>>>> As Henry said, to store an intermediate value in a verb's evaluation
>> for use
>>> _after_ it's application, you must use an explicit verb, for example:
>>>>> 
>>>>> ,~ @ (3 : 'a=: y') @ (?@#)
>>>>> 
>>>>> Cheers,
>>>>> Louis
>>>>> 
>>>>>> On 21 Nov 2019, at 03:26, Nimp O  wrote:
>>>>>> 
>>>>>> Hello, simple question.
>>>>>> 
>>>>>> This behaviour surprised me.
>>>>>> 
>>>>>>  (a,a=.?@#)'01234'
>>>>>> 2 4
>>>>>> 
>>>>>>  3 : 'a,a=.?@#y' '01234'
>>>>>> 1 1
>>>>>> 
>>>>>> Why a is not equal to a in the first case? How can I save the roll
>> as an
>>> intermediate result in the tacit version?
>>>>>> Thanks.
>>>>>> 
>>>>>> -- For information about J forums see
>>>>>> http://www.jsoftware.com/forums.htm
>>>> --
>>>> For information about J forums see
>>> http://www.jsoftware.com/forums.htm
>>> 
>>> --
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>> 
> --
> For information about J forums see http://www.jsoftware.com/forums.htm

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


Re: [Jprogramming] (no subject)

2019-11-23 Thread Louis de Forcrand
I believe that as Devon said the subarray selected by m in x m} y must not 
contain any fill elements, which isn't the case of your example as in its case 
the first element of m specifies a length 4 vector while the other two elements 
specify length 2 vectors. This leads to a 2 by 2 matrix of fills (spaces) 
visible (or not) in m{y.

Another workaround is to manually specify all locations individually (which 
isn't too much work):

   n=: 5 8$'O'
   i=: (<0;0 1 2 3),(<1;2 3),<2 4;5
   ]j=: ; {&.> i
+---+---+---+---+---+---+---+---+
|0 0|0 1|0 2|0 3|1 2|1 3|2 5|4 5|
+---+---+---+---+---+---+---+---+
   '=' j} n

OO==
O=OO

O=OO

Cheers,
Louis

> On 23 Nov 2019, at 20:35, Devon McCormick  wrote:
> 
> Not sure why but it seems to have to do with length compatibility of the
> indexes:
> 
>   '='((<0; 0 1 2 3),(<1; 2 3),< 2 4 ; 5)}n
> |domain error
> |   '='((<0;0 1 2 3),(<1;2 3),<2 4;5)}n
> 
> but
> 
>   '='((<0; 0 1 2 3),(<1;2 2 2 3),< 2 2 2 4 ; 5)}n
> 
> OO==
> O=OO
> 
> O=OO
> 
> and
> 
>   (0,&.>0 1 2 3),(1,&.>2 3),2 4,&.>5
> +---+---+---+---+---+---+---+---+
> |0 0|0 1|0 2|0 3|1 2|1 3|2 5|4 5|
> +---+---+---+---+---+---+---+---+
>   '=' ((0,&.>0 1 2 3),(1,&.>2 3),2 4,&.>5) } n
> 
> OO==
> O=OO
> 
> O=OO
> 
> 
> 
>> On Sat, Nov 23, 2019 at 2:19 PM Jimmy Gauvin  wrote:
>> 
>> Hi,
>> 
>> is there any way of making this kind of assignment ?
>> 
>>   '='((<0; 0 1 2 3),(<1; 2 3),< 2 4 ; 5)}n
>> |domain error
>> |   '='((<0;0 1 2 3),(<1;2 3),<2 4;5)}n
>> 
>> But this works :
>>   '='((<1; 2 3),< 2 4 ; 5)}n
>> 
>> OO==
>> O=OO
>> 
>> O=OO
>> 
>> and so does :
>> 
>> ((<0; 0 1 2 3),(<1; 2 3),< 2 4 ; 5){n
>> 
>> 
>> 
>> OO
>> 
>> OO
>> 
>> 
>> 
>> Thanks
>> --
>> 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] Explicit vs tacit with assignment

2019-11-20 Thread Louis de Forcrand
Just to correct a mistake that I always hate making:

"... for use after _its_ application ..."

Sorry for the noise,
Louis

> On 21 Nov 2019, at 03:49, Louis de Forcrand  wrote:
> 
> (a,a=.?@#) is a verb, namely (?@# , ?@#). In this expression a is set to the 
> _verb_ ?@# and then train (a,a) is evaluated.
> 
> In the second case a is set to the _result_ of ?@# and then (a,a) is 
> evaluated. To do this tacitly:
> 
> (] , ]) @ (?@#)
> 
> or more concisely
> 
> ,~@?@#
> 
> or equivalently (how I would write it)
> 
> 2 $ ?@#
> 
> As Henry said, to store an intermediate value in a verb's evaluation for use 
> _after_ it's application, you must use an explicit verb, for example:
> 
> ,~ @ (3 : 'a=: y') @ (?@#)
> 
> Cheers,
> Louis
> 
>> On 21 Nov 2019, at 03:26, Nimp O  wrote:
>> 
>> Hello, simple question.
>> 
>> This behaviour surprised me.
>> 
>>  (a,a=.?@#)'01234'
>> 2 4
>> 
>>  3 : 'a,a=.?@#y' '01234'
>> 1 1
>> 
>> Why a is not equal to a in the first case? How can I save the roll as an 
>> intermediate result in the tacit version?
>> Thanks.
>> --
>> 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] Explicit vs tacit with assignment

2019-11-20 Thread Louis de Forcrand
(a,a=.?@#) is a verb, namely (?@# , ?@#). In this expression a is set to the 
_verb_ ?@# and then train (a,a) is evaluated.

In the second case a is set to the _result_ of ?@# and then (a,a) is evaluated. 
To do this tacitly:

(] , ]) @ (?@#)

or more concisely

,~@?@#

or equivalently (how I would write it)

2 $ ?@#

As Henry said, to store an intermediate value in a verb's evaluation for use 
_after_ it's application, you must use an explicit verb, for example:

,~ @ (3 : 'a=: y') @ (?@#)

Cheers,
Louis

> On 21 Nov 2019, at 03:26, Nimp O  wrote:
> 
> Hello, simple question.
> 
> This behaviour surprised me.
> 
>   (a,a=.?@#)'01234'
> 2 4
> 
>   3 : 'a,a=.?@#y' '01234'
> 1 1
> 
> Why a is not equal to a in the first case? How can I save the roll as an 
> intermediate result in the tacit version?
> Thanks.
> --
> 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] J and data structures

2019-11-19 Thread Louis de Forcrand
A simple use case which resembles the German-English dictionary is to implement 
variable-value bindings in a small interpreter. I've run into this many times 
in what I've been doing lately.

Cheers,
Louis

> On 18 Nov 2019, at 19:38, Raul Miller  wrote:
> 
> Dictionaries might provide a useful optimization for compression algorithms
> 
> For example: https://rosettacode.org/wiki/LZW_compression#J
> 
> See also:
> https://en.wikipedia.org/wiki/DEFLATE
> https://en.wikipedia.org/wiki/LZ77_and_LZ78
> https://en.wikipedia.org/wiki/Prediction_by_partial_matching
> https://en.wikipedia.org/wiki/Burrows%E2%80%93Wheeler_transform
> 
> Thanks,
> 
> 
> --
> Raul
> 
> 
>> On Mon, Nov 18, 2019 at 1:15 PM Devon McCormick  wrote:
>> 
>> I would like to see examples of where a dictionary would be the preferred
>> way of dealing with some data.  Does anyone know of any, not necessarily in
>> J, that are short and to the point?
>> 
>> 
>> On Mon, Nov 18, 2019 at 1:02 PM Danil Osipchuk 
>> wrote:
>> 
>>> I quickly put together a minimal implementation along those lines, to have
>>> a subject for a discussion regarding performance and general usage
>>> An object 'Map has a hash list mapping hash value to other 2 lists -- boxed
>>> lists of boxed keys (per hash value) and boxed  lists of boxed values.
>>> 
>>> It is not thoroughly tested and not well thought through about argument
>>> boxing and ranks, but should be pretty close to what would be a
>>> straightforward implementation of the thing.
>>> 'get_Map key'   should give a boxed value for a key or raise a error if key
>>> is absent
>>> 'somevalue get_Map key' should give a stored value or save and return
>>> somevalue if key is not there (but I can not catch an exception raised in a
>>> monad called from a dyad - something silly, but have to go home)
>>> 'key put__Map value' stores a value
>>> 'delkey__Map key' removes a key if there
>>> 
>>> M=: 0 conew'map'
>>> 
>>> 123 put__M 1230
>>> 
>>> 1230
>>> 
>>> 'strkey' put__M 'strval'
>>> 
>>> strval
>>> 
>>> (<'boxkey') put__M <'boxval'
>>> 
>>> ┌──┐
>>> 
>>> │boxval│
>>> 
>>> └──┘
>>> 
>>> keys__M
>>> 
>>> ┌─┬┬──┐
>>> 
>>> │┌───┐│┌──┐│┌┐│
>>> 
>>> ││123│││strkey│││┌──┐││
>>> 
>>> │└───┘│└──┘│││boxkey│││
>>> 
>>> │ │ ││└──┘││
>>> 
>>> │ │ │└┘│
>>> 
>>> └─┴┴──┘
>>> 
>>> hashes__M
>>> 
>>> _1845511330 2120780259 _71755953
>>> 
>>> values__M
>>> 
>>> ┌──┬┬──┐
>>> 
>>> │┌┐│┌──┐│┌┐│
>>> 
>>> ││1230│││strval│││┌──┐││
>>> 
>>> │└┘│└──┘│││boxval│││
>>> 
>>> │ │ ││└──┘││
>>> 
>>> │ │ │└┘│
>>> 
>>> └──┴┴──┘
>>> 
>>> get__M 123
>>> 
>>> ┌┐
>>> 
>>> │1230│
>>> 
>>> └┘
>>> 
>>> get__M 'not there'
>>> 
>>> |uncaught throw.: get__M
>>> 
>>> | get__M'not there'
>>> 
>>> 'to set to something' get__M 'not there'
>>> 
>>> |uncaught throw.: get
>>> 
>>> | get y
>>> 
>>> delkey__M 123
>>> 
>>> 1
>>> 
>>> get__M 123
>>> 
>>> |uncaught throw.: get__M
>>> 
>>> | get__M 123
>>> 
>>> values__M
>>> 
>>> ┌┬──┐
>>> 
>>> │┌──┐│┌┐│
>>> 
>>> ││strval│││┌──┐││
>>> 
>>> │└──┘│││boxval│││
>>> 
>>> │ ││└──┘││
>>> 
>>> │ │└┘│
>>> 
>>> └┴──┘
>>> 
>>> keys__M
>>> 
>>> ┌┬──┐
>>> 
>>> │┌──┐│┌┐│
>>> 
>>> ││strkey│││┌──┐││
>>> 
>>> │└──┘│││boxkey│││
>>> 
>>> │ ││└──┘││
>>> 
>>> │ │└┘│
>>> 
>>> └┴──┘
>>> 
>>> пн, 18 нояб. 2019 г. в 16:10, Henry Rich :
>>> 
 Right now I am thinking that the need for dictionaries could be met by a
 class whose instances are associative memories.  Key, values,
 hashtables, chains if needed would be stored inside the instance.  The
 interface would be simply x Put y and Get y.  I reckon this would be
 fast enough without any special support from the interpreter beyond the
 hash calculation that is there now.
 
 Henry Rich
 
> On 11/18/2019 6:10 AM, Danil Osipchuk wrote:
> symbols are essentially names optimized for lookup and comparison, as
 such
> they are useful to implement locales efficiently, if one to build an
>>> map
> using those as keys, indeed one gets something resembling K
>>> dictionaries
> http://www.math.bas.bg/bantchev/place/k.html :
> 
> "Another distinguishing feature of K is the use of dictionaries:
> associative tables whose keys are symbols, i.e., internalized strings.
>>> In
> turn, dictionaries are the building material of a hierarchically
 organized
> global data space called the K-tree"
> 
> https://github.com/kevinlawler/kona/wiki/Dictionaries
> 
> This is important case of course, but still a restriction. Tables in
>>> Lua
> are more fundamental:
> 
> "The table type implements associative arrays. An associative array is
>>> an
> array that can be indexed not only with numbers, but also with strings
>>> 

Re: [Jprogramming] Multiple Takes

2019-10-21 Thread Louis de Forcrand
Another (possibly lighter on memory) approach:

~. ; (#:i.2^4) <@(10 #. i.@!@# A. ])@# 0 1 2 6

Cheers,
Louis

> On 21 Oct 2019, at 01:09, Skip Cave  wrote:
> 
> Is there a less-verbose way to list all the integers (one-digit, two-digit,
> three-digit, four-digit) can be formed by using the characters 0, 1, 2, and
> 6 once? I used multiple takes:
> 
> *#b=.~.>10#.ea({1{."1 a),({2{."1 a),({3{."1 a),{a=.(perm 4){0 1 2 6*
> 
> *49*
> 
> *b*
> 
> *0 1 2 6 10 12 16 20 21 26 60 61 62 102 106 120 126 160 162 201 206 210 216
> 260 261 601 602 610 612 620 621 1026 1062 1206 1260 1602 1620 2016 2061
> 2106 2160 2601 2610 6012 6021 6102 6120 6201 6210*
> 
> 
> 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


Re: [Jprogramming] Sorry for the previous messages I neglected to remove from my reply

2019-10-14 Thread Louis de Forcrand
If this makes it any clearer, here is an implementation of /. key:

key=: 1 : 0
=@[ u@# ]
)

where = self-classify can itself be defined as

sc=: ~. -:"_ _1"_1 _ ]

Cheers,
Louis

> On 14 Oct 2019, at 21:26, Raul Miller  wrote:
> 
> I'm not sure what you mean, but consider:
> 
>   'abcba'  +--+--+-+
> |ae|bd|c|
> +--+--+-+
> 
> Basically, any monadic verb that can handle lists of items from the
> right argument will work with /. (but keep in mind that if the results
> have differing lengths, the short results will be padded when
> assembling the result).
> 
> Thanks,
> 
> -- 
> Raul
> 
>> On Mon, Oct 14, 2019 at 3:18 PM 'Jim Russell' via Programming
>>  wrote:
>> 
>> Yes, much. That seems not the case for a character array left argument, thus 
>> my confusion. Thank you!
>> What other arguments/verbs play nice with /,  ?
>> 
 On Oct 14, 2019, at 3:05 PM, Raul Miller  wrote:
>>> 
>>> Ok, try this:
>>> 
>>>  1 2 3 2 1 >> +--+--+-+
>>> |ae|bd|c|
>>> +--+--+-+
>>> 
>>> The nub of the left argument determines the number of items in the
>>> result, but it's not sufficient to determine what's in each box.
>>> 
>>> Is this clearer?
>>> 
>>> Thanks,
>>> 
>>> --
>>> Raul
>>> 
>>> 
 On Mon, Oct 14, 2019 at 1:24 PM 'Jim Russell' via Programming
  wrote:
 
 Sorry, I'm still stuck on u=#. (Or "," or "<" or "[" ). I'll try to 
 understand some harder working verbs, perhaps + or ! or I. or e?
 
>> On Oct 14, 2019, at 12:18 PM, Raul Miller  wrote:
> 
> On Mon, Oct 14, 2019 at 12:06 PM 'Jim Russell' via Programming
>  wrote:
>> Thank you Raul! I thought I was agreeing, until I got to the following:
>> 
 On Oct 14, 2019, at 11:40 AM, Raul Miller  
 wrote:
>>> 
>>> So ... it's the "only the nub" which is relevant here, if you do not
>>> care about the calculation which produces the result.
>> 
>> What calculation? What would be different if (I was allowed to) just 
>> supply (~.x) as a left argument? (Assuming I didn't care to waste the 
>> cycles calculating the nub when it, at least its size,  is going fall 
>> out as a result of looking up each of the eight argument rows).
>> 
>> But I'll accept that I'm missing something; the alternate that Roger 
>> suggested looks like it should do exactly what I was looking for.
> 
> The X U/.Y calculation.
> 
> The order and values of X matter for that calculation, since they control 
> it.
> 
> Thanks,
> 
> --
> Raul
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
 
 --
 For information about J forums see http://www.jsoftware.com/forums.htm
>>> --
>>> 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] A bit-twisting puzzle

2019-07-28 Thread Louis de Forcrand
I am missing something:
a == 0 iff popcnt(a) == 0, so indeed
a == 0 || b == 0
is equivalent to
popcnt(a) == 0 || popcnt(b) == 0
which can be written as
!(popcnt(a) && popcnt(b)),
but if this is translated into a single-branch sequence of machine 
instructions, then wouldn’t
!(a && b)
be as well?

The solution I was thinking of by counting leading zero bits is (with LZCNT 
said instruction, | bitwise or, ~ bitwise not, >> logical shift right, and 32 = 
2^5 bit integers):

LZCNT(a) >> 5 | LZCNT(b) >> 5

Using POPCNT in the same way is also possible:

POPCNT(~a) >> 5 | POPCNT(~b) >> 5

Cheers,
Louis

> On 28 Jul 2019, at 23:49, Roger Hui  wrote:
> 
> If you have thought about this for a year then the following can't be the
> answer, but here it is:
> 
> There is either a popcnt instruction, or you can implement it with
> straight-line code without branching.  Whence:
> if !(popcnt(a)&(b)) stmt;
> 
> 
> 
>> On Sun, Jul 28, 2019 at 5:51 PM Henry Rich  wrote:
>> 
>> Many of the members of this Forum will remember the days of assembler
>> language
>> 
>>   ...and who could less than merry be
>>   when writing out BXLE?
>> 
>> AND, OR, XOR were our meat.  Those days are returning.
>> 
>> You have two integer variables a and b and you want to do something if
>> one or both of them are 0.  In C, you might write
>> 
>>   if(a==0 || b==0)stmt;
>> 
>> but that will generate the code
>> 
>>   cmp a,0
>>   bz stmt
>>   cmp b,0
>>   bnz notstmt
>> stmt:
>> ...
>> notstmt:
>> 
>> Here's the problem: your machine is very slow at branch instructions.
>> Each branch takes 30 times as long as a regular instruction.  (I am
>> describing a state-of-the-art Intel CPU when it cannot predict the
>> branches effectively, perhaps because the data is... unpredictable).
>> 
>> Obviously, you want to use only one branch instruction.  You may use as
>> many arithmetic and logic instructions as you like, but only one
>> branch.  The usual condition codes, ZNCV, are available. How tight can
>> you make the code?
>> 
>> Example: suppose the problem were to execute stmt if one or both of a
>> and b is NOT zero.  Then you would simply write
>> 
>>   or a,b
>>   bnz notstmt
>> ...
>> 
>> Checking for zero seems to be harder.
>> 
>> No hurry.  I have pondered this problem for over a year, and just today
>> I found a solution I consider acceptable.
>> 
>> Henry Rich
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> ---
>> This email has been checked for viruses by AVG.
>> https://www.avg.com
>> 
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>> 
> --
> For information about J forums see http://www.jsoftware.com/forums.htm

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


Re: [Jprogramming] A bit-twisting puzzle

2019-07-28 Thread Louis de Forcrand
Do we have access to an instruction which counts leading zero bits?

Interesting problem,
Louis

> On 28 Jul 2019, at 19:51, Henry Rich  wrote:
> 
> Many of the members of this Forum will remember the days of assembler language
> 
>   ...and who could less than merry be
>   when writing out BXLE?
> 
> AND, OR, XOR were our meat.  Those days are returning.
> 
> You have two integer variables a and b and you want to do something if one or 
> both of them are 0.  In C, you might write
> 
>   if(a==0 || b==0)stmt;
> 
> but that will generate the code
> 
>   cmp a,0
>   bz stmt
>   cmp b,0
>   bnz notstmt
> stmt:
> ...
> notstmt:
> 
> Here's the problem: your machine is very slow at branch instructions.  Each 
> branch takes 30 times as long as a regular instruction.  (I am describing a 
> state-of-the-art Intel CPU when it cannot predict the branches effectively, 
> perhaps because the data is... unpredictable).
> 
> Obviously, you want to use only one branch instruction.  You may use as many 
> arithmetic and logic instructions as you like, but only one branch.  The 
> usual condition codes, ZNCV, are available. How tight can you make the code?
> 
> Example: suppose the problem were to execute stmt if one or both of a and b 
> is NOT zero.  Then you would simply write
> 
>   or a,b
>   bnz notstmt
> ...
> 
> Checking for zero seems to be harder.
> 
> No hurry.  I have pondered this problem for over a year, and just today I 
> found a solution I consider acceptable.
> 
> Henry Rich
> 
> 
> 
> 
> 
> 
> 
> ---
> 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] newbie question about indexing/tabling

2019-07-13 Thread Louis de Forcrand
Quick correction: the answer given by Pascal is not 1019 but P(2166)-P(1019), 
and my email should use that instead of 1019 wherever it is mentioned.

Sorry for the noise,
Louis

> On 14 Jul 2019, at 01:58, Louis de Forcrand  wrote:
> 
> I’m with Skip here: how do y’all guarantee that your brute-force answers 
> (which search through a list of the first few pentagonal numbers) actually 
> return the pair with the smallest _difference_? How do you know there isn’t a 
> pair outside your search range, where each number in the pair is much larger 
> than any you searched but whose difference is smaller?
> 
> One possibility is to find a lower bound B as a function of k for the 
> difference P(n)-P(m), where n>m>k. If B(k) is larger than 1019 (the answer 
> Pascal Jasmin gave) for k outside your search range, then 1019 is indeed the 
> answer.
> A possibility for B is B(k) = P(k+1)-P(k).
> 
> Another idea I had is that since the sum and the difference must both be 
> pentagonal, we can instead search in the same way for them and make sure 
> their half-sum and half-difference (which equal the original numbers) are 
> indeed pentagonal. The first pair we find will be the one we want since by 
> then we’ll have checked all pairs with a smaller difference.
> 
> Do you have a better justification?
> 
> Thanks!
> Louis
> 
>> On 13 Jul 2019, at 01:31, Skip Cave  wrote:
>> 
>> Another approach to Euler 44:
>> NB. make a pentagonal number generator verb:
>>  *pn=.3 :'y*(1-~3*y)%2'*
>> 
>> NB. Generate the first 5000 pentagonal numbers and store them in p. Then
>> find all possible pair combinations of the first 5000 pentagonal numbers
>> and store the pairs in p2. Then store the two integers in each pair in the
>> vectors a & b respectively:
>> * 'a b'=.|:p2=.(2 comb 5000){p=:pn>:i.5000x*
>> 
>> NB. Find and mark all pairs where a+b and a-b are both pentagonal numbers.
>> Store that mark vector in m. Also sum the marks in m to see how many
>> solution pairs we have:
>> * +/m=.(p e. ~a+b) *. p e. ~|a-b*
>> 
>> *1*
>> 
>> NB. So there is only one solution pair in the first 5000 pentagonal
>> numbers. Now use the mark vector to extract that one pair of pentagonal
>> numbers we found that meets all the criteria, store the pair in n, and
>> display them.
>>   * ]n=.m#p2*
>> 
>> *1560090 7042750*
>> 
>> 
>> NB. List a, b, a+b, & a-b of the discovered pair in n=a,b:
>> 
>> * (,n),(+/"1 n),(|-/"1 n) *
>> 
>> *1560090 7042750 8602840 5482660*
>> 
>> 
>> NB. Are the four integers a, b, a+b, & a-b all pentagonal numbers?
>> 
>> *p e.~(,n),(+/"1 n),(|-/"1 n) *
>> 
>> *1 1 1 1*
>> 
>> 
>> NB. Yes. So what is "D" (the difference between the pair) which is required
>> to get the final answer in the euler question?
>> 
>> 
>> *]D=.|-/"1 n*
>> 
>> *5482660*
>> 
>> 
>> However the Euler 44 question wants to find a pentagonal pair where D is
>> minimised, so we will need to expand our search so see if there are
>> pentagonal pairs with a smaller D. Unfortunately, I run into memory limits
>> when I try to examine a larger range of pentagonal numbers. So I'll need to
>> break the one-shot approach into a loop and segment the array of pentagonal
>> numbers (sigh). I'll leave that exercise for the reader...
>> 
>> 
>> 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


Re: [Jprogramming] newbie question about indexing/tabling

2019-07-13 Thread Louis de Forcrand
I’m with Skip here: how do y’all guarantee that your brute-force answers (which 
search through a list of the first few pentagonal numbers) actually return the 
pair with the smallest _difference_? How do you know there isn’t a pair outside 
your search range, where each number in the pair is much larger than any you 
searched but whose difference is smaller?

One possibility is to find a lower bound B as a function of k for the 
difference P(n)-P(m), where n>m>k. If B(k) is larger than 1019 (the answer 
Pascal Jasmin gave) for k outside your search range, then 1019 is indeed the 
answer.
A possibility for B is B(k) = P(k+1)-P(k).

Another idea I had is that since the sum and the difference must both be 
pentagonal, we can instead search in the same way for them and make sure their 
half-sum and half-difference (which equal the original numbers) are indeed 
pentagonal. The first pair we find will be the one we want since by then we’ll 
have checked all pairs with a smaller difference.

Do you have a better justification?

Thanks!
Louis

> On 13 Jul 2019, at 01:31, Skip Cave  wrote:
> 
> Another approach to Euler 44:
> NB. make a pentagonal number generator verb:
>   *pn=.3 :'y*(1-~3*y)%2'*
> 
> NB. Generate the first 5000 pentagonal numbers and store them in p. Then
> find all possible pair combinations of the first 5000 pentagonal numbers
> and store the pairs in p2. Then store the two integers in each pair in the
> vectors a & b respectively:
>  * 'a b'=.|:p2=.(2 comb 5000){p=:pn>:i.5000x*
> 
> NB. Find and mark all pairs where a+b and a-b are both pentagonal numbers.
> Store that mark vector in m. Also sum the marks in m to see how many
> solution pairs we have:
>  * +/m=.(p e. ~a+b) *. p e. ~|a-b*
> 
> *1*
> 
> NB. So there is only one solution pair in the first 5000 pentagonal
> numbers. Now use the mark vector to extract that one pair of pentagonal
> numbers we found that meets all the criteria, store the pair in n, and
> display them.
>* ]n=.m#p2*
> 
> *1560090 7042750*
> 
> 
> NB. List a, b, a+b, & a-b of the discovered pair in n=a,b:
> 
> * (,n),(+/"1 n),(|-/"1 n) *
> 
> *1560090 7042750 8602840 5482660*
> 
> 
> NB. Are the four integers a, b, a+b, & a-b all pentagonal numbers?
> 
> *p e.~(,n),(+/"1 n),(|-/"1 n) *
> 
> *1 1 1 1*
> 
> 
> NB. Yes. So what is "D" (the difference between the pair) which is required
> to get the final answer in the euler question?
> 
> 
> *]D=.|-/"1 n*
> 
> *5482660*
> 
> 
> However the Euler 44 question wants to find a pentagonal pair where D is
> minimised, so we will need to expand our search so see if there are
> pentagonal pairs with a smaller D. Unfortunately, I run into memory limits
> when I try to examine a larger range of pentagonal numbers. So I'll need to
> break the one-shot approach into a loop and segment the array of pentagonal
> numbers (sigh). I'll leave that exercise for the reader...
> 
> 
> 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


Re: [Jprogramming] newbie question about indexing/tabling

2019-07-12 Thread Louis de Forcrand
Hi Daniel,

If the ravel indices into the array M are stored in I, the multi-dimensional 
indices are then

($M) #: I

So for your toy example a possible verb is

v=: $ #: , I.@:= _1:

Cheers,
Louis

> On 12 Jul 2019, at 02:11, Daniel Eklund  wrote:
> 
> Double thanks.
> 
> One for that sparse array trick.  That will go into my toolbox.
> 
> And secondly, for the work you've been putting into the youtube videos -- I
> think they've been an invaluable teaching aid, and a welcome addition to
> the relative paucity of J learning outside of the main website.
> 
> 
> On Thu, Jul 11, 2019 at 7:35 PM 'robert therriault' via Programming <
> programm...@jsoftware.com> wrote:
> 
>> Wow Daniel,
>> I am sincerely impressed at how you wrestled that one to the ground.
>> 
>> A trick I learned a while ago on these forums was the use of Sparse ($.)
>> 
>>toy e. _1
>> 1 0 0 0
>> 0 0 1 1
>> 0 0 0 0
>>   $. toy e. _1  NB. converts dense array to sparse form
>> 0 0 │ 1
>> 1 2 │ 1
>> 1 3 │ 1
>>   4 $. $. toy e. _1 NB. Dyadic 4 $. returns the indices of sparse form
>> 0 0
>> 1 2
>> 1 3
>> 
>> Cheers, bob
>> 
>>> On Jul 11, 2019, at 4:20 PM, Daniel Eklund  wrote:
>>> 
>>> Hi everyone,
>>> 
>>> I’m looking for some newbie help.  I feel I’ve come so far but I’ve run
>>> into something that is making me think I’m not really getting something
>>> fundamental.
>>> 
>>> Rather than try to come up with a contrived example, I’ll just say
>> outright
>>> that I’m trying to solve one of the project Euler questions (problem 44)
>>> and in my desire to use a particular J strategy (‘tabling’) I’m
>> struggling
>>> to deduce how array indexing to recover the input pairs works best.
>>> 
>>> From the question:
>>> 
>>> A pentagonal number is Pn=n(3n−1)/2. The first ten pentagonal numbers
>> are:
>>> 
>>> 1, 5, 12, 22, 35, 51, 70, 92, 117, 145, …
>>> 
>>> The challenge is to find two pentagonal numbers that both added together
>>> and whose difference is also a pentagonal number.
>>> 
>>> Producing pentagonals is easy enough:
>>> 
>>> pentagonal =: [ * ( 1 -~ 3 * ])
>>> 
>>> pentagonal >: i. 5
>>> 
>>> 2 10 24 44 70
>>> 
>>> My plan was then to table both the addition and subtraction
>>> 
>>>  +/~ pentagonal >: i. 5
>>> 
>>> 4 12 26  46 72
>>> 
>>> 12 20 34  54 80
>>> 
>>> 26 34 48  68 94
>>> 
>>> 46 54 68  88 114
>>> 
>>> 72 80 94 114 140
>>> 
>>>  -/~ pentagonal >: i. 5
>>> 
>>> 0 _8 _22 _42 _68
>>> 
>>> 8  0 _14 _34 _60
>>> 
>>> 22 14   0 _20 _46
>>> 
>>> 42 34  20 0 _26
>>> 
>>> 68 60  46 26   0
>>> 
>>> And then fetch the values in the table that were also pentagonal.  This
>>> seems like a sane strategy -- not entirely clever -- but I am running
>> into
>>> something that makes me feel I am missing something essential:  how to
>>> recover the numbers (horizontal row number and column number pair, and
>>> therefore input values) that induced the result.
>>> 
>>> I create myself a toy example to try to understand, by creating a
>> hardcoded
>>> matrix where I’m interested in those that have a certain value:
>>> 
>>> ] toy =: 3 4 $ _1 2 12 9 32 23 _1  NB. _1 will be value of interest
>>> 
>>> _1  2 12  9
>>> 
>>> 32 23 _1 _1
>>> 
>>> 2 12  9 32
>>> 
>>>  toy e. _1  NB. I am searching for _1 (a proxy for a truth function like
>>> "is_pentagonal")
>>> 
>>> 1 0 0 0
>>> 
>>> 0 0 1 1
>>> 
>>> 0 0 0 0
>>> 
>>> I cannot easily find the indices using I., because
>>> 
>>>  I. toy e. _1
>>> 
>>> 0 0
>>> 
>>> 2 3
>>> 
>>> 0 0
>>> 
>>> Has a zero in the first row which is semantically important, but
>>> zero-padding (semantically unimportant) in other locations.
>>> 
>>> I realize I can ravel the answer and deduce (using the original shape)
>> the
>>> indices
>>> 
>>>  I. , toy e. _1
>>> 
>>> 0 6 7
>>> 
>>> NB. The following is ugly, but works
>>> 
>>>  (<.@:%&4 ; 4&|)"0 I. , toy e. _1  NB. The 4 hardcoded is the length
>>> of each item
>>> 
>>> ┌─┬─┐
>>> 
>>> │0│0│
>>> 
>>> ├─┼─┤
>>> 
>>> │1│2│
>>> 
>>> ├─┼─┤
>>> 
>>> │1│3│
>>> 
>>> └─┴─┘
>>> 
>>> And voilà  a table of items of row/column pairs that can be used to fetch
>>> the original inducing values.
>>> 
>>> To get to the point: is there anything easier?  I spent a long time on
>>> NuVoc looking at the “i.” family along with “{“. I  feel like I might be
>>> missing out on something obvious, stipulating that there is probably
>>> another way to do this without tabling and trying to recover the inducing
>>> values.
>>> 
>>> Is my desire, i.e. to table results and simultaneously keep pointers back
>>> to the original values (a matter of some hoop jumping) the smell of an
>>> anti-pattern in J ?
>>> 
>>> Thanks for any input.
>>> 
>>> Daniel
>>> 
>>> PS. In my question I purposefully am ignoring the obvious symmetry of
>>> 
>>> +/~ pentagonal >: i. 5
>>> 
>>> As I am interested in the _general_ case of tabling two different arrays:
>>> 
>>>  (  pentagonal 20+i.6) +/ pentagonal >: i. 5
>>> 
>>> 1182 1190 1204 1224 1250
>>> 
>>> 1304 1312 1326 1346 1372
>>> 
>>> 1432 1440 1454 1474 1500
>>> 

Re: [Jprogramming] How to improve speed searching for substrings using "E."?

2019-07-07 Thread Louis de Forcrand
Hmm,

I’m disappointed the slight « loopiness » of my solutions makes them that much 
slower than the naïve approach :(
There probably is however little inclusion among random words, maybe try again 
with, say, the first 1 words? :)

Also, there is special code for calculating +/x E.y as x +/@:E. y; try the 
following modification of your verb (probably won’t be much faster but will 
definitely use less space):

naiveS=: 3 : 0
 joined=. ; (,&'|')&.> y
  y #~ 1 = +/@E.@> y
)

Will keep thinking!
Louis

PS: If naiveS isn’t any better try +/@:E. instead of +/@E., as only the former 
is actually listed in the special code section of the dictionary even though 
they are equivalent.

> On 7 Jul 2019, at 20:15, vadim .  wrote:
> 
> Hi, Louis,
> 
> I've got mixed results here. The "cmaxs" solution is, indeed, fastest
> so far, but (1) even then I'm not brave enough to test it against more
> than 1 lines (certainly not "millions"), and, (2) perhaps because
> of "words_alpha" (simple arrays of characters) as test subject, very
> naive approach wins.
> 
>   s =. freads 'words_alpha.txt'
>   lines =: <;._2 s
>   lines1 =: (1 ?. #lines) { lines
> 
>   ts 'fastincl lines1'
> 17.6488 190720
>   ts 'recincl lines1'
> 16.871 3.3762e7
>   ts '(P cmaxs L) lines1'
> 7.76267 395264
>   ts 'naive lines1'
> 1.47661 1.07415e9
> 
> Where "naive" follows aforementioned Perl approach, except it doesn't
> stop searching after second match, and its huge memory appetite (my
> fault? could it be written better?) won't allow more than ~1
> samples anyway (FWIW, Perl script, though on different randomly chosen
> shuffled 1 lines, completes in 1.1 sec and of course doesn't eat 1
> Gb of RAM).
> 
>   naive =: 3 : 0
> joined =. ;(,&'|')&.> y
> (1&= +/"1 y ((>@:[)E.])"0 _ joined)#y
> )
> 
> On the other hand, I appreciate that your solutions are very general,
> thank you for shedding the light on correct path. E.g. "P" can be
> easily replaced to test for unordered subsets instead. Then another
> dilemma, whether repeated part numbers are allowed on one line...
> 
> Best regards,
> Vadim
> 
>> On Sat, Jul 6, 2019 at 5:35 AM Louis de Forcrand  wrote:
>> 
>> Hi again,
>> 
>> I’m back with a speedier solution.
>> comaxs is a conjunction, and if P is a boolean-valued dyadic verb and L any 
>> monadic verb on the items of the array A, P comaxs L A does the following:
>> 
>> P and L are supposed to represent orderings on the elements of y. P 
>> represents a partial order, such that x P y says whether x is less than or 
>> equal to y for x and y any items of A. L is a “labelling” of the items of A, 
>> which represents a _total_ order compatible with P, in the sense that x P y 
>> implies that (L x) <: L y (or more generally that L x comes first in /:~(L 
>> x),L y).
>> 
>> Then the result of the computation is the set of maximal items of A for the 
>> partial order P, that is, items not less than any other item.
>> 
>> As mentioned earlier, the particular problem of inclusion of part number 
>> lists is a special case of this; indeed we can take
>> 
>> P=: +./@E.&>
>> L=: #@>
>> 
>> since, for part number lists (or any kind of lists) x and y, if x is 
>> included in y, then certainly #x is no larger than #y.
>> 
>> To measure performance we need a big, rather random dataset. Unfortunately I 
>> don’t know of any place I can find huge lists of part numbers, some of which 
>> include others, but if we look instead at lists of letters, we have a great 
>> data source which is the dictionary. At the following website we can find a 
>> quite huge file words_alpha.txt containing lots (too many for any of my 
>> devices probably) of english words, many of which are included in others:
>> 
>> https://github.com/dwyl/english-words
>> 
>> Running freads on it allows us to try out cmaxs on a part of the English 
>> language. Sadly though I’m on my phone right now, and I can’t freads 
>> downloaded files, so either I’ll do it at a later time or someone else can 
>> try.
>> 
>> The code works thanks to the previous observation used in fastmax that we 
>> can safely remove an element a from A that is included in another element, 
>> and no longer check other items for inclusion in a. The reason this verb is 
>> much faster than fastmax is because now we also know that if #x is greater 
>> than #y then we never have to check if x is included in y. (More generally, 
>> (L x) > L y implies -. x P y.)
>> We therefore sort A by decreasing list length (L value) prior to running a 
>> modified version of fastmax which only checks if  (i{A) P (j{A) when i > j.
>> The last bit if speedup if achieved by manipulating bit arrays rather than 
>> the actual array A itself.
>> 
>> Cheers,
>> Louis
>> 
>> 
>> cmaxs=: 2 : 0
>> n=. #B=. 0"0 C=. 1"0 y=. (\: v) y
>> while. n>i=. C i.1 do.
>>  B=. 1 i}B
>>  C=. 0 i}C
>>  C=. -.@:u&(i{y)&.(C

Re: [Jprogramming] How to improve speed searching for substrings using "E."?

2019-07-05 Thread Louis de Forcrand
Hi again,

I’m back with a speedier solution.
comaxs is a conjunction, and if P is a boolean-valued dyadic verb and L any 
monadic verb on the items of the array A, P comaxs L A does the following:

P and L are supposed to represent orderings on the elements of y. P represents 
a partial order, such that x P y says whether x is less than or equal to y for 
x and y any items of A. L is a “labelling” of the items of A, which represents 
a _total_ order compatible with P, in the sense that x P y implies that (L x) 
<: L y (or more generally that L x comes first in /:~(L x),L y).

Then the result of the computation is the set of maximal items of A for the 
partial order P, that is, items not less than any other item.

As mentioned earlier, the particular problem of inclusion of part number lists 
is a special case of this; indeed we can take

P=: +./@E.&>
L=: #@>

since, for part number lists (or any kind of lists) x and y, if x is included 
in y, then certainly #x is no larger than #y.

To measure performance we need a big, rather random dataset. Unfortunately I 
don’t know of any place I can find huge lists of part numbers, some of which 
include others, but if we look instead at lists of letters, we have a great 
data source which is the dictionary. At the following website we can find a 
quite huge file words_alpha.txt containing lots (too many for any of my devices 
probably) of english words, many of which are included in others:

https://github.com/dwyl/english-words

Running freads on it allows us to try out cmaxs on a part of the English 
language. Sadly though I’m on my phone right now, and I can’t freads downloaded 
files, so either I’ll do it at a later time or someone else can try.

The code works thanks to the previous observation used in fastmax that we can 
safely remove an element a from A that is included in another element, and no 
longer check other items for inclusion in a. The reason this verb is much 
faster than fastmax is because now we also know that if #x is greater than #y 
then we never have to check if x is included in y. (More generally, (L x) > L y 
implies -. x P y.)
We therefore sort A by decreasing list length (L value) prior to running a 
modified version of fastmax which only checks if  (i{A) P (j{A) when i > j.
The last bit if speedup if achieved by manipulating bit arrays rather than the 
actual array A itself.

Cheers,
Louis


cmaxs=: 2 : 0
 n=. #B=. 0"0 C=. 1"0 y=. (\: v) y
 while. n>i=. C i.1 do.
  B=. 1 i}B
  C=. 0 i}C
  C=. 

Re: [Jprogramming] How to improve speed searching for substrings using "E."?

2019-06-30 Thread Louis de Forcrand
woops!

Sorry, I changed the name of the adverb before sending the message (to 
something more descriptive than mxs3 :) but I forgot to switch the recursive 
call. Replace mxs3 by recmax and you should be good!

Louis

> On 30 Jun 2019, at 17:59, vadim .  wrote:
> 
> It's amazing. Thank you so much. I'm not yet comfortable with defining
> my own adverbs, and you show me constructs like 

Re: [Jprogramming] How to improve speed searching for substrings using "E."?

2019-06-30 Thread Louis de Forcrand
Hi again,

I haven’t much time right now, but I’ve come up with two new programs:

fastmax=: 1 : 0
 B=. C=. 1"_1 y
 while. +./C do.
  i=. C i.1
  B=. 0 i} B
  B=. 

Re: [Jprogramming] How to improve speed searching for substrings using "E."?

2019-06-30 Thread Louis de Forcrand
Hi,

Try this:

maxs=: 1 : 0
 for_i. i.-#y do.
  if. (i{y) +./@:u (<<

fast=: cmp maxs   NB. fast
fstr=: fast@(\: #@>)NB. faster?

maxs is a generic adverb that takes a boolean-valued verb and an array.
The verb represents a partial order on the elements of the array, and maxs 
returns the set of maximal elements of the array, that is those which are 
strictly less than no other element (and also removes duplicates of those 
elements).

This applies to the current problem as substring inclusion <= is a partial 
order (reflexivity: x <= x is always true; antisymmetry: x <= y <= x implies x 
= y; and transitivity: x <= y <= z implies x <= z).
cmp is the partial order at hand, and fast is the corresponding verb.

The key observation is that if we look at one element y and find that y <= z, 
we can safely remove y from the array and continue our search for maximal 
elements without comparing against y as, if for some x we have x <= y, then by 
transitivity x <= z and x will be removed anyway even if y is already gone.

This should give a pretty good speedup when there is a lot of repetition / 
inclusion.

Another thing to try for this particular problem when you have lines with a 
wide range of different sizes, is to sort the lines in decreasing order of 
lengths. This could give some benefit as short lines are more probable to be 
included in others, and maxs removes array elements starting from the end of 
the array and so with a little luck quickly does much less work.
The corresponding verb is fstr.

In the end though I don’t know how much better than quadratic time you can hope 
for, as with the current specification it doesn’t seem obvious to keep from 
comparing most elements to all the others.

Might come back with some more ideas.

Cheers!
Louis

> On 28 Jun 2019, at 20:20, Raul Miller  wrote:
> 
> Does order of the substrings matter? (In other words, would it be ok to
> treat 'B002|A001' like 'A001|B002'?)  -- Why or why not?
> 
> Are all the part numbers equal width?
> 
> Would any of the lines be duplicates of other lines? If so, how should that
> be handled?
> 
> My inclination would be to build a list of unique part numbers, replace
> each line with a list of indices into then treat this as a numeric problem
> (probably using sorting, possibly grouping the lines based on length). But
> to do that properly, I would need a deeper understanding of the
> requirements.
> 
> Thanks,
> 
> -- 
> Raul
> 
>> On Friday, June 28, 2019, vadim .  wrote:
>> 
>> Example: given a file (a string), where each line is list of part
>> numbers with separators, how to exclude lines which are substrings of
>> other lines (cut on separators)? E.g. (first line is to be excluded):
>> 
>>   z =: 0 : 0
>> A001|B002
>> C003|A001|B002
>> B002|A001
>> C003|D004|A001
>> E005|F006
>> D004|C003
>> )
>>   [lines =: <;._2 z
>> +-+--+-+--+-+-+
>> |A001|B002|C003|A001|B002|B002|A001|C003|D004|A001|E005|F006|D004|C003|
>> +-+--+-+--+-+-+
>>   [syms =: (s:@:('|'&,))&.> lines
>> +---+-+---+-
>> +---+---+
>> |`A001 `B002|`C003 `A001 `B002|`B002 `A001|`C003 `D004 `A001|`E005
>> `F006|`D004 `C003|
>> +---+-+---+-
>> +---+---+
>>   (+./@:E.)&.(> :.])/~ syms
>> 1 1 0 0 0 0
>> 0 1 0 0 0 0
>> 0 0 1 0 0 0
>> 0 0 0 1 0 0
>> 0 0 0 0 1 0
>> 0 0 0 0 0 1
>>   [idx =: 1&= +/"1 (+./@:E.)&.(> :.])/~ syms
>> 0 1 1 1 1 1
>>   [result =: idx#lines
>> +--+-+--+-+-+
>> |C003|A001|B002|B002|A001|C003|D004|A001|E005|F006|D004|C003|
>> +--+-+--+-+-+
>> 
>>   I'm worried about performance of this line:
>> 
>> (+./@:E.)&.(> :.])/~ syms
>> 
>> other details are not very important, as I'm only learning. Phrase
>> above uses form "+./@:E.", recommended for speed in J Wiki. I think
>> table adverb must be optimized, too. But, adding some weight:
>> 
>>   z =: 0 : 0
>> 2N0472|6N8595|9L1366|1189902|1413983|8B2026|1M3381|7K3377|
>> 3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|
>> 6Y1352|4P0489|2757803
>> 3419308|3514531|3525716|3557019|3586192|3635776|3783741
>> 3T3625|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854
>> 3T3625|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|
>> 3H5788|1F7854|8W1152|8R0721
>> 3T3628|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|
>> 3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|
>> 6Y1352|4P0489|1336934
>> 4N4906|6N6481|9L1366|1189902|1413983|8B2026|1M3381|7K3377
>> 4N4906|6N6481|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788
>> 6N7936|6N5049|9L1366|1189902|1413983|8B2026|1M3381|7K3377|
>> 3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|
>> 6Y1352|4P0489|2757803
>> 6Y0248|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|
>> 

Re: [Jprogramming] ambivalent tacit verb with Self-Reference

2019-05-05 Thread Louis de Forcrand
Doh. padop can easily be a verb:

   pad=: ];.0@((+$) {. ])^:2
   2 1 pad&.> (i.2 3); i.2 2 2
+-+---+
|0 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 2 0 0|0 0 0 0|
|0 0 3 4 5 0 0|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 0|
| |0 2 3 0|
| |0 0 0 0|
| |   |
| |0 0 0 0|
| |0 4 5 0|
| |0 6 7 0|
| |0 0 0 0|
| |   |
| |0 0 0 0|
| |0 0 0 0|
| |0 0 0 0|
| |0 0 0 0|
+-+---+

Sorry for the extra noise!
Louis

> On 5 May 2019, at 17:25, Louis de Forcrand  wrote:
> 
> Hi,
> 
> Not exactly an answer to the question, but rather a cute way to pad an array 
> of any rank using a cool feature of ;. cut that I ran into today.
> From the dictionary:
> 
> u;.0 y applies u to y after reversing y along each axis; it is equivalent to 
> (0 _1 */$y) u;.0 y .
> 
> Using this:
> 
>   padop=: &((+$) {. ]) (;.0) (^:2)
>   2 padop i.2 3
> 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0
> 0 0 0 1 2 0 0
> 0 0 3 4 5 0 0
> 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0
>   1 padop i.2 2 2
> 0 0 0 0
> 0 0 0 0
> 0 0 0 0
> 0 0 0 0
> 
> 0 0 0 0
> 0 0 1 0
> 0 2 3 0
> 0 0 0 0
> 
> 0 0 0 0
> 0 4 5 0
> 0 6 7 0
> 0 0 0 0
> 
> 0 0 0 0
> 0 0 0 0
> 0 0 0 0
> 0 0 0 0
> 
> Unfortunately padop must be an adverb in order to be tacit (unless there is 
> maybe some wicked way). The corresponding explicit verb could be used for a 
> default left argument.
> 
> Anyway just an illustration of one of cut’s many powers that I probably often 
> overlook.
> 
> Cheers,
> Louis
> 
>> On 5 May 2019, at 09:44, 'robert therriault' via Programming 
>>  wrote:
>> 
>> Hi Linda,
>> 
>> I think that the trick is that the left operand for ^: needs to be a verb. 
>> this seems to work.
>> 
>>   f=:(0 ,.~ 0 ,. 0 ,~ 0 , ])^:[
>>  1 f i. 3 4
>> 0 0 0  0  0 0
>> 0 0 1  2  3 0
>> 0 4 5  6  7 0
>> 0 8 9 10 11 0
>> 0 0 0  0  0 0
>>  g=: 4 : '(0 ,.~ 0 ,. 0 ,~ 0 , ])^:x y'
>>  1 g i. 3 4
>> 0 0 0  0  0 0
>> 0 0 1  2  3 0
>> 0 4 5  6  7 0
>> 0 8 9 10 11 0
>> 0 0 0  0  0 0
>> 
>> Cheers, bob
>> 
>>> On May 5, 2019, at 12:36 AM, Linda Alvord  wrote:
>>> 
>>> f=:(0 ,.~ 0 ,. 0 ,~ 0 , ])^:[
>> 
>> --
>> 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] ambivalent tacit verb with Self-Reference

2019-05-05 Thread Louis de Forcrand
Hi,

Not exactly an answer to the question, but rather a cute way to pad an array of 
any rank using a cool feature of ;. cut that I ran into today.
From the dictionary:

u;.0 y applies u to y after reversing y along each axis; it is equivalent to (0 
_1 */$y) u;.0 y .

Using this:

   padop=: &((+$) {. ]) (;.0) (^:2)
   2 padop i.2 3
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 1 2 0 0
0 0 3 4 5 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
   1 padop i.2 2 2
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0

0 0 0 0
0 0 1 0
0 2 3 0
0 0 0 0

0 0 0 0
0 4 5 0
0 6 7 0
0 0 0 0

0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0

Unfortunately padop must be an adverb in order to be tacit (unless there is 
maybe some wicked way). The corresponding explicit verb could be used for a 
default left argument.

Anyway just an illustration of one of cut’s many powers that I probably often 
overlook.

Cheers,
Louis

> On 5 May 2019, at 09:44, 'robert therriault' via Programming 
>  wrote:
> 
> Hi Linda,
> 
> I think that the trick is that the left operand for ^: needs to be a verb. 
> this seems to work.
> 
>f=:(0 ,.~ 0 ,. 0 ,~ 0 , ])^:[
>   1 f i. 3 4
> 0 0 0  0  0 0
> 0 0 1  2  3 0
> 0 4 5  6  7 0
> 0 8 9 10 11 0
> 0 0 0  0  0 0
>   g=: 4 : '(0 ,.~ 0 ,. 0 ,~ 0 , ])^:x y'
>   1 g i. 3 4
> 0 0 0  0  0 0
> 0 0 1  2  3 0
> 0 4 5  6  7 0
> 0 8 9 10 11 0
> 0 0 0  0  0 0
> 
> Cheers, bob
> 
>> On May 5, 2019, at 12:36 AM, Linda Alvord  wrote:
>> 
>> f=:(0 ,.~ 0 ,. 0 ,~ 0 , ])^:[
> 
> --
> 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] Is there an 'inverse" to evoke

2019-05-03 Thread Louis de Forcrand
If you mean a textual representation of the array y, check ": .
Otherwise if you want something like this

   var=: i.3
   'var' -: v var
1

then I doubt that such a v exists.

Cheers,
Louis

> On 3 May 2019, at 12:58, Piet de Jong  wrote:
> 
> If m is the name (ie string) of a variable then ‘m'~ is the value of the 
> variable.
> 
> Is there an “inverse" to this?
> 
> That is I want a verb v (or adverb or conjunction) so that if y is a variable 
> then
> 
> v y 
> 
> is the name (ie string) of the variable.
> 
> 
> 
> 
> 
> --
> 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] Applying different verbs to different items.

2019-05-03 Thread Louis de Forcrand
This subject regularly pops up every now and then, and it reminds me of 
something I wrote a little while back that might interest you. I found a couple 
of errors in them (oops) so I’m copying them here in hope that they are of help 
to you. They aren’t pretty or succinct but they work. (Code at bottom.)

These are versions of the composition conjunctions which depend on their right 
operand verb’s rank (that is, @, &, and &.), that take as left operand a 
gerund, and apply successive verbs in the gerund to the successive results of 
applying its right operand to successive cells of its right argument (or 
between its left and right arguments). The gerund is extended cyclically.

The above sentence being far too long for comprehension, an example imposes 
itself:
   M=: i.3 4 5
   (,: -`j. under >) ;/M
┌───┬┬───┐ │ 0 1 2 3 4 
│20 21 22 23 24 │40 41 42 43 44 │ │ 5 6 7 8 9 │25 26 27 28 29 │45 46 47 48 49 │ 
│10 11 12 13 14 │30 31 32 33 34 │50 51 52 53 54 │ │15 16 17 18 19 │35 36 37 38 
39 │55 56 57 58 59 │ 
├───┼┼───┤ │ 0 _1 _2 _3 
_4│0j20 0j21 0j22 0j23 0j24│_40 _41 _42 _43 _44│ │ _5 _6 _7 _8 _9│0j25 0j26 
0j27 0j28 0j29│_45 _46 _47 _48 _49│ │_10 _11 _12 _13 _14│0j30 0j31 0j32 0j33 
0j34│_50 _51 _52 _53 _54│ │_15 _16 _17 _18 _19│0j35 0j36 0j37 0j38 0j39│_55 _56 
_57 _58 _59│ └───┴┴───┘

What you’re looking for is probably rank:

   >:`<:`+:`-: rank 0 i.4
1 0 4 1.5
   >:`<:`+:`-: rank 1 i.4 3
  1  2   3
  2  3   4
 12 14  16
4.5  5 5.5
   1 +`- rank 0 1 ] i.2 3
 1  2  3
_2 _3 _4

Cheers,
Louis

Code:

temp=: 2 : 0NB. utility
[: (v^:_1@(4 : 'y`:6  >x')"0 m $~ $) <@v
)

NB. @
atop=: 2 : 'm temp (v :. ])'

NB. &.
under=: 2 : 0
m temp v : ([: (v^:_1@(4 : 'y`:6&>/>x')"0 m $~ $) <@,&<)
)

NB. &
compose=: 2 : 'm under (v :. ])'

NB. "
rank=:  2 : 'm compose (]"n)'
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] complex x in Copy

2019-04-27 Thread Louis de Forcrand
Sorry! Misunderstood / read too fast.
Devon’s using expand is the way to go. Does this do what you want?

   ]t=: 0,.#:0 14 14 0
0 0 0 0 0
0 1 1 1 0
0 1 1 1 0
0 0 0 0 0
   (,t) #inv ,10+i.2 3
0 0 0 0 0 0 10 11 12 0 0 13 14 15 0 0 0 0 0 0

Hope this is better,
Louis

> On 27 Apr 2019, at 17:31, Brian Schott  wrote:
> 
> Devon, your result looses the middle zero's, but may be the only way to go.
> I'll have to play more with your idea, or find another solution
> 
> Louis,
> 
> That helps a little, but I want my result to start with 6 zeros.
> So I want x#10 11 12 to produce 0 0 0 0 0 0 10 11 12 .
> 
> But instead I can only get results like the following.
> 
>   1j6 1 1 # 10 11 12  NB. 10 in the wrong place
> 10 0 0 0 0 0 0 11 12
>   0j6 1 1 # 10 11 12  NB. where's the 10?
> 0 0 0 0 0 0 11 12
> --
> 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] nubsieve modulo rotation

2019-02-17 Thread Louis de Forcrand
f=: |.~ 3 : 0
... (explicit code here)

is simply a hook which acts the same as

g= |.~ t
t=: 3 : 0
...

I was also very surprised to see this could be done the first time I ran into 
it!

Cheers,
Louis

> On 17 Feb 2019, at 13:03, R.E. Boss  wrote:
> 
> I am embarrassed to admit I don't understand the construction (|.~ 3 : 0)  .
> Even worse, I cannot find where it is documented.
> Please enlighten me.
> 
> 
> R.E. Boss
> 
> 
>> -Oorspronkelijk bericht-
>> Van: Programming 
>> Namens ol...@bluewin.ch
>> Verzonden: zaterdag 16 februari 2019 18:53
>> Aan: programm...@jsoftware.com
>> Onderwerp: Re: [Jprogramming] nubsieve modulo rotation
>> 
>> I rewrote two explicit and perhaps clearer versions of my sig verb. Both work
>> on the same principle as the original, but one uses a bit vector and the 
>> other
>> uses a list of indices, and the indices are a bit faster (pun probably 
>> intended).
>> I prefer the bit vector aesthetically though.
>> 
>> Both basically store the set of indices where possible lexicographically
>> minimal rotations could start (b and i in the verbs). On iteration n, the 
>> starting
>> index of rotations whose nth element is not minimal among the nth
>> elements of all possibly minimal rotations are removed from the
>> aforementioned set. The iteration continues until only one possible rotation
>> is left, and for a maximum of #y times, in which case all elements of y are
>> identical and so any rotation will do.
>> 
>> If I am not mistaken (I might be, have to hurry and go now), since there are 
>> a
>> maximum of #y iterations and each includes at most #y comparisons (= <./),
>> the number of comparisons is at worst quadratic in the length of y. This
>> happens when 1=#~.y, but most of the time this number is much smaller.
>> 
>> sigb=: (|.~ 3 : 0)"1
>> b=. 1"0 y
>> for. y do.
>>  if. 1 = +/b do. break. end.
>>  b=. (= 

Re: [Jprogramming] nubsieve modulo rotation

2019-02-13 Thread Louis de Forcrand
A possible version of the signature verb:

   sig=: |.~ >:@(# -~ {: i. 1:)@min
   min=: (_1 |. ] #^:_1 (= <./)@#~)^:(1 < +/@])^:a: 1"0

Perhaps not the fastest version, but it’s light on memory.

Cheers,
Louis

> On 13 Feb 2019, at 18:52, Roger Hui  wrote:
> 
> Yes, well, left as an exercise for the reader. :-)
> 
> Idea: the minimum rotation of a vector necessarily begins with its minimal
> item.
> 
>> On Wed, Feb 13, 2019 at 9:34 AM Henry Rich  wrote:
>> 
>> Yes; but now suppose the lines are very long.  Is there a way to find
>> the signature (I would call it a canonical form) that doesn't require
>> enumerating rotations?  (I haven't found a good way yet).
>> 
>> Henry Rich
>> 
>>> On 2/13/2019 12:16 PM, Roger Hui wrote:
>>> For each row, find a "signature", then find the nub sieve of the
>>> signatures.  The signature I use here is the minimum of all possible
>>> rotations.
>>> 
>>>signature=: {. @ (/:~) @ (i.@# |."0 1 ])
>>> 
>>>~: signature"1 a
>>> 1 1 1 1 1 0 1 1 1 1 1 0
>>> 
>>> 
>>> 
>>> 
 On Wed, Feb 13, 2019 at 8:55 AM R.E. Boss  wrote:
 
 Let the 12 x 20 matrix be defined by
 a=: 0 : 0
  1  4  4  1 _4 _4  1  1 _4 _1 _1 _4 _4 _1  4  4 _1 _1  4  1
  1  4  4  1 _4 _4  1  1 _4 _1 _1 _4 _4 _1  4  1  4 _1 _1  4
  1  4  4  1 _4 _1 _4  1  1 _4 _1 _4 _4 _1  4  1  4 _1 _1  4
  4  1  1  4 _1  4  1 _4 _4  1 _4 _1 _1 _4  1 _4 _1  4  4 _1
  4  1  1  4 _1  4  1 _4 _4  1  1 _4 _1 _1 _4 _4 _1  4  4 _1
 _1  4  1  1  4  4  1 _4 _4  1  1 _4 _1 _1 _4 _4 _1  4  4 _1
 _1  4  4 _1 _4 _4 _1 _1 _4  1  1 _4 _4  1  4  4  1  1  4 _1
 _1  4  4 _1 _4 _4 _1 _1 _4  1  1 _4 _4  1  4 _1  4  1  1  4
 _1  4  4 _1 _4  1 _4 _1 _1 _4  1 _4 _4  1  4 _1  4  1  1  4
  4 _1 _1  4  1  4 _1 _4 _4 _1 _4  1  1 _4 _1 _4  1  4  4  1
  4 _1 _1  4  1  4 _1 _4 _4 _1 _1 _4  1  1 _4 _4  1  4  4  1
  1  4 _1 _1  4  4 _1 _4 _4 _1 _1 _4  1  1 _4 _4  1  4  4  1
 )
 
 Required is the nubsieve for the items modulo rotation.
 So two arrays are considered to be equal if one is a rotation of the
>> other.
 
 The answer I found is
 1 1 1 1 1 0 1 1 1 1 1 0
 
 
 R.E. Boss
 --
 For information about J forums see http://www.jsoftware.com/forums.htm
>>> --
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>> 
>> 
>> ---
>> This email has been checked for viruses by AVG.
>> https://www.avg.com
>> 
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] (no subject)

2018-12-16 Thread Louis de Forcrand
Hi,

This is very similar to what you’re doing (you have to transpose the result to 
get exactly what you want):

   AC=: ({.~ -@>:@#) {~ #\ *"1 [: #:@i. 2 ^ #
   |:AC 'PNDQ'


  DD  DD  DD  DD
 Q Q Q Q Q Q Q Q


This one is quite cute if you don’t care about the aligning of the columns, but 
it only works for vectors, and a space / zero must be appended at the end of 
the vector:

   (] , (,. ,.))/'PNDQ '
 
Q
D
DQ   
N
NQ   
ND   
NDQ  
P
PQ   
PD   
PDQ  
PN   
PNQ  
PND  
PNDQ 


Cheers,
Louis

> On 16 Dec 2018, at 02:50, lindaalvord  wrote:
> 
> 
> In 1984 I wrote a little paperback called “Probility in APL”. I have been 
> thinking about combination. So I translated three verbs to provide all the 
> ways ‘PNDQ’ or a penny, nickel,
> dime and quarter could be combined.
>  
> Possible outcomes:
> po=: 13 :'|:y#:i.*/y'
> po 2 2 2 2
> 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
> 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1
> 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
> 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
> Correction matrix: (array)
>  
> cm=: 13 :'(*/y)(#"0) 0,}:+/y' 
> cm 2 2 2 2
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
> 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
> 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
> All combinations as chafacters:
>  
> ac=: 13 :'((po + cm) ($y)#2){,'' '',.y'
> ac 'PNDQ'
> 
>  
> DD DD DD DD
> Q Q Q Q Q Q Q Q
> Each column is possible combination of the coins.
>  
> I’m interested to know a better way to get this conclusion.
>  
> Linda
>  
>  
> 
> Sent from my Verizon, Samsung Galaxy smartphone
> --
> 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] Class sort

2018-12-12 Thread Louis de Forcrand
Hi,

R. E. Boss’s thread gave me an idea for an interesting problem:
Given two vectors v and s of the same length, find the permutation w of v such 
that

((s=x)#w) -: /:~(s=x)#v

for any scalar x in s.

I have two solutions; the first is more obvious and relies on the key adverb 
and boxing, whereas the second (more elegant IMO) uses no boxing and relies on 
the grade verb, much like progressive dyadic index and company:

   r=:   /:@/:
   csk=: r@[ { <@/:~/. ;@/: ~.@[
   prm=: (] {~ r@:{~ i. r@[) /:
   csr=: prm { ]

csk uses key and can be generalized to apply operations other than sorting to 
each class in v.
csr is faster though (on my phone in j701 at least), and uses prm which 
generates the permutation corresponding to the desired operation first.

Here is an example where s -: -*v, so elements in the result must match the 
sign of the corresponding element in v:

   v
4 3 _2 _5 1 _4 _3 0 _1 2
   -s
1 1 _1 _1 1 _1 _1 0 _1 1
   s srt v
4 9 3 5 1 6 2 7 8 0
   s csr v
1 2 _5 _4 3 _3 _2 0 _1 4


I’d be curious to see what elegant solutions the forum can come up with!

Cheers,
Louis

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

Re: [Jprogramming] Cute solution

2018-12-12 Thread Louis de Forcrand
> On 12 Dec 2018, at 17:26, R.E. Boss  wrote:
> 
> Foo=: (\: %)

Very nice! Here’s mine:

Foo=: /: <&0 ,. ]

Cheers,
Louis

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

Re: [Jprogramming] Tacit form: How to handle intermediate result..?

2018-09-04 Thread Louis de Forcrand
I sent this message earlier today, but it seems that I used the wrong email 
address. I didn’t find it in the forum archives; sorry if it comes in twice.
I see that most of what I said has since been covered by Mike.

~~~

I would’ve done it this way; the semi-perimeter is not stored, but rather 
passed through the subtraction by subtracting 0.

   H=: [: %: -:@(+/) */ . - ,&0
   H 3 4 5
6

Heron’s formula is in fact a special case the more general Brahmagupta formula 
for calculating the area of a quadrilateral with sides a b c d inscribed in a 
circle:

A = sqrt( (s-a)(s-b)(s-c)(s-d) )

and a triangle is a quadrilateral with one side of length 0, and is always 
inscribed in a circle.
This formula I would implement like this:

   A=: %:@(*/ . -~ [: -: +/)
   A 1 1 1 1
1
   A 2 2 2 2
4
   A 3 4 5 0
6

In the last example of the same triangle as before, the semi-perimeter is 
effectively passed through the subtraction, inspiring the definition of H.

Louis

> On 4 Sep 2018, at 13:50, Martin Kreuzer  wrote:
> 
> Hi all -
> 
> To calculate the area of a flat triangle, using Heron's formula,
> A(a,b,c)= sqrt( s2*(s2-a)*(s2-b)*(s2-c) )
> I wrote a simple function doing this:
> 
> * get the three sides (as list input y)
> * compute the half  perimeter s2
> * build the differences s2-y
> * build product
> * take square root
> 
> My explicit solution looks like this
> 
> taher=: 13 : '%: s2 * */ s2-y [ s2=. -: +/ y'
> 
> and works
> 
>   taher 3 4 5
> 6
> 
> Suggested tacit version looks like this (and works too)
> 
> tahert=: [: %: ([: -: +/) * [: */ ([: -: +/) - ]
> 
> Q: Is there a way to reference the intermediate result of ([: -: +/) the half 
> perimeter s2
> within the tacit expression, as has been done in the explicit..?
> [Guess the interpreter takes care of this anyway; my question aims at whether 
> a shorter formulation could be reached.]
> 
> Thanks
> -M
> 
> --
> For information about J forums see http://www.jsoftware.com/forums.htm

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

Re: [Jprogramming] Control Words

2018-06-26 Thread Louis de Forcrand
Hi,

If I understand your wording, you would like to generate n “multisets” of 6 
random numbers which sum to 172. I say multiset because I imagine that order 
doesn’t matter, but that multiplicity does (so numbers can be repeated).

If speed is a concern, then you could generate all possible multisets and then 
select some at random. This takes some memory though, but I can run it on my 
phone so it shouldn’t be too bad. What follows was thrown together quickly, and 
could probably be improved.

g=: 4 : 0
 'm M'=. x
 'n s'=. y
 if. n<:0 do. i.1 0 return. end.
 min=. m >. s - M * d=. <:n
 max=. M <. s <.@% n
 p=. min ivl max
 ; (,"_ 1 , g d , s&-)&.> p
)

ivl=: [ + 0 i.@>. >:@-~
$t=: 1 70 g 6 172   NB. 1141667*6 integers!
sel=: t {~ ?@$&(#t)

(m,M) g n,s generates all increasing sequences of n integers which sum to s, 
all between m and M inclusive (provided I didn’t make any mistakes!).
If what you want is actual sets, then g can be modified slightly to yield 
strictly increasing sequences, and the space required will be slightly lessened.

Cheers,
Louis

> On 26 Jun 2018, at 16:12, Skip Cave  wrote:
> 
> I want to generate n sets of 6 random integers from 1->70 where each set of
> 6 integers sums to 172
> 
> Here's my first try:
> 
> ts =: 3 : 0
> 
> b=: 2 6$0
> 
> for. i.y do. a=:1+6?70
> 
> b=:b,a
> 
> end.
> 
> b#~172=+/"1 b
> 
> )
> 
> Test it:
> 
> ts 1000
> 
> 27 60 5 24 53 3
> 
> 38 35 3 15 57 24
> 
> 16 29 19 50 4 54
> 
> This generates some 6-element vectors that sum to 172 by elimination, but I
> don't have control of how many vectors it produces.
> 
> 
> I want to change the logic in the loop so that it keeps generating sets of
> 6 random integers, testing whether they sum to 172, saving just the sets
> that sum to 172, until I have saved y random sets that sum to 172, and then
> exits.
> 
> 
> Any help would be appreciated.
> 
> 
> 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

Re: [Jprogramming] Fifty Shades of J

2018-05-26 Thread Louis de Forcrand
I don’t know if this is the right place for this, but I just read through the 
beginning of a few sections, and looking at the one on groups I found the 
mathematical definition of a group kind of peculiar, in particular point (c):

« every element e has a left and right inverse, that is there are elements e' 
and e'' with the properties that ee'=e''e=I. If left and right inverses are 
equal for all a the group is symmetric and is known as an Abelian group. »

While different sources surely have their own conventions, both my mathematics 
course on abstract algebra as well as Wikipedia agree that the left and right 
inverses must be equal, and (more importantly) that an Abelian group G is a 
commutative group, that is that ab = ba for all a and b in G.
See
https://en.m.wikipedia.org/wiki/Abelian_group#Definition

Cheers,
Louis

> On 27 May 2018, at 01:08, Ian Clark  wrote:
> 
> Thoroughly agree, Chris.
> 
>> On Sat, May 26, 2018 at 11:18 PM, chris burke  wrote:
>> 
>> These suggestions on spacing are interesting, but I am concerned that they
>> divert attention away from the main focus, which is to recruit volunteers
>> to make sure the code and text in each essay is technically correct.
>> 
>> There is no generally agreed spacing convention for J code, so it is really
>> just a matter of style. I don't see anything wrong with Norman's style, nor
>> is it much different from other examples in the wiki, for example Roger's
>> Essays.
>> 
>> Can we move the discussion on spacing to another thread?
>> --
>> 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] Summing odd numbers

2018-05-15 Thread Louis de Forcrand
Since you have an even number of verbs in your train (1 and 2 are parsed as 
constant 1"_ and 2"_ verbs) the whole is interpreted as a hook, with the 
leading +/ taking its dyadic form. Your smodd1 verb is (in its monadic form) 
equivalent to

] +/ 1 + 2 * i.

Since you want to apply +/ to the result of the rest of the verb, you can 
either use @ atop as in

+/@(1 + 2 * i.)

or [: cap to continue the train but use +/‘s monadic form instead of giving it 
a left argument:

[: +/ 1 + 2 * i.

A train is a juxtaposition of an odd number of verbs, the first one being the 
left argument to the second _unless_ the leading verb is [: .

Cheers,
Louis

> On 15 May 2018, at 10:29, Skip Cave  wrote:
> 
> A simple Quora question wants to know the formula to sum the first n odd
> numbers.
> 
> I can write an explicit verb:
> 
> smodd =.3 :'+/1+2*i.y'
> 
> smodd 5
> 
> 25
> 
> I want to write a tacit verb:
> 
> smodd1=:+/1+2*i.
> 
> smodd1 5
> 
> 6 8 10 12 14
> 
> What am I doing wrong?
> 
> 
> 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

Re: [Jprogramming] Goodstein Sequences and Hereditary base-n notation

2018-04-11 Thread Louis de Forcrand
Hi,

This is my tacit version. Not claiming speed (or anything in the way of code 
legibility for that matter). The important verb is hbi, hereditary base-x 
incrementation of y used in creating the Goodstein sequence.
My gs verb uses a starting base of 2, and gss starts with base x:

hbi=: ([ (] +/ . * >:@[ ^ [ $: i.@-@#@]) #.^:_1)`]@.(0 = ])"0
gs=: , >:@# <:@hbi {:
gss=: ] , (+ <:@#) <:@hbi {:@]

   gs^:(0~:{:)^:10 ] 3x
3 3 3 2 1 0
   gs^:(0~:{:)^:10 ] 4x
4 26 41 60 83 109 139 173 211 253 299
   gs^:(0~:{:)^:3 ] 19x
19 7625597484990 
13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084099
 191101259794547752035640455...

   3 gss^:(0~:{:@])^:10 ] 3x
3 3 2 1 0


Sorry if I didn’t explain my code, kind of short on time. I’m pretty sure it 
works though!

Cheers,
Louis

> On 11 Apr 2018, at 15:15, 'Jon Hough' via Programming 
>  wrote:
> 
> My first answer was actually comletely wrong, and only works for the simplest 
> cases. This is a more robust and correct solution
> 
> goodstein=: 4 : 0"0 0
> if. y = x do.
>  x+1 return.
> elseif. y = 0 do.
>  0 return.
> end.
> s=. I. x (|.@:((>:@:>.@:^. # [) #: ])) y
> d=. (x+1) ^ (x:x) goodstein x: s
> +/d
> )
> 
> G=: <:@:goodstein
> 
> NB. generates sequence
> genSeq=: 3 : 0"1
> 'base val its'=. y
> c=. 0
> vals=. val
> whilst. its > c=. c+1 do.
>  val=. base G val
>  vals=. vals,val
>  base=. base+1
> end.
> vals
> )
> 
> genSeq 2 4 10
> 4 26 41 60 83 109 139 173 211 253 299
> 
> genSeq 2 19 3
> 19 7625597484990 
> 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084099
>  
> 19110125979454775203564045597039645991980810489900943371395127892465205302426158030...
> 
> 
> 
> On Wed, 4/11/18, 'Jon Hough' via Programming  
> wrote:
> 
> Subject: [Jprogramming] Goodstein Sequences and Hereditary base-n notation
> To: "Programming Forum" 
> Date: Wednesday, April 11, 2018, 5:14 PM
> 
> Goodstein's theorem: https://en.wikipedia.org/wiki/Goodstein%27s_theorem
> This states  that every Goodstein
> sequence eventually terminates at 0.
> The wikipedia page defines Goodstein
> sequences in terms of Hereditary base-n notation
> one such sequence is 4,26,41,60...
> 
> Copying verbatim from wikipedia:
> ==
> The Goodstein sequence G(m) of a number
> m is a sequence of natural numbers. The first element in the
> sequence G(m) is m itself. To get the second, G(m)(2), write
> m in hereditary base-2 notation, change all the 2s to 3s,
> and then subtract 1 from the result. In general, the
> (n + 1)-st term G(m)(n + 1) of the Goodstein
> sequence of m is as follows:
> 
> Take the hereditary base-n + 1
> representation of G(m)(n).
> Replace each occurrence of the
> base-n + 1 with n + 2.
> Subtract one. (Note that the next term
> depends both on the previous term and on the index n.)
> Continue until the result is zero, at
> which point the sequence terminates.
> ===
> 
> The sequences take an impossibly long
> time to terminate for most inputs, so there is no use
> writing a verb that iterates until convergance. This is my
> verb that will calculate the first N elements of the
> sequence,
> starting with a given base and val. the
> base should start at 2, to conform to the above definition.
> 
> 
> goodstein=: 3 : 0
> 'base val its'=. y
> vals=. ''
> c=: 0
> whilst.its> c=: c+1 do.
>   if. val = 0 do. vals return.
>   else.
> t=: ((1+
>> .base^.val)#base) #: val
> if. base < # t do.
>   if. 0 < base {
> |.t do.
> tr=: 0
> (base}) |.t
> if.
> (base+1) < # tr do.
>   ts=:
> (1+(base+1){tr) ((x+1)}) tr
>   ts=:
> |.ts
> else.
>   ts=:
> tr,1
>   ts=:
> |.ts
> end.
>   else. ts=: t end.
> else.
>   ts=: t
> end.
> val=. <:(base+1) #.
> ts
> vals=. vals,val
> base=. base+1
>   end.
> end.
> vals
> )
> 
> 
> 
> NB. example
> goodstein 2 4 9
> 26 41 60 83 109 139 173 211 253 
> NB. continues to very large numbers.
> 
>  goodstein 2 3 5
> 3 3 2 1 0   NB. terminates after 6
> iterations
> 
> Is was hoping the goodstein verb could
> be defined tacitly, but my verb is clearly a bit of a mess.
> Just for fun, any elegant solutions?
> 
> 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

Re: [Jprogramming] Expression to generate sequ

2018-04-06 Thread Louis de Forcrand
Hi,

Not a general answer about gerunds or tacit conditionals, but a particular 
solution for seq:

   seq=: [ + (* * i.@>:@|)@-~
   3 seq 7
3 4 5 6 7
   3 seq~ 7
7 6 5 4 3

Cheers,
Louis

> On 6 Apr 2018, at 22:23, Devon McCormick  wrote:
> 
> Hi -
> 
> I'm working with selecting sequential items from a vector given a starting
> and an ending point as a pair of integers.  If we assume we always get the
> pair as (lesser, greater), something like this suffices:
> 
>   seq=: {. + [: i. [: >: -~/
>   seq 3 7
> 3 4 5 6 7
> 
> However, if our assumption about the order of our points is violated, we
> get nonsense:
> 
>   seq 7 3
> 7 8 9
> 
> Just for robustness, how could we write a version of "seq" that would
> return the sequence in reverse order in this latter case, i.e. give the
> proper sequence from seven to three: 7 6 5 4 3 ?
> 
> I generalized the "seq" verb to remove the ordering assumption: my idea was
> to generate the ascending sequence, then flip it if >/y is true.  I tried
> this with "agenda" but am not sure how to get it to work on one thing - the
> ascending vector - on the basis of comparison of another thing - the pair
> of integers.
> 
> I did achieve this using the "power" conjunction:
> 
>   seq=: 3 : '|.^:(>/y)](<./ + [: i. [: >: >./ - <./) y'
>   seq 3 7
> 3 4 5 6 7
>   seq 7 3
> 7 6 5 4 3
> 
> Does anyone have any ideas for a more elegant, preferably tacit, solution?
> 
> 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

Re: [Jprogramming] running count

2018-03-30 Thread Louis de Forcrand
Hiya,

   rc=: i.~ (] - {) /:@/:
   rc 1 2 1 1 2
0 0 1 2 1

Cheers,
Louis

> On 28 Mar 2018, at 20:32, Joe Bogner  wrote:
> 
> I think this is an easy one but it's escaping me. How to calculate a
> running count of an item in a list?
> 
> runct (1,2,1,1,2) -: 0,0,1,2,1
> runct (5,6,5,5,6) -: 0,0,1,2,1
> 
> This seems to be a good start
> 
> = (5,6,5,5,6)
> 1 0 1 1 0
> 0 1 0 0 1
> --
> 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] On rank

2018-02-27 Thread Louis de Forcrand
Yes that is correct; u"n M always divides up into cells formed by grouping the 
last n dimensions together. Another way to see it is that elements of the array 
M who have the same (#$M) - n first indices are grouped together.

A variant on u"n M is "(-n), which is roughly equivalent to u"((#$M)-n) M.

If you need to break M up according to axes which are not on the tail end, you 
can look into |: transpose.

Cheers,
Louis

> On 28 Feb 2018, at 07:18, Nick S  wrote:
> 
> Someone please tell me if I understand this:
> 
> If I have a list of 5x5 tables, that is, a thing with a shape of n 5 5
> where n is anything from 1 to 30, That is, the shape of the table might be
> (5 5 or 2 5 5 or 3 5 5 etc.) and I want to compare it against a single 5x5
> thing in 5x5 groups, the proper rank to use for the comparison is 2, as
> 
> a ="2 b or a -:"2 b or a *."2 b
> 
> depending on what I want to do.
> 
> When I use a rank 2, does it take the last two dimensions of whatever and
> use those?  The examples I see are all for the more common cases of taking
> a table and processing it by individual items, rows or columns.  My
> experimentation seems to indicate that my guess is true, but I am so damned
> confused at this point, I need to see if I am on the right track.
> 
> -- 
> Of course I can ride in the carpool lane, officer.  Jesus is my constant
> companion.
> --
> 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 accurate is (o.) for arguments close to 0 or 1?

2018-02-27 Thread Louis de Forcrand
Try <.@%: .
I believe it returns extended results on extended arguments.

Cheers,
Louis

> On 27 Feb 2018, at 20:56, Don Kelly  wrote:
> 
> I agree with the series approach but the final result depends on division 
> which has limited accuracy. I would suggest using the following which uses 
> 100*L%R as a rational fraction
> 
> (10^_2)*(1r2)* 175r637816300
> 
> 1.37187e_9
> 
> 
> However, the solution is wrong in any case. It is the result of using a 
> circle and a line parallel to the tangent line at any point. In other words, 
> looking at the earth from a great distance.
> 
> The right answer (for a perfect sphere) is 0 as the curvature of the earth is 
> the same in every direction from the observer.  There is no "arch"   It seems 
> that the old Greeks had it right- as ships went off into the distance, they 
> didn't just shrink and remain whole but would also disappear gradually from 
> the  bottom up. What Patrick Harrington said is at the core of what is 
> actually observed.
> 
> 
> Don Kelly
> 
> 
>> On 2018-02-26 10:10 PM, J. Patrick Harrington wrote:
>> The way to avoid loss of accuracy is to expand in a binomial series:
>>  D = R - √(R²-L²) = R[ 1 - (1 - (L/R)^2)^(1/2)]
>>= R[ 1 - (1 -(1/2)(L/R)^2 + ...)] = (1/2) L*L/R
>> and thus
>>  ]D=. -:L*L%R
>>  1.76384e_9
>> 
>>> On Tue, 27 Feb 2018, Ian Clark wrote:
>>> In "The Curious Incident of the Dog in the Night-Time", Mark Haddon has his
>>> young autistic hero verify that the earth is not flat by holding up a steel
>>> straight-edge to the horizon.
>>> 
>>> In the course of private research into public gullibility, I tried to
>>> replicate Haddon's thought-experiment – and failed! Try as I might, I could
>>> not see the slightest discrepancy between the horizon and my straight-edge.
>>> 
>>> I strongly suspect that Haddon hasn't performed the experiment himself, but
>>> simply written down what he thought one "ought" to see.
>>> 
>>> So what am I to conclude?
>>> (a) The earth is flat.
>>> (b) The curvature is too small to be seen this way.
>>> (c) Don't believe everything you read in novels.
>>> 
>>> Let's go with (b), and try to calculate the height D of the "arch" of the
>>> horizon over the ruler's edge, and show it's too small to observe by the
>>> naked eye.
>>> 
>>> There's a diagram at:
>>> 
>>> https://whitbywriters.wordpress.com/2018/02/26/the-curious-incident-of-the-dead-flat-horizon
>>>  
>>> where I discuss the matter for non-mathematical readers. There I baldly
>>> state that D is given by the formula:
>>> 
>>>   D = R * (1 – cos arcsin L/R)
>>> 
>>> where L is the half-length of the straight-edge and R the radius of the
>>> earth.
>>> 
>>> Have I got it right?
>>> 
>>> I calculated D = 1.4 nm, but omit to say how. (I used J of course).
>>> 
>>>   R=: 6378163  NB. equatorial radius of earth (m)
>>>   L=: 0.15 NB. half-length of metal ruler (m)
>>>   cos=: 2
>>>   arcsin=: _1
>>>   smoutput D=: R * (1 - cos arcsin L%R)
>>> 1.41624e_9
>>> 
>>> Now 1.41624e_9 m is roughly 1.4 nm, less than the width of a DNA molecule.
>>> 
>>> But I suspect that my estimate of D is unreliable. Moreover it could be out
>>> by several orders of magnitude. Why? Because I'm calculating the arcsin of
>>> a very small number, and then calculating the cosine of the resulting very
>>> small angle, which may be pushing (o.) beyond its limits.
>>> 
>>> Now I could use Pythagoras instead of trigonometry:
>>> 
>>>   D = R - √(R²-L²)
>>> 
>>> which avoids using (o.) and may perform the entire calculation in extended
>>> precision without conversion to (float). I'll also work in nanometres (nm),
>>> not metres (m):
>>> 
>>>   R=: 63781630x   NB. (nm)
>>>   L=: 15000x  NB. (nm)
>>>   smoutput D=: R - %:(R*R)-(L*L)
>>> 2
>>> 
>>> I thought I was getting 6-figure accuracy, so this result worries me.
>>> 2 nm differs significantly from the result of the trig formula: 1.4 nm.
>>> 
>>> Now (R*R)-(L*L) is extended precision, but (%:) is returning (float) not
>>> (extended). Is it also corrupting the result? Is "2" just an artefact of
>>> its algorithm?
>>> 
>>> So let's work in picometres, to see if the "2" holds up under greater
>>> precision:
>>> 
>>>   R=: 6378163x
>>>   L=: 1500x
>>>   smoutput D=: R - %:(R*R)-(L*L)
>>> 2048
>>> 
>>> It does. This is encouraging. But (%:) still returns (float).
>>> 
>>> Let's try different ways of calculating the square root of an extended
>>> precision result:
>>> 
>>>   sq=: ^&2
>>>   sqr=: %:
>>>   smoutput D=: R - sqr (sq R)-(sq L)
>>> 2048
>>>   sqr=: ^&0.5
>>>   smoutput D=: R - sqr (sq R)-(sq L)
>>> 2048
>>>   sqr=: ^&1r2
>>>   smoutput D=: R - sqr (sq R)-(sq L)
>>> 3072
>>> …which is even more worrying!
>>> 
>>> So which is the most dependable approximation to D?
>>>  3 nm
>>>  2 nm
>>>  1.4 nm
>>>  none of the above?
>>> 
>>> Is it robust enough to warrant my original deduction?
>>> 
>>> Have I made a logical error somewhere?
>>> 

Re: [Jprogramming] Unboxing problem

2018-02-18 Thread Louis de Forcrand
I believe you are looking for raze ( ; ).

Cheers,
Louis

> On 18 Feb 2018, at 10:02, Arnab Chakraborty  wrote:
> 
> Hi,
> 
>   I have a list of boxes like
> 
>   m=. 1; 2 3 5; 4 5
> 
> All the boxes contain lists whose items have the same shape. So it is
> meaningful to make a combined list, eg convert m to
> 
> n=.1, 2 3 5, 4 5
> 
> As the individual lists differ in length, using >"0 produces unwanted
> padding.
> 
> The brute force approach
> 
> (>0{m), etc
> 
> works. But I am looking for a smart solution.
> --
> 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] Another Quora Problem

2018-01-29 Thread Louis de Forcrand
Indeed I should’ve mentioned it; I was referring to my earlier message:

0 = (4^z) - (2^z) - 8
= _8 _1 1 p. 2^z

so 2^(x+iy) = z = (1 +- (%:33))/2.

The rest should be clearer now.

Thanks,
Louis

> On 29 Jan 2018, at 18:43, Raul Miller <rauldmil...@gmail.com> wrote:
> 
> I do not know which of j expressions which could have matched original
> expression you were referring to.
> 
> Thanks,
> 
> -- 
> Raul
> 
> 
>> On Mon, Jan 29, 2018 at 12:39 PM, Louis de Forcrand <ol...@bluewin.ch> wrote:
>> Yes, typed a little fast.
>> 
>> sqrt33 = %:33.
>> 
>> Why does it not make sense?
>> 
>> Louis
>> 
>>> On 29 Jan 2018, at 18:35, Raul Miller <rauldmil...@gmail.com> wrote:
>>> 
>>> What is sqrt33 here? (I would have guessed %:33 but that does not make
>>> sense to me.)
>>> 
>>> Thanks,
>>> 
>>> --
>>> Raul
>>> 
>>> 
>>>> On Mon, Jan 29, 2018 at 12:31 PM, Louis de Forcrand <ol...@bluewin.ch> 
>>>> wrote:
>>>> I skipped a few steps there. With pencil and paper, I find that (using 
>>>> standard notation)
>>>> 
>>>> 2^(x+iy) = (1 +- sqrt(33)) / 2
>>>> 
>>>> Yet 2^(x+iy) = 2^x * 2^iy, and because the whole is real, 2^iy must be 
>>>> real.
>>>> 
>>>> Moreover, when y is such that 2^iy is real (when y is a multiple of 
>>>> Pi/log2) then
>>>> 
>>>> 2^iy
>>>> = exp(log2 * i*k*Pi/log2)
>>>> = exp(i*k*Pi)
>>>> = (-1)^k
>>>> 
>>>> We can see that,  because 2^x is positive, one of the roots of the 
>>>> polynomial corresponds to even k and the other to odd k.
>>>> 
>>>> Thus (with J’s ^. log)
>>>> 
>>>> x = 2 ^. (sqrt33 + (-1)^k)/2
>>>> y = k*Pi/log2
>>>> 
>>>> for any integer k describes the (countable) set of solutions.
>>>> 
>>>> They are indeed arranged in a zigzag pattern on two vertical lines, and 
>>>> the one real solution occurs when k = 0.
>>>> 
>>>> Cheers,
>>>> Louis
>>>> 
>>>>> On 29 Jan 2018, at 08:09, Louis de Forcrand <ol...@bluewin.ch> wrote:
>>>>> 
>>>>> Note that if the equation really is (in traditional notation)
>>>>> 
>>>>> 4^x - 2^x - 8 = 0
>>>>> 
>>>>> then it can be rewritten as
>>>>> 
>>>>> y^2 - y - 8 = 0, y = 2^x
>>>>> 
>>>>> and solved in closed form as well,
>>>>> yielding a countably infinite set of solutions aligned along one (or two) 
>>>>> vertical lines in the complex plane.
>>>>> (If I am not mistaken!)
>>>>> 
>>>>> Louis
>>>>> 
>>>>>> On 29 Jan 2018, at 07:19, Rob Hodgkinson <rhodg...@me.com> wrote:
>>>>>> 
>>>>>> @Skip et al …
>>>>>> 
>>>>>> also apologies for my sill definitions, I should have used y inside the 
>>>>>> definitions not x (!!!), sorry if I confused the issue…
>>>>>> 
>>>>>> as in here for the first interpretation …
>>>>>> 
>>>>>> x,"0 (3 : '8+(2^y)-((2^2)^y)') x=:1.6+0.05*i.8
>>>>>> 
>>>>>> …/Rob
>>>>>> 
>>>>>>> On 29 Jan 2018, at 3:49 pm, Jose Mario Quintana 
>>>>>>> <jose.mario.quint...@gmail.com> wrote:
>>>>>>> 
>>>>>>> In that case,
>>>>>>> 
>>>>>>> (X=. (8 + (2 ^ ]) - (2 ^ 2) ^ ])New (^:22) 1)
>>>>>>> 1.75372489
>>>>>>> 
>>>>>>> is a root,
>>>>>>> 
>>>>>>> (8 + (2 ^ ]) - (2 ^ 2) ^ ])X
>>>>>>> 0
>>>>>>> 
>>>>>>> but, it is not the only one,
>>>>>>> 
>>>>>>> (X=. (8 + (2 ^ ]) - (2 ^ 2) ^ ])New (^:22) 0.5j_0.5)
>>>>>>> 1.24627511j4.53236014
>>>>>>> 
>>>>>>> (8 + (2 ^ ]) - (2 ^ 2) ^ ])X
>>>>>>> 8.8817842e_16j7.72083702e_15
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>>> On Sun, Jan 28, 2018 at 9:27 PM, Raul Miller <rauldmil...@gmail.com> 
>>>>>>>>

Re: [Jprogramming] Another Quora Problem

2018-01-29 Thread Louis de Forcrand
Yes, typed a little fast.

sqrt33 = %:33.

Why does it not make sense?

Louis

> On 29 Jan 2018, at 18:35, Raul Miller <rauldmil...@gmail.com> wrote:
> 
> What is sqrt33 here? (I would have guessed %:33 but that does not make
> sense to me.)
> 
> Thanks,
> 
> -- 
> Raul
> 
> 
>> On Mon, Jan 29, 2018 at 12:31 PM, Louis de Forcrand <ol...@bluewin.ch> wrote:
>> I skipped a few steps there. With pencil and paper, I find that (using 
>> standard notation)
>> 
>> 2^(x+iy) = (1 +- sqrt(33)) / 2
>> 
>> Yet 2^(x+iy) = 2^x * 2^iy, and because the whole is real, 2^iy must be real.
>> 
>> Moreover, when y is such that 2^iy is real (when y is a multiple of Pi/log2) 
>> then
>> 
>> 2^iy
>> = exp(log2 * i*k*Pi/log2)
>> = exp(i*k*Pi)
>> = (-1)^k
>> 
>> We can see that,  because 2^x is positive, one of the roots of the 
>> polynomial corresponds to even k and the other to odd k.
>> 
>> Thus (with J’s ^. log)
>> 
>> x = 2 ^. (sqrt33 + (-1)^k)/2
>> y = k*Pi/log2
>> 
>> for any integer k describes the (countable) set of solutions.
>> 
>> They are indeed arranged in a zigzag pattern on two vertical lines, and the 
>> one real solution occurs when k = 0.
>> 
>> Cheers,
>> Louis
>> 
>>> On 29 Jan 2018, at 08:09, Louis de Forcrand <ol...@bluewin.ch> wrote:
>>> 
>>> Note that if the equation really is (in traditional notation)
>>> 
>>> 4^x - 2^x - 8 = 0
>>> 
>>> then it can be rewritten as
>>> 
>>> y^2 - y - 8 = 0, y = 2^x
>>> 
>>> and solved in closed form as well,
>>> yielding a countably infinite set of solutions aligned along one (or two) 
>>> vertical lines in the complex plane.
>>> (If I am not mistaken!)
>>> 
>>> Louis
>>> 
>>>> On 29 Jan 2018, at 07:19, Rob Hodgkinson <rhodg...@me.com> wrote:
>>>> 
>>>> @Skip et al …
>>>> 
>>>> also apologies for my sill definitions, I should have used y inside the 
>>>> definitions not x (!!!), sorry if I confused the issue…
>>>> 
>>>> as in here for the first interpretation …
>>>> 
>>>> x,"0 (3 : '8+(2^y)-((2^2)^y)') x=:1.6+0.05*i.8
>>>> 
>>>> …/Rob
>>>> 
>>>>> On 29 Jan 2018, at 3:49 pm, Jose Mario Quintana 
>>>>> <jose.mario.quint...@gmail.com> wrote:
>>>>> 
>>>>> In that case,
>>>>> 
>>>>> (X=. (8 + (2 ^ ]) - (2 ^ 2) ^ ])New (^:22) 1)
>>>>> 1.75372489
>>>>> 
>>>>> is a root,
>>>>> 
>>>>> (8 + (2 ^ ]) - (2 ^ 2) ^ ])X
>>>>> 0
>>>>> 
>>>>> but, it is not the only one,
>>>>> 
>>>>> (X=. (8 + (2 ^ ]) - (2 ^ 2) ^ ])New (^:22) 0.5j_0.5)
>>>>> 1.24627511j4.53236014
>>>>> 
>>>>> (8 + (2 ^ ]) - (2 ^ 2) ^ ])X
>>>>> 8.8817842e_16j7.72083702e_15
>>>>> 
>>>>> 
>>>>> 
>>>>>> On Sun, Jan 28, 2018 at 9:27 PM, Raul Miller <rauldmil...@gmail.com> 
>>>>>> wrote:
>>>>>> 
>>>>>> Hmm...
>>>>>> 
>>>>>> I had originally thought about calling out the (2^2)^x interpretation
>>>>>> as a possibility, because rejected that, because that would be better
>>>>>> expressed as 4^x
>>>>>> 
>>>>>> But it's possible that Skip got the 1.75379 number from someone who
>>>>>> thought different about this.
>>>>>> 
>>>>>> And, to be honest, it is an ambiguity in the original expression -
>>>>>> just one that I thought should be rejected outright, rather than
>>>>>> suggested.
>>>>>> 
>>>>>> Which gets us into another issue, which is that what one person would
>>>>>> think is obviously right is almost always what some other person would
>>>>>> think is obviously wrong... (and this issue crops up all over, not
>>>>>> just in mathematic and/or programming contexts).
>>>>>> 
>>>>>> --
>>>>>> Raul
>>>>>> 
>>>>>> 
>>>>>>> On Sun, Jan 28, 2018 at 9:08 PM, Rob Hodgkinson <rhodg...@me.com> wrote:
>>>>>>> @Skip
>>>>>>> 
>&

Re: [Jprogramming] Another Quora Problem

2018-01-29 Thread Louis de Forcrand
I skipped a few steps there. With pencil and paper, I find that (using standard 
notation)

2^(x+iy) = (1 +- sqrt(33)) / 2

Yet 2^(x+iy) = 2^x * 2^iy, and because the whole is real, 2^iy must be real.

Moreover, when y is such that 2^iy is real (when y is a multiple of Pi/log2) 
then

2^iy
= exp(log2 * i*k*Pi/log2)
= exp(i*k*Pi)
= (-1)^k

We can see that,  because 2^x is positive, one of the roots of the polynomial 
corresponds to even k and the other to odd k.

Thus (with J’s ^. log)

x = 2 ^. (sqrt33 + (-1)^k)/2
y = k*Pi/log2

for any integer k describes the (countable) set of solutions.

They are indeed arranged in a zigzag pattern on two vertical lines, and the one 
real solution occurs when k = 0.

Cheers,
Louis

> On 29 Jan 2018, at 08:09, Louis de Forcrand <ol...@bluewin.ch> wrote:
> 
> Note that if the equation really is (in traditional notation)
> 
> 4^x - 2^x - 8 = 0
> 
> then it can be rewritten as
> 
> y^2 - y - 8 = 0, y = 2^x
> 
> and solved in closed form as well,
> yielding a countably infinite set of solutions aligned along one (or two) 
> vertical lines in the complex plane.
> (If I am not mistaken!)
> 
> Louis
> 
>> On 29 Jan 2018, at 07:19, Rob Hodgkinson <rhodg...@me.com> wrote:
>> 
>> @Skip et al …
>> 
>> also apologies for my sill definitions, I should have used y inside the 
>> definitions not x (!!!), sorry if I confused the issue…
>> 
>> as in here for the first interpretation …
>> 
>> x,"0 (3 : '8+(2^y)-((2^2)^y)') x=:1.6+0.05*i.8
>> 
>> …/Rob
>> 
>>> On 29 Jan 2018, at 3:49 pm, Jose Mario Quintana 
>>> <jose.mario.quint...@gmail.com> wrote:
>>> 
>>> In that case,
>>> 
>>> (X=. (8 + (2 ^ ]) - (2 ^ 2) ^ ])New (^:22) 1)
>>> 1.75372489
>>> 
>>> is a root,
>>> 
>>> (8 + (2 ^ ]) - (2 ^ 2) ^ ])X
>>> 0
>>> 
>>> but, it is not the only one,
>>> 
>>> (X=. (8 + (2 ^ ]) - (2 ^ 2) ^ ])New (^:22) 0.5j_0.5)
>>> 1.24627511j4.53236014
>>> 
>>> (8 + (2 ^ ]) - (2 ^ 2) ^ ])X
>>> 8.8817842e_16j7.72083702e_15
>>> 
>>> 
>>> 
>>>> On Sun, Jan 28, 2018 at 9:27 PM, Raul Miller <rauldmil...@gmail.com> wrote:
>>>> 
>>>> Hmm...
>>>> 
>>>> I had originally thought about calling out the (2^2)^x interpretation
>>>> as a possibility, because rejected that, because that would be better
>>>> expressed as 4^x
>>>> 
>>>> But it's possible that Skip got the 1.75379 number from someone who
>>>> thought different about this.
>>>> 
>>>> And, to be honest, it is an ambiguity in the original expression -
>>>> just one that I thought should be rejected outright, rather than
>>>> suggested.
>>>> 
>>>> Which gets us into another issue, which is that what one person would
>>>> think is obviously right is almost always what some other person would
>>>> think is obviously wrong... (and this issue crops up all over, not
>>>> just in mathematic and/or programming contexts).
>>>> 
>>>> --
>>>> Raul
>>>> 
>>>> 
>>>>> On Sun, Jan 28, 2018 at 9:08 PM, Rob Hodgkinson <rhodg...@me.com> wrote:
>>>>> @Skip
>>>>> 
>>>>> Skip, I am a confused in your original post… your actual post read;
>>>>> 
>>>>> 
>>>>> What is the best iterative way to solve this equation:
>>>>> (-2^2^x) + (2^x) +8 =0
>>>>> then later to Raul,
>>>>> 0 = 8 + (2^x) - 2^2^xNB. Is correct, and the answer is real
>>>>> The answer is close to 1.75379
>>>>> 
>>>>> 
>>>>> However I suspect your original syntax was not J syntax (could it have
>>>> been math type syntax ?) as it differs on the J style right-to-left syntax
>>>> on the 2^2^x expression.
>>>>> 
>>>>> The 2 possible interpretations are shown below and only the Excel type
>>>> syntax seems to get close to your expected answer.
>>>>> 
>>>>> NB. Excel interpretation
>>>>> x,"0 (3 : '8+(2^x)-((2^2)^x)') x=:1.6+0.05*i.8
>>>>> 1.61.84185
>>>>> 1.65   1.28918
>>>>> 1.70.692946
>>>>> 1.75   0.0498772NB. intercept seems close to your
>>>> expected 

Re: [Jprogramming] Another Quora Problem

2018-01-28 Thread Louis de Forcrand
Note that if the equation really is (in traditional notation)

4^x - 2^x - 8 = 0

then it can be rewritten as

y^2 - y - 8 = 0, y = 2^x

and solved in closed form as well,
yielding a countably infinite set of solutions aligned along one (or two) 
vertical lines in the complex plane.
(If I am not mistaken!)

Louis

> On 29 Jan 2018, at 07:19, Rob Hodgkinson  wrote:
> 
> @Skip et al …
> 
> also apologies for my sill definitions, I should have used y inside the 
> definitions not x (!!!), sorry if I confused the issue…
> 
> as in here for the first interpretation …
> 
> x,"0 (3 : '8+(2^y)-((2^2)^y)') x=:1.6+0.05*i.8
> 
> …/Rob
> 
>> On 29 Jan 2018, at 3:49 pm, Jose Mario Quintana 
>>  wrote:
>> 
>> In that case,
>> 
>>  (X=. (8 + (2 ^ ]) - (2 ^ 2) ^ ])New (^:22) 1)
>> 1.75372489
>> 
>> is a root,
>> 
>>  (8 + (2 ^ ]) - (2 ^ 2) ^ ])X
>> 0
>> 
>> but, it is not the only one,
>> 
>>  (X=. (8 + (2 ^ ]) - (2 ^ 2) ^ ])New (^:22) 0.5j_0.5)
>> 1.24627511j4.53236014
>> 
>>  (8 + (2 ^ ]) - (2 ^ 2) ^ ])X
>> 8.8817842e_16j7.72083702e_15
>> 
>> 
>> 
>>> On Sun, Jan 28, 2018 at 9:27 PM, Raul Miller  wrote:
>>> 
>>> Hmm...
>>> 
>>> I had originally thought about calling out the (2^2)^x interpretation
>>> as a possibility, because rejected that, because that would be better
>>> expressed as 4^x
>>> 
>>> But it's possible that Skip got the 1.75379 number from someone who
>>> thought different about this.
>>> 
>>> And, to be honest, it is an ambiguity in the original expression -
>>> just one that I thought should be rejected outright, rather than
>>> suggested.
>>> 
>>> Which gets us into another issue, which is that what one person would
>>> think is obviously right is almost always what some other person would
>>> think is obviously wrong... (and this issue crops up all over, not
>>> just in mathematic and/or programming contexts).
>>> 
>>> --
>>> Raul
>>> 
>>> 
 On Sun, Jan 28, 2018 at 9:08 PM, Rob Hodgkinson  wrote:
 @Skip
 
 Skip, I am a confused in your original post… your actual post read;
 
 
 What is the best iterative way to solve this equation:
 (-2^2^x) + (2^x) +8 =0
 then later to Raul,
 0 = 8 + (2^x) - 2^2^xNB. Is correct, and the answer is real
 The answer is close to 1.75379
 
 
 However I suspect your original syntax was not J syntax (could it have
>>> been math type syntax ?) as it differs on the J style right-to-left syntax
>>> on the 2^2^x expression.
 
 The 2 possible interpretations are shown below and only the Excel type
>>> syntax seems to get close to your expected answer.
 
 NB. Excel interpretation
  x,"0 (3 : '8+(2^x)-((2^2)^x)') x=:1.6+0.05*i.8
 1.61.84185
 1.65   1.28918
 1.70.692946
 1.75   0.0498772NB. intercept seems close to your
>>> expected value of 1.75379
 1.8_0.64353
 1.85  _1.39104
 1.9_2.19668
 1.95  _3.06478
 
 NB. J style interpretation
  x,"0 (3 : '8+(2^x)-(2^2^x)') x=:1.6+0.05*i.8
 1.6  2.85522
 1.652.33325
 1.7  1.74188
 1.751.07063
 1.8  0.307207 NB. But in this model the intercept is
>>> above 1.8, but this is the model that has been coded in responses to your
>>> post ??
 1.85  _0.562844
 1.9_1.5566
 1.95  _2.69431
 
 Please clarify, thanks, Rob
 
 
> On 29 Jan 2018, at 12:48 pm, Jose Mario Quintana <
>>> jose.mario.quint...@gmail.com> wrote:
> 
> Moreover, apparently there is at least another solution,
> 
> ((-2^2^X) + (2^X) +8 ) [  X=. 2.9992934709539156j_13.597080425481581
> 5.19549681e_16j_2.92973749e_15
> 
> 
> On Sun, Jan 28, 2018 at 7:28 PM, Jose Mario Quintana <
> jose.mario.quint...@gmail.com> wrote:
> 
>> Are you sure?
>> 
>> u New
>> - (u %. u D.1)
>> 
>> ,. (8 + (2 ^ ]) - 2 ^ 2 ^ ])New (^:(<22)) 1
>>   1
>> 3.44167448
>> 3.25190632
>> 3.03819348
>> 2.7974808
>> 2.53114635
>> 2.25407823
>> 2.00897742
>> 1.86069674
>> 1.82070294
>> 1.81842281
>> 1.81841595
>> 1.81841595
>> 1.81841595
>> 1.81841595
>> 1.81841595
>> 1.81841595
>> 1.81841595
>> 1.81841595
>> 1.81841595
>> 1.81841595
>> 1.81841595
>> 
>> (8 + (2 ^ ]) - 2 ^ 2 ^ ]) 1.81841595
>> _8.21739086e_8
>> 
>> (8 + (2 ^ ]) - 2 ^ 2 ^ ]) 1.75379
>> 1.01615682
>> 
>> PS.  Notice that New is a tacit version (not shown) of Louis' VN
>>> adverb.
>> 
>> 
>> 
>> 
>> On Sun, Jan 28, 2018 at 5:52 PM, Skip Cave 
>> wrote:
>> 
>>> Raul,
>>> 
>>> You had it right in the first place.
>>> 
>>> 0 = 8 + (2^x) - 2^2^xNB. Is correct, 

Re: [Jprogramming] Another Quora Problem

2018-01-28 Thread Louis de Forcrand
Since Newton-Raphson is mentioned, I’d like to throw in (even though it might 
be mentioned on the wiki page) that 

VN=: 1 : 0
- u %. u D.1
)

is a kind of holy grail.
It can iteratively find roots not only of complex scalar functions, but also 
complex vector and even tensor functions I believe. Of course accuracy and 
initial guesses might become problematic, but I still find it quite cool for 
such a simple function to be so powerful.

Best,
Louis

> On 29 Jan 2018, at 00:07, Raul Miller  wrote:
> 
> Yeah, I guess it should be fine to just look at the sequence to see if
> it's converging, or test the result.
> 
> My thought was that iterations are cheap, I just wanted a small finite
> number of them.
> 
> Thanks,
> 
> -- 
> Raul
> 
>> On Sun, Jan 28, 2018 at 6:05 PM, Henry Rich  wrote:
>> If Newton's method converges, you won't need a couple of hundred rounds -
>> just a dozen or so.
>> 
>> Henry Rich
>> 
>> 
>>> On 1/28/2018 5:52 PM, Skip Cave wrote:
>>> 
>>> Raul,
>>> 
>>> You had it right in the first place.
>>> 
>>> 0 = 8 + (2^x) - 2^2^xNB. Is correct, and the answer is real
>>> 
>>> The answer is close to 1.75379
>>> 
>>> I wanted to know how to construct the Newton Raphson method using the
>>> iteration verb N described in the link: http://code.jsoftware.
>>> com/wiki/NYCJUG/2010-11-09
>>> under "A Sampling of Solvers - Newton's Method"
>>> 
>>> N=: 1 : '- u % u d. 1'
>>> 
>>> Skip
>>> 
>>> 
>>> 
>>> 
>>> 
>>> Skip Cave
>>> Cave Consulting LLC
>>> 
>>> On Sun, Jan 28, 2018 at 4:38 PM, Raul Miller 
>>> wrote:
>>> 
 Eh... I *think* you meant what would be expressed in J as:
 
 0 = 8 + (2^x) - 2^2^x
 
 I'd probably try maybe a few hundred rounds of newton's method first,
 and see where that leads.
 
 But there's an ambiguity where the original expression (depending on
 the frame of reference of the poster) could have been intended to be:
 
 0 = 8 + (2^x) + _2^2^x
 
 [if that is solvable, x might have to be complex]
 
 Thanks,
 
 --
 Raul
 
 On Sun, Jan 28, 2018 at 5:25 PM, Skip Cave 
 wrote:
> 
> What is the best iterative way to solve this equation:
> 
> (-2^2^x) + (2^x) +8 =0
> 
> 
> 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
>> 
>> 
>> 
>> ---
>> This email has been checked for viruses by AVG.
>> http://www.avg.com
>> 
>> 
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
> --
> For information about J forums see http://www.jsoftware.com/forums.htm

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

Re: [Jprogramming] Fill between curves using plot

2018-01-18 Thread Louis de Forcrand
You could try something with the polygon plot type. Assuming you have two sets 
of points, one for the top curve and one for the bottom curve, each in the 
usual form (xcoords;ycoords):

'poly' plot bot (, |.)&.> top

might do something interesting.
There may be other options like for opacity etc., but I can’t help you with 
those.

Cheers,
Louis

> On 19 Jan 2018, at 02:57, 'Jon Hough' via Programming 
>  wrote:
> 
> Thanks Linda,
> 
> I am not sure that is exactly what I am looking for, but thank you  anyway. I 
> am interested
> in showing the error estimates on a line graph, e.g. see the second answer 
> here: 
> https://stackoverflow.com/questions/12957582/matplotlib-plot-yerr-xerr-as-shaded-region-rather-than-error-bars
> 
> It seems, J plot does not have this feature. 
> 
> Thanks,
> Jon
> 
> 
> 
> On Thu, 1/18/18, Linda Alvord  wrote:
> 
> Subject: Re: [Jprogramming] Fill between curves using plot
> To: "programm...@jsoftware.com" 
> Date: Thursday, January 18, 2018, 4:19 PM
> 
> This is something I kept,
> probably from Cliff Reiter's book.
> There
> are several plots which you can see all at once if you run
> it in JHS.
> 
> load
> 'plot'
> d=: 13
> :'(0{x)-(-/x)*(i.>:y)%y'NB. domain
> intervals 
> f=: 13 :'(0 1) d y'   
> NB. frame domain 
> circle=: 13 :'(1 o. y) (*"1)2 1
> o./y'
> tf=: 13 :'(1 o.3*y) (*"1)
> 2 1 o./y'  NB. trifolium
> T=:2p1
> plot ;/circle (0,T) d 385
> plot
> ;/a=:(circle(0,T) d 385)*/f 385
> plot ;/ tf
> (0,T) d 385   
> plot ;/ b=:(tf d 385)*/f
> 385
> plot ;/ c=:(tf (0,T) d 385)*/f 385
> b
> c
>  load
> 'plot'
> d=: 13
> :'(0{x)-(-/x)*(i.>:y)%y'NB. domain
> intervals 
> f=: 13 :'(0 1) d y'   
> NB. frame domain 
> circle=: 13 :'(1 o. y) (*"1)2 1
> o./y'
> tf=: 13 :'(1 o.3*y) (*"1)
> 2 1 o./y'  NB. trifolium
> T=:2p1
> plot ;/circle (0,T) d 385
> plot
> ;/a=:(circle(0,T) d 385)*/f 385
> plot ;/ tf
> (0,T) d 385   
> plot ;/ b=:(tf d 385)*/f
> 385
> plot ;/ c=:(tf (0,T) d 385)*/f 385
> 
> Linda
> 
> 
> 
> -Original
> Message-
> From: Programming [mailto:programming-boun...@forums.jsoftware.com]
> On Behalf Of 'Jon Hough' via Programming
> Sent: Thursday, January 18, 2018 1:49 AM
> To: Programming Forum 
> Subject: [Jprogramming] Fill between curves
> using plot
> 
> Using plot, is
> it possible to draw two curves and color-fill the area
> between them?
> e.g. with matplotlib,
> something like this 
> https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmatplotlib.org%2Fapi%2Fpyplot_api.html%23matplotlib.pyplot.fill_between=02%7C01%7C%7Cc6013875e092416b2d9008d55e3f8483%7C84df9e7fe9f640afb435%7C1%7C0%7C636518549256345902=%2BlW%2Bfmdtji26ouCyW7EpuwMang%2F%2BNXO4SShQUd9K2IU%3D=0
> ?
> 
> I've looked
> through the wiki 
> (https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fcode.jsoftware.com%2Fwiki%2FPlot=02%7C01%7C%7Cc6013875e092416b2d9008d55e3f8483%7C84df9e7fe9f640afb435%7C1%7C0%7C636518549256345902=ekGRSnU3MrGOazCce%2FYgRUPb7IeX5J1pns%2F55JP3fE4%3D=0)
> but cannot seem to find anything that does this.
> 
> Thanks,
> Jon
> --
> For information about J forums see 
> https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jsoftware.com%2Fforums.htm=02%7C01%7C%7Cc6013875e092416b2d9008d55e3f8483%7C84df9e7fe9f640afb435%7C1%7C0%7C636518549256345902=fDFVvz%2BKRNxGw6jC6GBVhlG1qxqqhY7Mktg5iBF3dZw%3D=0
> --
> 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] shortening a verbose expression

2018-01-06 Thread Louis de Forcrand
vec3=: [: ((* {.)~ , {:@[)/ 2 1 o.~/~ ]

In the end though the most readable is probably Bo’s. No distracting array 
tricks.

Louis

> On 7 Jan 2018, at 02:26, Jimmy Gauvin  wrote:
> 
> This might be easier on the eyes:
> 
>   vc=:_2 */\ 1 2 1 1 2 o. 5 $ o.
> 
>   vc 1.25,_0.55
> 0.110616 0.698401 _0.707107
> 
> 
>> On Sat, Jan 6, 2018 at 7:05 PM, Henry Rich  wrote:
>> 
>> Not really any better, but you might enjoy playing with it:
>> 
>> vec2 =: ((+.@:(* {:) , {.@]) +.)~/@:(^@:j.)
>> 
>> Henry Rich
>> 
>> 
>>> On 1/6/2018 5:07 PM, Jerry wrote:
>>> 
>>> I am a relative newbie and am trying to teach myself the intricacies by
>>> addressing a simple problem: some geometric operations on the surface of a
>>> unit sphere.  The first step is to take latitude and longitude angles and
>>> create a Cartesian vector pointing from the center of the sphere to that
>>> point.  I can do that via:
>>> 
>>> vec =: ((1 o. }:)*(2 o. {:)),((1 o. }:)*(1 o. {:)),(2 o. }:)
>>> 
>>> this verb yields the desired vector
>>> 
>>>[vec o. (1.25,_0.55)
>>> 
>>> 0.110616 0.698401 _0.707107
>>> 
>>>   +/([vec o. (1.25,_0.55))^2
>>> 
>>> 1
>>> 
>>> Is there a shorter, less verbose way of writing the verb 'vec'?
>>> 
>>> --
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>> 
>> 
>> 
>> ---
>> This email has been checked for viruses by AVG.
>> http://www.avg.com
>> 
>> 
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>> 
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] NaN, p., and control structures

2017-12-31 Thread Louis de Forcrand
Obviously nobody would ever enter
if. 0 > _.
them self. I guess if primitives never produce _. then we need not worry about 
it; but in the very slight off-chance that a bug lets one slip through, 
wouldn’t it be safer if an error is thrown?

Anyhow, this topic’s problem is solved; gotta stay up to date!

Louis

> On 30 Dec 2017, at 01:32, bill lam  wrote:
> 
> IMO the current behavior is acceptable for
> if. 0 > _. do. etc…
> 
> The user who wrote this sentence must have some special task to accomplish
> and can just skip the condition depending on what he/she think the
> condition should be true or false or signaling error.
> 
> If the _. is a result of operation on primitive, then it will signal an
> error before passing to control structure.i
> --
> 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] NaN, p., and control structures

2017-12-29 Thread Louis de Forcrand
I now remember why I hadn’t used j806; my Mac is too old for AVX.
Anyhow, I tried j806 without AVX:

   2 7 p.1e308j_
_j_

So, apparently the problem has already been solved. Sorry for the bother!

Louis

PS: I still would make something throw an error when doing things like
if. 0 > _. do. etc…
for the sake of potential headache avoidance. I had a really hard time finding 
my error earlier today in j805.

> On 29 Dec 2017, at 23:08, Henry Rich <henryhr...@gmail.com> wrote:
> 
> J's position on _. is that it is an abomination and we make no claims for 
> what happens when _. appears in an argument and spend no time worrying about 
> it.
> 
> Henry Rich
> 
> On 12/29/2017 10:50 PM, Louis de Forcrand wrote:
>> Sorry for not trying this in j806, I should install it on my Mac.
>> Will update.
>> 
>> As for control structures treating _. as false, I was mistaken.
>> I was actually comparing a float with _., and that returned 0.
>> Nevertheless, I think control structures should signal _. instead of 
>> silently accepting it, and perhaps even comparison operators? Either that or 
>> have comparisons return _. as well. That would probably be more consistent.
>> 
>> Louis
>> 
>>> On 29 Dec 2017, at 22:41, bill lam <bbill@gmail.com> wrote:
>>> 
>>> This is what I got from J806
>>>   foo
>>> 3 : 0
>>> if. _ - _ do.
>>> echo 1
>>> else.
>>> echo 0
>>> end.
>>> EMPTY
>>> )
>>>   foo''
>>> |NaN error: foo
>>> |   _-_
>>>   bar
>>> 3 : 0
>>> if. _. do.
>>> echo 1
>>> else.
>>> echo 0
>>> end.
>>> EMPTY
>>> )
>>>   bar''
>>> 1
>>> 
>>> foo is reasonable.
>>> bar is also reasonable to me, because _. is not equal 0 so that
>>> the condition is true.
>>> 
>>> What is your code that treating _. as false?
>>> 
>>> Also on my J806 linux64
>>>   2 7 p.1e308j_
>>> _j_
>>> 
>>> 
>>> Пт, 29 дек 2017, Louis de Forcrand написал(а):
>>>> What about control structures treating _. as false?
>>>> I personally would make that an error, and I would also say that code that 
>>>> makes use of this should be considered bad style.
>>>> 
>>>> Louis
>>>> 
>>>>> On 29 Dec 2017, at 18:29, Henry Rich <henryhr...@gmail.com> wrote:
>>>>> 
>>>>> Surely not intended.  Put it on the bug list.
>>>>> 
>>>>> Henry Rich
>>>>> 
>>>>> On 12/29/2017 6:06 PM, Louis de Forcrand wrote:
>>>>>> On the Indeterminate vocabulary page of the dictionary it is written
>>>>>> 
>>>>>> The only ways to create _. are as follows:
>>>>>>  direct entry of _.
>>>>>>  ".
>>>>>>  3!:n
>>>>>>  DLL call (database, LAPACK, etc.)
>>>>>> 
>>>>>> and
>>>>>> 
>>>>>> Primitives on arguments not containing _. signal NaN error instead of 
>>>>>> producing _. .
>>>>>> 
>>>>>> yet (in j64-805 on macOS 10.10.5)
>>>>>> 
>>>>>>   2 7 p.1e308j_
>>>>>> _.j_
>>>>>> 
>>>>>> This is very dangerous, as comparison with _. seems to yield _. and it 
>>>>>> also seems that control structures treat _. as false instead of 
>>>>>> signalling an error (which is in my opinion a very bad idea).
>>>>>> Are both these behaviours intended?
>>>>>> 
>>>>>> Thanks,
>>>>>> Louis
>>>>>> 
>>>>>> --
>>>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>>> 
>>>>> ---
>>>>> This email has been checked for viruses by AVG.
>>>>> http://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
>>> -- 
>>> regards,
>>> 
>>> GPG key 1024D/4434BAB3 2008-08-24
>>> gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
>>> gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3
>>> --
>>> 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] NaN, p., and control structures

2017-12-29 Thread Louis de Forcrand
Sorry for not trying this in j806, I should install it on my Mac.
Will update.

As for control structures treating _. as false, I was mistaken.
I was actually comparing a float with _., and that returned 0.
Nevertheless, I think control structures should signal _. instead of silently 
accepting it, and perhaps even comparison operators? Either that or have 
comparisons return _. as well. That would probably be more consistent.

Louis

> On 29 Dec 2017, at 22:41, bill lam <bbill@gmail.com> wrote:
> 
> This is what I got from J806
>   foo
> 3 : 0
> if. _ - _ do.
> echo 1
> else.
> echo 0
> end.
> EMPTY
> )
>   foo''
> |NaN error: foo
> |   _-_
>   bar
> 3 : 0
> if. _. do.
> echo 1
> else.
> echo 0
> end.
> EMPTY
> )
>   bar''
> 1
> 
> foo is reasonable.
> bar is also reasonable to me, because _. is not equal 0 so that
> the condition is true.
> 
> What is your code that treating _. as false?
> 
> Also on my J806 linux64
>   2 7 p.1e308j_
> _j_
> 
> 
> Пт, 29 дек 2017, Louis de Forcrand написал(а):
>> What about control structures treating _. as false?
>> I personally would make that an error, and I would also say that code that 
>> makes use of this should be considered bad style.
>> 
>> Louis
>> 
>>> On 29 Dec 2017, at 18:29, Henry Rich <henryhr...@gmail.com> wrote:
>>> 
>>> Surely not intended.  Put it on the bug list.
>>> 
>>> Henry Rich
>>> 
>>> On 12/29/2017 6:06 PM, Louis de Forcrand wrote:
>>>> On the Indeterminate vocabulary page of the dictionary it is written
>>>> 
>>>> The only ways to create _. are as follows:
>>>>direct entry of _.
>>>>".
>>>>3!:n
>>>>DLL call (database, LAPACK, etc.)
>>>> 
>>>> and
>>>> 
>>>> Primitives on arguments not containing _. signal NaN error instead of 
>>>> producing _. .
>>>> 
>>>> yet (in j64-805 on macOS 10.10.5)
>>>> 
>>>>   2 7 p.1e308j_
>>>> _.j_
>>>> 
>>>> This is very dangerous, as comparison with _. seems to yield _. and it 
>>>> also seems that control structures treat _. as false instead of signalling 
>>>> an error (which is in my opinion a very bad idea).
>>>> Are both these behaviours intended?
>>>> 
>>>> Thanks,
>>>> Louis
>>>> 
>>>> --
>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>> 
>>> 
>>> ---
>>> This email has been checked for viruses by AVG.
>>> http://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
> 
> -- 
> regards,
> 
> GPG key 1024D/4434BAB3 2008-08-24
> gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
> gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3
> --
> 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] NaN, p., and control structures

2017-12-29 Thread Louis de Forcrand
What about control structures treating _. as false?
I personally would make that an error, and I would also say that code that 
makes use of this should be considered bad style.

Louis

> On 29 Dec 2017, at 18:29, Henry Rich <henryhr...@gmail.com> wrote:
> 
> Surely not intended.  Put it on the bug list.
> 
> Henry Rich
> 
> On 12/29/2017 6:06 PM, Louis de Forcrand wrote:
>> On the Indeterminate vocabulary page of the dictionary it is written
>> 
>> The only ways to create _. are as follows:
>>  direct entry of _.
>>  ".
>>  3!:n
>>  DLL call (database, LAPACK, etc.)
>> 
>> and
>> 
>> Primitives on arguments not containing _. signal NaN error instead of 
>> producing _. .
>> 
>> yet (in j64-805 on macOS 10.10.5)
>> 
>>2 7 p.1e308j_
>> _.j_
>> 
>> This is very dangerous, as comparison with _. seems to yield _. and it also 
>> seems that control structures treat _. as false instead of signalling an 
>> error (which is in my opinion a very bad idea).
>> Are both these behaviours intended?
>> 
>> Thanks,
>> Louis
>> 
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
> 
> 
> ---
> This email has been checked for viruses by AVG.
> http://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] NaN, p., and control structures

2017-12-29 Thread Louis de Forcrand
On the Indeterminate vocabulary page of the dictionary it is written

The only ways to create _. are as follows:
direct entry of _. 
".
3!:n
DLL call (database, LAPACK, etc.)

and

Primitives on arguments not containing _. signal NaN error instead of producing 
_. .

yet (in j64-805 on macOS 10.10.5)

   2 7 p.1e308j_
_.j_

This is very dangerous, as comparison with _. seems to yield _. and it also 
seems that control structures treat _. as false instead of signalling an error 
(which is in my opinion a very bad idea).
Are both these behaviours intended?

Thanks,
Louis

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

[Jprogramming] viewmat export size

2017-12-19 Thread Louis de Forcrand
Hi,

Does anyone know how to save a viewmat image to disk, and if so, how to chose 
the resulting image’s size?

Thanks,
Louis


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

Re: [Jprogramming] Euclidean Distance

2017-10-29 Thread Louis de Forcrand
I believe you can easily plot points in 3D space with lines betweens pairs of 
points:

require 'plot'
plot (; 2 ; 1) i:10j100

Cheers,
Louis

> On 28 Oct 2017, at 15:12, 'Skip Cave' via Programming 
>  wrote:
> 
> Thanks to Raul & Esa for their very clear instructions and examples for
> plotting points in 2D space.
> 
> I originally thought that my plot post was overlooked, so I re-posted it
> under a more descriptive
> title. Then I saw Raul & Esa's posts, so you can ignore that post.
> In any case, Raul & Esa's answers have resolved part of my requirements.
> 
> However, I need to plot 3D point plots as well. So I may need to look at GNU
> Plot, or
> perhaps Mathematica, to do the 3D plots. I also need to draw lines between
> the pairs of points
> (between each left argument point and it's corresponding right argument
> point) in both 2D & 3D plots.
> 
> I might be willing to pay for someone to update the J plot package to
> handle point plots and lines
> between point pairs. Anyone interested?
> 
> Skip
> 
> <<< >>>
> 
>> On Sat, Oct 28, 2017 at 1:53 AM, Raul Miller  wrote:
>> 
>> I had to study the plot docs, and experiment a little. The page
>> http://code.jsoftware.com/wiki/Plot/Data is probably the most
>> important to understand.
>> 
>> For your item 1, something like this might work (change the pensize to
>> change the size of the dots - the default size is too small for a
>> graph with only a few dots):
>> 
>>  'type dot;pensize 5' plot ;/|:0 0, 2 _3, _1 2, 1 1,_1 _2,: 3 4
>> 
>> Note, especially, that I used ,: between the last pair of points so
>> these would form into a matrix rather than a long vector. (And then I
>> flipped the matrix on its side with |: and broke it into x and y
>> elements using ;/ so that plot would recognize the data in the way you
>> wanted it to.)
>> 
>> For your item 2, I just now saw Lippu Esa post what looks like a good
>> answer while I was composing this message.
>> 
>> For your item 4 ..  according to
>> http://code.jsoftware.com/wiki/Plot/Types plot currently does not
>> support dot plots for 3d data. I sometimes struggle understanding
>> plot's limitations, but since I have not been prepared to rewrite it,
>> I mostly just accept them as they are. Still, we could use a stick
>> plot:
>> 
>>'type stick; pensize 5' plot ;/|:_1 _1 _1,0 0 0, 2 _3 1, _1 2 0, 1
>> 1 1,_1 _2 3,: 3 4 2
>> 
>> Sadly, it looks like a stick plot does not adequately show some
>> points. We could work around that by adding another point to force a
>> different bounding box:
>> 
>>  'type stick; pensize 5' plot ;/|:_1 _1 _1,0 0 0, 2 _3 1, _1 2 0, 1 1
>> 1,_1 _2 3,: 3 4 2
>> 
>> There might be a better way?
>> 
>> For your item 5, you can also set the observer viewpoint:
>> 
>>'type stick; pensize 5; viewpoint _1.6 _2.4 1.5' plot ;/|:0 0 0, 2
>> _3 1, _1 2 0, 1 1 1,_1 _2 3,: 3 4  2
>> 
>> And, finally, for your item 6, you would probably want to break up
>> this one-liner into a sequence of commands, as was illustrated in
>> Lippu Esa's post. (You do get a sequence of commands separated by ; in
>> the left hand argument to plot, but to break up the data and issue
>> commands for different chunks of data you need to work with a sequence
>> of pd statements.)
>> 
>> Thanks,
>> 
>> --
>> Raul
>> 
>> 
>> 
>> 
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-10-22 Thread Louis de Forcrand
I’ve been trying to simply count solutions. The best I could do is with the 
prime decomposition powers.

Say we want to find the number of unordered solutions to
n = */v
solving for vector v where n is a scalar, and both are non-negative integers.

Let p=: {: __ q: n.
Then we need to “partition” these powers into #v buckets.

For each x in p we need to calculate a sort of “ordered partition number” of x. 
That is, in x=4 and 3 = #v:
4 + 0 + 0
0 + 4 + 0
0 + 0 + 4
3 + 1 + 0
3 + 0 + 1
1 + 3 + 0
1 + 0 + 3
0 + 3 + 1
0 + 1 + 3
2 + 1 + 1
1 + 2 + 1
1 + 1 + 2
are all possible “partitions” of x.
More specifically, we need to count the number of functions f from {1...#v} to 
the naturals such that x = +/f”0 >:i.#v.

Then we could simply take the product of f applied to each of the items of p 
and divide by !#v.

Unfortunately I doubt counting valid f is easy, and I haven’t found anything 
yet.

Cheers,
Louis

> On 22 Oct 2017, at 12:53, R.E. Boss  wrote:
> 
> In one of my more successful years I studied partitions as well, see 
> http://www.jsoftware.com/pipermail/programming/2006-September/003209.html
> 
> 
> R.E. Boss
> 
> 
>> -Original Message-
>> From: Programming [mailto:programming-boun...@forums.jsoftware.com]
>> On Behalf Of Rob B
>> Sent: zondag 22 oktober 2017 11:40
>> To: programm...@jsoftware.com
>> Subject: Re: [Jprogramming] Partitions
>> 
>> In the twelvefold way at https://www.johndcook.com/TwelvefoldWay.pdf I
>> think this is case 6, labelled, unlabelled, >=1.
>> 
>> Regards, Rob.
>> 
>>> On 22 Oct 2017, at 01:29, Rob Hodgkinson  wrote:
>>> 
>>> Skip, not sure the status of a solution for this yet (Raul’s was last 
>>> closest I
>> believe ?).
>>> 
>>> I thought through the following analysis over the weekend, more around
>> combinatorics.
>>> 
>>> Problem is to split a list of objects o, into y “buckets” and you want to 
>>> all the
>> ways possible given the constraints below.
>>> 
>>> A combinatoric view is to consider filling each bucket (without
>>> replacement) until no more objects, for example; Suppose 7 objects (e.g.
>> ‘abcdefg’) split into 3 buckets of size 2 3 2.
>>>   There are 2C7 (or 2!7) ways to fill the first bucket, leaving 5 left.
>>>   From these 5 there are then 3!5 ways to fill the second bucket, leaving 2
>> left.
>>>   From these 2 there are then 2!2 ways to fill the last bucket
>>> 
>>> The combinations (with decreasing sample sets) can be calculated as
>> follows (I pasted in Courier New, hope this appears OK).
>>>  smoutput bset=:(+/bsize)- +/\ 0,}:bsize=:2 3 2
>>> 7 5 2
>>> 
>>> So from the reducing sample from which to fill each successive bucket, the
>> possible combinations are:
>>>  bsize ! bset=:(+/bsize)- +/\ 0,}:bsize=:2 3 2
>>> 21 10 1
>>> 
>>> And the combinations in each bucket are then “indices” within each bucket
>> from the available objects remaining;
>>>  smoutput bcombs=:bsize comb each bset=:(+/bsize)- +/\ 0,}:bsize=:2 3
>>> 2 ┌───┬─┬───┐
>>> │0 1│0 1 2│0 1│
>>> │0 2│0 1 3│   │
>>> │0 3│0 1 4│   │
>>> │0 4│0 2 3│   │
>>> │0 5│0 2 4│   │
>>> │0 6│0 3 4│   │
>>> │1 2│1 2 3│   │
>>> │1 3│1 2 4│   │
>>> │1 4│1 3 4│   │
>>> │1 5│2 3 4│   │
>>> │1 6│ │   │
>>> │2 3│ │   │
>>> │2 4│ │   │
>>> │2 5│ │   │
>>> │2 6│ │   │
>>> │3 4│ │   │
>>> │3 5│ │   │
>>> │3 6│ │   │
>>> │4 5│ │   │
>>> │4 6│ │   │
>>> │5 6│ │   │
>>> └───┴─┴───┘
>>> So for example the first row in each bucket only says e.g. from ‘abcdefg’,
>> choose (‘ab’;’cde’;’fg’), the first “trial”.
>>>  $ each bcombs
>>> ┌┬┬───┐
>>> │21 2│10 3│1 2│
>>> └┴┴───┘
>>> 
>>> This shows there would be 210 possible combinations (trials), although I am
>> unclear on your rule 5 below, to remove “like” combinations, but this could
>> be achieved post the algorithm.
>>> To get the actual 210 samples you could then index into each cell, but the
>> “samples remaining” would then change for each combination.
>>> 
>>> For example, bucket1 is straightforward to calculate, along with the
>> remainder samples available to fill the remaining buckets …
>>>  smoutput bucket1=:'abcdefg' {~ >{.bcombs ab ac ad ae af ag bc bd be
>>> bf bg cd ce cf cg de df dg ef eg fg
>>>  bucket1;'abcdefg'-."1 bucket1
>>> ┌──┬─┐
>>> │ab│cdefg│
>>> │ac│bdefg│
>>> │ad│bcefg│
>>> │ae│bcdfg│
>>> │af│bcdeg│
>>> │ag│bcdef│
>>> │bc│adefg│
>>> │bd│acefg│
>>> │be│acdfg│
>>> │bf│acdeg│
>>> │bg│acdef│
>>> │cd│abefg│
>>> │ce│abdfg│
>>> │cf│abdeg│
>>> │cg│abdef│
>>> │de│abcfg│
>>> │df│abceg│
>>> │dg│abcef│
>>> │ef│abcdg│
>>> │eg│abcdf│
>>> │fg│abcde│
>>> └──┴─┘
>>> The steps would be repeated for each product, at each stage “expanding”
>> the combinations within each bucket by the successive indices (avoiding
>> selecting any items already in existing buckets).
>>> This will become a cartesian product of samples at each iteration to
>> generate the final 210 samples.
>>> 
>>> This would likely involve recursion or some form of (f ,/), 

Re: [Jprogramming] load'plot'

2017-10-19 Thread Louis de Forcrand
Otherwise if you just want the plot package I believe the following works:

load ‘pacman’
‘install’ jpkg ‘search’ jpkg ‘plot’

You could make sure that ‘search’ jpkg ‘plot’ brings up only one result.

Louis

> On 19 Oct 2017, at 20:02, Raul Miller  wrote:
> 
> I think I would try:
> 
>   install'all'
>   load'plot'
> 
> Thanks,
> 
> -- 
> Raul
> 
> 
> On Thu, Oct 19, 2017 at 2:01 PM, 'Bo Jacoby' via Programming
>  wrote:
>> What to do?Thanks. Bo.
>>   load 'plot'not found: 
>> c:/users/admin/downloads/j805_win32/j805/addons/graphics/plot/plot.ijs|file 
>> name error: script| 0!:0 y[4!:55<'y'
>> JVERSIONEngine: j805/j32/windowsRelease-b: 
>> commercial/2017-04-20T13:26:01Library: 8.05.14Qt IDE: 1.5.4/5.6.2Platform: 
>> Win 32Installer: J805 installInstallPath: 
>> c:/users/admin/downloads/j805_win32/j805Contact: www.jsoftware.com
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
> --
> For information about J forums see http://www.jsoftware.com/forums.htm

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

Re: [Jprogramming] Jx 1.1 Release

2017-10-08 Thread Louis de Forcrand
Maybe he didn’t understand your original question?

In any case it seems you could use a lesson in good manners.

Louis

> On 8 Oct 2017, at 10:58, Erling Hellenäs  wrote:
> 
> Many people here have a habit of giving long lectures to people about things 
> they already know to make it appear like they are totally stupid and they 
> themselves are very clever and are teaching this stupid person even the most 
> basic things. /Erling
> 
>> On 2017-10-08 01:25, Don Guinn wrote:
>> I don't think that it works like you would expect.
>> 
>>(p , 0 $ p =: ]) 'erling'
>> erling
>>p
>> ]
>>(p , 0 $ 'p' =: ]) 'erling'
>> erling
>>p
>> ]
>>(p , 0 $ 'p' =: ])
>> p , 0 $ ]
>>4 !:0 <'p'
>> 3
>> 
>> Turns out that "p" is a verb who's value is "]", as you would expect. And
>> of course the result of the expression is the right argument.
>> 
>>(p , 1 $ p =: ]) 'erling'
>> erlinge
>> 
>> But as you can see the assignment disappears. The test above shows that
>> both "p"s select the right argument.
>> 
>> On Sat, Oct 7, 2017 at 3:31 PM, Erling Hellenäs 
>> wrote:
>> 
>>> Hi all !
>>> 
>>> I was trying to understand how thecopula verbs =..and=:: works in tacit
>>> expressions.
>>> 
>>>(p , 0 $ 'p' =.. ]) 'erling'
>>> |value error: p
>>> |   (p,0$'p'=..])'erling'
>>>('p' =.. ]) 'erling'
>>> erling
>>> 
>>>(p , 0 $ 'p' =.. ]) 'erling'
>>> erling
>>>(p , 0 $ 'p' =.. ]) 'fredrik'
>>> erling
>>>(p , 0 $ 'p' =.. ]) 'fredrik'
>>> fredrik
>>>(p , 0 $ 'p' =.. ])
>>> 'fredrik' , 0 $ 'p' =.. ]
>>> 
>>> I wonder if it is really useful in tacit expressions, and in that case,
>>> how it can be used.
>>> It is only used to set variables outside of the expressions, not to use
>>> the variables in the expressions?
>>> Useful in for example debugging?
>>> 
>>> This is from the documentation:
>>> "The copula verbs =..and=:: are similar to their corresponding copulas but
>>> are syntactically dyadic verbs and may be embedded in tacit expressions."
>>> 
>>> Cheers,
>>> 
>>> Erling Hellenäs
>>> 
>>> 
>>> 
 On 2017-10-07 16:09, Erling Hellenäs wrote:
 
 Hi all!
 
 We are micro-blogging about Jx here. https://twitter.com/erlheldata
 
 Cheers,
 
 Erling Hellenäs
 
> On 2017-10-06 17:01, 'Mike Day' via Programming wrote:
> 
> Thanks, BIll
> I probably knew that route sometime in the past.
> 
> Just in case someone else needs to know,  this is what I've actually
> done.  This is for Windows 10,  as I said earlier:-
> 
> - "create shortcut" from each of the "shortcuts" seen in the Windows
>"desktop" (as installed for jqt and jconsole)
> - rename each according to taste
> - edit the "target" shown in their "properties" dialogue,
>according to your suggestion,  but with full pathname for
>"jx.dll",
>   in my case: C:\d\j806\bin\jqt.exe -lib C:\d\j806\bin\jx.dll
> 
> Pace Thomas Costigliola,  I had tried duplicating the whole installation,
> but that's rather greedy for space!
> 
> Thanks to both,
> 
> Mike
> 
> PS - should debug work under JQt with jx.dll ?
> CTRL-K invokes a domain error for me:
> |domain error: script
> 
> | FRINGEBORDER=: (<0 0 0 1)"0 FRINGECOLOR
> 
> |[-4849] c:\d\j806\addons\debug\dissect\dissect.ijs
> 
> 
> clicking instead on Run/Debug results in
> 
> |value error: jdebug_run
> 
> | jdebug_run 0
> 
> 
> M
> 
> 
> 
>> On 06/10/2017 03:46, bill lam wrote:
>> 
>> Rename the jx j.dll as jx.dll, then type
>> jconsole -lib jx.dll
>> jqt -lib jx.dll
>> 
>> Or rename the official j.dll depending which one will become your
>> favorite.
>> 
>> On Oct 5, 2017 5:29 PM, "'Mike Day' via Programming" <
>> programm...@jsoftware.com> wrote:
>> 
>> OK - I've got the Jx 1.1 j.dll and the various accessory information,
>>> but
>>> suppose I want
>>> 
>>> to try jx and compare it with the "orthodox" J806?
>>> 
>>> Do you advocate setting up a complete "JX" installation parallel with
>>> J806
>>> (or J805 ...),
>>> 
>>> or can it somehow share those orthodox folder/s,  given that j.dll is
>>> the
>>> only difference?
>>> 
>>> Thanks,
>>> 
>>> Mike
>>> 
>>> On 30/09/2017 22:27, Jose Mario Quintana wrote:
>>> 
>>> Jx 1.1 Release
 A Jx v1.1 Extensions Guide, a J/Jx Cheatsheet, a Jx Assertions script
 together with links to a Windows 64 bit dll, a Unix 64 bit so binaries
 (without avx support) and the patch corresponding to the J806 source
 (beta-6) can be found at the link [0].
 
 Summary
 
 - Primitives
   Added =.. =:: $:: [. ]. ]: ".. `. &:.(*) ?:(*) i.. O.
   Extended  ~ $.
   Modified  " 

Re: [Jprogramming] (no subject)

2017-10-03 Thread Louis de Forcrand
Here is another approach using __: to generate only unique factors due to 
their unique prime factorisations:

factors=: (*/ . ^ [: |:@:>@,@{ <@i.@>:)/@(__:)

Cheers,
Louis

> On 3 Oct 2017, at 12:23, Erling Hellenäs  wrote:
> 
> Hi all!
> 
> a=: 2 5 7
> f=: 1 :'/:~ (#: }. i.2^#y) u@# y'
>+/f a
> 2 5 7 7 9 12 14
>*/f a
> 2 5 7 10 14 35 70
> ┌─┬───┬─┬───┬─┬───┬─┐
> │2│2 5│2 5 7│2 7│5│5 7│7│
> └─┴───┴─┴───┴─┴───┴─┘
> 
> With the no element combination deliberately dropped.
> 
> Cheers,
> Erling
> 
> 
> 
>> On 2017-10-03 00:45, Erling Hellenäs wrote:
>> Hi all !
>> 
>>a=: 2 5 7
>>f=: 1 : '/:~(#: }. i. 2 ^ # y) ([: u/ #) /"1 y'
>>+ f a
>> 2 5 7 7 9 12 14
>>* f a
>> 2 5 7 10 14 35 70
>> 
>> Cheers,
>> Erling
>> 
>>> On 2017-10-02 19:45, Erling Hellenäs wrote:
>>> Hi all!
>>> 
>>> You don't want the combination of zero elements?
>>> 
>>>a=: 2 5 7
>>>/:~(#: i. 2 ^ # a) ([:+/#) /"1 1 a
>>> 0 2 5 7 7 9 12 14
>>>/:~(#: i. 2 ^ # a) ([:*/#) /"1 1 a
>>> 1 2 5 7 10 14 35 70
>>> 
>>> Guess I could drop it.
>>> 
>>> Cheers,
>>> 
>>> Erling
>>> 
 On 2017-10-02 18:49, Skip Cave wrote:
 Given a set of integers, what is the most concise and or efficient way to
 list the numbers along with the sum of all combinations of the numbers? the
 products of all combinations?
 
 for example:
 
 a =. 2 5 7
 + f aNB. 2, 5, 7, (2+5), (2+7), (5+7), (2+5+7)
 2 5 7 7 9 12 14
 
 * f aNB. 2, 5, 7, (2*5), (2*7), (5*7), (2*5*7)
 2 5 7 10 14 35 70
 
 The function 'f' should work for any verb and any size right argument noun
 vector.
 
 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

Re: [Jprogramming] Composition conjunctions

2017-10-02 Thread Louis de Forcrand
Beyond wether these tests are useful or not, you should run "ts" with a left 
argument, as a single run which lasts only 0.1 seconds can be somewhat 
imprecise.
ts's left argument n is the number of times to run the string of code, and its 
result will be the total time elapsed divided by n.

Cheers,
Louis

> On 2 Oct 2017, at 19:51, Erling Hellenäs  wrote:
> 
> Hi all!
> 
> If something is not interesting or important, a good general idea could be to 
> not spend forum time on lengthy  discussions about it?
> Normally, if I get spammed like this, I would assume that what I said WAS 
> important, and I'd repost it and write more about it. However, since this is 
> a proprietary mail list I will have to leave that to the  readers.
> 
> Cheers,
> Erling
>> On 2017-10-02 19:26, Don Guinn wrote:
>> Detailed measurements are useful and meaningful if your application is
>> performing badly. But general statements about poor performance in parts of
>> an application that isn't used much is a waste of time.
>> 
>> @ vs. @: is a concern but blanket proclamations is wrong. Today @ performs
>> better than @: most of the time, especially for primitives. But for defined
>> verbs, depending on the design, there may be no performance gain and a lot
>> of wasted memory.
>> 
>> If you have an app with a performance problem then run a tool to find out
>> where you're spending the time. J has such a tool, as do almost all
>> programming languages. Now you know where to spend your time.
>> 
>> And you may find out that the problem is not in J, but in your design.
>> 
>> There is no argument that @ has much room for improvement. Which seems to
>> be what your beef is about. So you're wasting your time and everybody
>> else's time proving the obvious.
>> 
>>> On Oct 2, 2017 10:06 AM, "Erling Hellenäs"  wrote:
>>> 
>>> You are welcome to show us better measurements if you think these
>>> measurements are very important and worthy of a lengthy discussion in the
>>> forum. /Erling
>>> 
 On 2017-10-02 17:53, Raul Miller wrote:
 
 The null case here should be ]
 
 (-@- -: ]) v
 1
 
 Thanks,
 
 
>>> --
>>> 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] Agenda in explicit expressions WAS: Tacit Expressions with Explicit J Syntax

2017-09-30 Thread Louis de Forcrand
That's what I understood from the J dictionary, NuVoc, and personal experience:
$: refers to the *largest, unnamed, tacit* verb containing it. And by "tacit" 
here I mean in the same "colon-level" as the $: in question.
For example:
In
$: @ (3 : 'y')
$: refers to the whole verb.
In
3 : '$: y'
it refers to itself only.
In
3 : '$:@>: y'
it refers to $:@>:.
In
$:@>:
it refers to the whole tacit verb, but in
u=: v@>:
v=: $:
it refers to only v.

So in your examples Erling, $: in those explicit definitions refers only to 
itself, which obviously leads to a stack error. Use the explicit verb's name if 
you need recursion in an explicit verb.

Louis

> On 1 Oct 2017, at 00:54, Raul Miller  wrote:
> 
> Hmm.. after re-reading the dictionary definition, I think I was wrong
> when I said that
>  x $: <: y
> was the meaning for $: in that second example:
> 
> Since no verbs are formed in that sentence, $: just refers to itself
> as the largest containing verb.
> 
> Please tell me if you have reason to think I'm wrong about this.
> 
> Thanks,
> 
> -- 
> Raul
> 
> 
>> On Sat, Sep 30, 2017 at 6:44 PM, Henry Rich  wrote:
>> The problem is that we mean different things by 'work'.  To me, that means
>> it behaves the way NuVoc says it does.  I get the feeling that to you,
>> 'works' means it behaves the way you want it to.
>> 
>> It works, by my meaning.  The Dictionary is not precise about the behavior
>> of $: in explicit definitions.
>> 
>> Henry Rich
>> 
>> 
>>> On 9/30/2017 6:04 PM, Erling Hellenäs wrote:
>>> 
>>> I guess it would be impossible to get you to acknowledge that it does not
>>> work  with explicit J in agenda :) /Erling
>>> 
 On 2017-09-30 23:16, Raul Miller wrote:
 
 Yes, if you want to explicitly reference the definition of f, you
 should use the name f (like you used at first), and not $:
 
 $: refers to the containing sentence, which in your example was
x $: <: y
 
 To have $: mean something different you need to use it in a different
 sentence (which is entirely possible, of course).
 
 Thanks,
 
>>> 
>>> --
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>> 
>> 
>> 
>> ---
>> This email has been checked for viruses by AVG.
>> http://www.avg.com
>> 
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
> --
> For information about J forums see http://www.jsoftware.com/forums.htm

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

Re: [Jprogramming] Tacit Expressions with Explicit J Syntax

2017-09-28 Thread Louis de Forcrand
I don't really understand what you wish to add either, Erling.

If you want to use explicit J syntax, you could write an explicit verb.

You write:
> Particularly to create what you most commonly need, a sequence of
> monadic verbs, each acting on the result of the verb to the right.
> Well, it is not complicated as such, but for some reason people don't like
> the obvious way to do it, which is [: f [: g [: h ]. Then they dive into a
> mess of complications. I mean the cap should not be necessary. That simple
> right to left execution should be the default, possibly modified with
> parenthesis. That tacit and explicit J should have the same basic syntax.

f@:g@:h?
In addition, I disagree with your last two sentences. What's the point of 
having tacit syntax if it's the same as explicit syntax? If you want explicit 
syntax, write an explicit verb; other times tacit syntax is really practical.
In an explicit verb, simple right to left execution *is* the default.

In any case I don't really see how the rest of your suggestion differs from 
Henry's (.). verbs, which I like very much by the way.

Cheers,
Louis

> On 28 Sep 2017, at 14:53, Raul Miller  wrote:
> 
> Jose's work is impressive, but I try to avoid it because of the extra
> complexity it creates when I want to (for example) provide a parameter
> in clauses for conjunctions like &. -- the extra complexity can be a
> nice mental exercise and maybe even a cure for boredom, but I feel
> that I have the right to treat it as unnecessary.
> 
> Thanks,
> 
> -- 
> Raul
> 
> 
> On Thu, Sep 28, 2017 at 8:33 AM, Erling Hellenäs
>  wrote:
>> Hi all !
>> 
>> I am very impressed by Jose's work and I think it is an excellent
>> illustration to why we need the modification to J I propose.
>> It is extremely  complicated to do these things which should be simple, as I
>> see it. Particularly to create what you most commonly need, a sequence of
>> monadic verbs, each acting on the result of the verb to the right.
>> Well, it is not complicated as such, but for some reason people don't like
>> the obvious way to do it, which is [: f [: g [: h ]. Then they dive into a
>> mess of complications. I mean the cap should not be necessary. That simple
>> right to left execution should be the default, possibly modified with
>> parenthesis. That tacit and explicit J should have the same basic syntax. I
>> tried my ideas of a different tacit J in a test implementation and it was
>> great.
>> 
>> Cheers,
>> Erling Hellenäs
>> 
>> 
>>> On 2017-09-28 05:29, Jose Mario Quintana wrote:
>>> 
>>> Hi Erling,
>>> 
>>> You are right, the adverb (At) produces tacit sentences but it is really
>>> an
>>> implementation of Dan's pipeline proposal using strand notation via a
>>> Curried adverb (aka, recurrent adverb and multiple adverb).
>>> 
>>> However, I have written (tacitly) a tacit Curried adverb (xi) which, using
>>> a lambda-style syntax, produces a tacit verb which in turn, given its
>>> arguments, produces tacit entities.  You might find xi interesting; the
>>> general form is,
>>> 
>>> t=. [: v0 v1 ... vn '...' xi
>>> 
>>> The names v0 v1 ... vn should be syntactically verbs (recall, xi is a
>>> Curried adverb) but they can represent nouns, verbs, adverbs, or
>>> conjunctions.  I use undefined names since those are regarded by default
>>> as
>>> verbs (even if xi does not affect in any way the named verbs).  The
>>> literal
>>> '...' represents a quoted J (or more generally a Jx) sentence.
>>> 
>>> This is how your example can be written using xi,
>>> 
>>>erase 'b v'
>>> 
>>>[: v '([: b ''<:b++/\b-~-.b'' xi <''\''=v){."0 v' xi <'\\\//\\\//'
>>> \
>>>  \
>>>   \
>>>   /
>>>  /
>>>  \
>>>   \
>>>\
>>>/
>>>   /
>>> 
>>> There is the nuisance of quotes within quotes and the argument must be
>>> boxed; however, this allows, in general, the verb (t) to produce a noun, a
>>> verb, an adverb, or a conjunction and to take multiple boxed nouns, verbs,
>>> adverbs, or conjunctions as its argument.  The following verb (t) acts
>>> directly on a couple of (boxed) verbs and produces a verb,
>>> 
>>>t=. [: u v 'u/@:v' xi
>>> 
>>>t[:+*:]: NB. Sum of squares
>>> +/@:*:
>>>t[:+*:]: 1 2 3 4 5
>>> 55
>>> 
>>>t[:-%:]: NB. Difference of square roots
>>> -/@:%:
>>>t[:-%:]: 1 2 3 4 5
>>> 1.55390522
>>> 
>>> Note that the Curried higher-order verb (t) is, in effect, acting on two
>>> arguments: [:-%:]: and 1 2 3 4 5; furthermore, t [:-%:]: performs a
>>> partial
>>> application of the verb (t) acting on [:-%:]: .
>>> 
>>> The following are variations of the verb produced in [0], the verb (t)
>>> acts on a (boxed) conjunction and produces an adverb,
>>> 
>>>t=. [: u '(ver adv u)&:train/adv' xi
>>> 
>>>]`{.`{:`{: (t [:(>> ]@:({.@:({:@:{:))
>>> 
>>>]`{.`{:`{: (t [:(>> ]@({.@({:@{:))
>>> 
>>>]`{.`{:`{: (t [:(

Re: [Jprogramming] Ranges

2017-09-24 Thread Louis de Forcrand
You could compress twice:

drng=: {.@[ (<: # ]) {:@[ (>: # ]) ]

Perhaps faster on large data?
You could reorder and filter out the data under the lower bound first if your 
data is usually smaller than it to speed up the verb.

Louis

> On 24 Sep 2017, at 22:37, Joey K Tuttle  wrote:
> 
> Yes, my bad. I did sort and forgot that I had. I should have caught that 
> silliness - sorry for the noise. 
> 
> This was a problem that I worked on in APL back in 1971 when I had a tape 
> with many thousands of data points and wanted to put them in buckets 
> (actually just count them) - it was that struggle that inspired putting /. 
> into j.   
> 
> The problem was made a little harder by only having 64kbytes of workspace 
>  Ah, how times have changed!
> 
> - joey
> 
>> On 2017Sep 24, at 13:22, Skip Cave  wrote:
>> 
>> I suspect that Joey sorted a before breaking it into ranges:
>> 
>>   ]b =. /:~ a
>> 
>> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
>> 
>> 
>>   /:~ ( 5 10 15 I. b) > 
>> ┌─┬──┬──┬──┐
>> 
>> │1 2 3 4 5│6 7 8 9 10│11 12 13 14 15│16 17 18 19 20│
>> 
>> └─┴──┴──┴──┘
>> 
>> 
>> In that case you don't need the final sort:
>> 
>> 
>>   ( 5 10 15 I. b) > 
>> ┌─┬──┬──┬──┐
>> 
>> │1 2 3 4 5│6 7 8 9 10│11 12 13 14 15│16 17 18 19 20│
>> 
>> └─┴──┴──┴──┘
>> 
>> 
>> Skip Cave
>> Cave Consulting LLC
>> 
>>> On Sun, Sep 24, 2017 at 3:15 PM, Skip Cave  wrote:
>>> 
>>> Joey T. said:
>>> 
>>>   /:~ (0 5 10 15 I. a) >> ┌─┬──┬──┬──┐
>>> │1 2 3 4 5│6 7 8 9 10│11 12 13 14 15│16 17 18 19 20│
>>> └─┴──┴──┴──┘
>>> 
>>> However when I try the same thing:
>>> 
>>> /:~ (0 5 10 15 I. a) >> 
>>> ┌─┬──┬──┬──┐
>>> 
>>> │2 5 3 1 4│9 7 8 10 6│12 14 11 13 15│20 19 16 18 17│
>>> 
>>> └─┴──┴──┴──┘
>>> 
>>> j805/j64/windows
>>> 
>>> Library 8.05.14
>>> 
>>> 
>>> So on Joey's system the box contents and the boxes are sorted. On my
>>> system just the boxes are sorted. ???
>>> 
>>> 
>>> Skip
>>> 
>>> Skip Cave
>>> Cave Consulting LLC
>>> 
 On Sun, Sep 24, 2017 at 3:03 PM, Joey K Tuttle  wrote:
 
   /:~ (0 5 10 15 I. a) >>> ┌─┬──┬──┬──┐
 │1 2 3 4 5│6 7 8 9 10│11 12 13 14 15│16 17 18 19 20│
 └─┴──┴──┴──┘
 
 But that is a more boring (and perhaps less useful) result...
 
 
> On 2017Sep 24, at 12:57, Skip Cave  wrote:
> 
> Jimmy G said:
> 
> With key /. and <
> 
> (0 5 10 15 I. a)  
> <<<>>>
> 
>   a
> 
> 9 12 2 20 14 11 13 15 7 5 3 19 8 1 4 16 10 6 18 17
> 
> 
>   (0 5 10 15 I. a)  
> ┌──┬──┬─┬──┐
> 
> │9 7 8 10 6│12 14 11 13 15│2 5 3 1 4│20 19 16 18 17│
> 
> └──┴──┴─┴──┘
> 
> 
> So Jimmy's solution does box the ranges, but the ranges are not in the
> range order specified by the left argument. Why? And how can you create
 a
> verb that will keep the ranges in ascending order?
> 
> 
> 
> Skip Cave
> Cave Consulting LLC
> 
> On Sun, Sep 24, 2017 at 2:37 PM, Jimmy Gauvin 
> wrote:
> 
>> With key /. and <
>> 
>> (0 5 10 15 I. a) > 
>> you can also count them
>> 
>> (0 5 10 15 I. a) #/. a
>> 
>> 
>> On Sun, Sep 24, 2017 at 3:19 PM, Skip Cave 
>> wrote:
>> 
>>> So that brings up another interesting problem. How
>>> to
>>>   box ranges
>>> ​?​
>>> :
>>> 
>>> ]a=:>:?~20
>>> 9 12 2 20 14 11 13 15 7 5 3 19 8 1 4 16 10 6 18 17
>>> 
>>> 0 5 10 15 brng a
>>> ┌─┬──┬──┬──┐
>>> │2 5 3 1 4│9 7 8 10 6│12 14 11 13 15│20 19 16 18 17│
>>> └─┴──┴──┴──┘
>>> 
>>> S
>>> ​o how do you construct brng?​
>>> 
>>> Skip Cave
>>> Cave Consulting LLC
>>> 
>>> On Sun, Sep 24, 2017 at 2:09 PM, 'Mike Day' via Programming <
>>> programm...@jsoftware.com> wrote:
>>> 
 I was about to send something when we had to go out for a bit...
 
 My best so far is
 ((] #~ 1 = I.)~ (0 _1 + ])) ~
 assuming I've copied it correctly...
 
 Mike
 
 Please reply to mike_liz@tiscali.co.uk.
 Sent from my iPad
 
> On 24 Sep 2017, at 18:45, Skip Cave 
 wrote:
> 
> Marshall,
> 
> Wow! that 

Re: [Jprogramming] Gerund composed application

2017-09-24 Thread Louis de Forcrand
   rob=: {: ,~ ({.[:`'') ,@,. }:
   g=: %:`*:`+:
   g
+--+--+--+
|%:|*:|+:|
+--+--+--+
   rob g
+--+--+--+--+--+
|[:|%:|[:|*:|+:|
+--+--+--+--+--+
   (rob g)`:6]5
10

"rob" transforms your gerund into a suitable train. You can then apply it with 
`:6.

Cheers,
Louis

> On 24 Sep 2017, at 20:35, Rob Moore  wrote:
> 
> Thanks for replying Raul, your solutions weren't what I was looking for,
> but I understand the confusion from my first explanation.
> 
> Jose your first solution worked perfectly, thanks very much! The other two
> solutions you gave caused syntax errors for me, must be different versions,
> I'm on 604.
> 
> What did you mean by compliant and non-compliant in your comments?
> 
> Thanks,
> 
> Rob
> --
> 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] Quora Challenge

2017-09-16 Thread Louis de Forcrand
lnps=: 4 : 0
(i{p)+}.i.d{~i=. (i.>./)d=. 2-~/\p=. (<:x),(p:([+i.@-~)/_1 p:x,y),>:y
)

Cheers,
Louis

> On 15 Sep 2017, at 18:24, Raul Miller  wrote:
> 
> Oh, oops...
> 
> thru=: <. + i.@(+ *@+&0.5)@-~
> biggap=: {~ (0 1 + [: (i. >./) 2 -~/\ ])
> f=: [: thru/ 1 _1 + [: biggap <./ >. >./ <. thru&.(p:inv)
> 
> Thanks,
> 
> -- 
> Raul
> 
>> On Fri, Sep 15, 2017 at 12:08 PM, Skip Cave  wrote:
>> Something is wrong with Raul's 'f'
>> 
>>   10 f 100
>> 
>> 90 91 92 93 94 95 96
>> 
>>100 f 200
>> 
>> 114 115 116 117 118 119 120 121 122 123 124 125 126
>> 
>> 200 f 300
>> 
>> 294 295 296 297 298 299 300 301 302 303 304 305 306
>> 
>> That last list isn't in the interval 200, 300
>> 
>> Skip
>> 
>>> On Fri, Sep 15, 2017 at 7:40 AM, Raul Miller  wrote:
>>> 
>>> Do you mean like this?
>>> 
>>> thru=: <. + i.@(+ *@+&0.5)@-~
>>> biggap=: {~ (0 1 + [: (i. >./) 2 -~/\ ])
>>> f=: [: thru/ 1 _1 + [: biggap thru&.(p:inv)
>>> 
>>> Thanks,
>>> 
>>> --
>>> Raul
>>> 
>>> On Fri, Sep 15, 2017 at 5:36 AM, Skip Cave 
>>> wrote:
 Write a function f, which will list the longest set of consecutive
 non-prime integers between two prime numbers in the interval x, y
 
 for example:
 
   10 f 100
 90 91 92 93 94 95 96
 
 
 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

Re: [Jprogramming] Puzzling result

2017-09-10 Thread Louis de Forcrand
Sorry if that came through as a request for addition of extended complex 
numbers. I was just pointing out that they weren't there. (maybe not very well 
though?)
They are definitely not worth the time or effort.

Louis

> On 10 Sep 2017, at 03:28, HenryRich <henryhr...@gmail.com> wrote:
> 
> We could get a few more bits if we needed them.  But supporting a new 
> datatype like this would take many months of work, for minimal value.
> 
> Henry Rich
> 
>> On 9/9/2017 9:10 PM, bill lam wrote:
>> Each j datatype is assigned a number of value 2^n and it is already almost
>> used up (only 32-bit range is used to stay compatible with J32). The latest
>> addition is literal4 in j805. IMO extended complex or extended complex
>> rational are unlikely to be a candidate to use the nearly used up resource.
>> 
>> On Sep 10, 2017 8:02 AM, "Louis de Forcrand" <ol...@bluewin.ch> wrote:
>> 
>> I don't know; I hardly ever use extended precision or rationals myself
>> either. I guess it would make the language more "complete".
>> Definitely not a priority.
>> 
>> Louis
>> 
>>> On 9 Sep 2017, at 11:34, Raul Miller <rauldmil...@gmail.com> wrote:
>>> 
>>> What would it be used for? (Related: how would the exponential aspects
>>> of complex number operations get handled?)
>>> 
>>> Thanks,
>>> 
>>> --
>>> Raul
>>> 
>>> 
>>>> On Sat, Sep 9, 2017 at 4:57 AM, Louis de Forcrand <ol...@bluewin.ch>
>> wrote:
>>>> There is no extended complex datatype in J (although its addition could
>> be a thought).
>>>> Louis
>>>> 
>>>>> On 9 Sep 2017, at 09:23, 'Bo Jacoby' via Programming <
>> programm...@jsoftware.com> wrote:
>>>>> 
>>>>>   %2 NB. floating
>>>>> 0.5
>>>>>   x: %2 NB. extended
>>>>> 1r2
>>>>>   %1j1 NB. floating
>>>>> 0.5j_0.5
>>>>>   x: %1j1 NB. why not extended?
>>>>> |domain error
>>>>> | x:%1j1
>>>>> 
>>>>> 
>>>>> 
>>>>>   Den 3:53 lørdag den 9. september 2017 skrev Don Kelly <d...@shaw.ca>:
>>>>> 
>>>>> 
>>>>> It appears that the verb   ^  may be a large part of the problem (as in
>>>>> 14^2). Check NuVoc  /vocabulary/Numeric Precision  and go the table for
>>>>> different verbs . This and the division may be floating point in this
>> case
>>>>> _
>>>>> 
>>>>> ^ ^. -: % %. inexact (complex if needed),
>>>>> 
>>>>> preserves extended and rational
>>>>> if result is exact
>>>>> 
>>>>> _
>>>>> 
>>>>> Don Kelly
>>>>> 
>>>>>> On 2017-09-08 1:36 AM, Raul Miller wrote:
>>>>>> No: integers do not automatically get converted to extended precision.
>>>>>> 
>>>>>> Integers simply have sufficient precision for this example.
>>>>>> 
>>>>>> Thanks,
>>>>>> 
>>>>> --
>>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>>> 
>>>>> 
>>>>> --
>>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>> --
>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>> --
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
> 
> --
> 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] Puzzling result

2017-09-09 Thread Louis de Forcrand
I don't know; I hardly ever use extended precision or rationals myself either. 
I guess it would make the language more "complete".
Definitely not a priority.

Louis

> On 9 Sep 2017, at 11:34, Raul Miller <rauldmil...@gmail.com> wrote:
> 
> What would it be used for? (Related: how would the exponential aspects
> of complex number operations get handled?)
> 
> Thanks,
> 
> -- 
> Raul
> 
> 
>> On Sat, Sep 9, 2017 at 4:57 AM, Louis de Forcrand <ol...@bluewin.ch> wrote:
>> There is no extended complex datatype in J (although its addition could be a 
>> thought).
>> 
>> Louis
>> 
>>> On 9 Sep 2017, at 09:23, 'Bo Jacoby' via Programming 
>>> <programm...@jsoftware.com> wrote:
>>> 
>>> 
>>>   %2 NB. floating
>>> 0.5
>>>   x: %2 NB. extended
>>> 1r2
>>>   %1j1 NB. floating
>>> 0.5j_0.5
>>>   x: %1j1 NB. why not extended?
>>> |domain error
>>> | x:%1j1
>>> 
>>> 
>>> 
>>>   Den 3:53 lørdag den 9. september 2017 skrev Don Kelly <d...@shaw.ca>:
>>> 
>>> 
>>> It appears that the verb   ^  may be a large part of the problem (as in
>>> 14^2). Check NuVoc  /vocabulary/Numeric Precision  and go the table for
>>> different verbs . This and the division may be floating point in this case
>>> 
>>> _
>>> 
>>> ^ ^. -: % %. inexact (complex if needed),
>>> 
>>> preserves extended and rational
>>> if result is exact
>>> 
>>> _
>>> 
>>> Don Kelly
>>> 
>>>> On 2017-09-08 1:36 AM, Raul Miller wrote:
>>>> No: integers do not automatically get converted to extended precision.
>>>> 
>>>> Integers simply have sufficient precision for this example.
>>>> 
>>>> Thanks,
>>>> 
>>> 
>>> --
>>> 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] Puzzling result

2017-09-09 Thread Louis de Forcrand
There is no extended complex datatype in J (although its addition could be a 
thought).

Louis

> On 9 Sep 2017, at 09:23, 'Bo Jacoby' via Programming 
>  wrote:
> 
> 
>%2 NB. floating
> 0.5
>x: %2 NB. extended
> 1r2
>%1j1 NB. floating
> 0.5j_0.5
>x: %1j1 NB. why not extended?
> |domain error
> | x:%1j1
> 
> 
> 
>Den 3:53 lørdag den 9. september 2017 skrev Don Kelly :
> 
> 
> It appears that the verb   ^  may be a large part of the problem (as in 
> 14^2). Check NuVoc  /vocabulary/Numeric Precision  and go the table for 
> different verbs . This and the division may be floating point in this case
> 
> _
> 
> ^ ^. -: % %. inexact (complex if needed),
> 
> preserves extended and rational
> if result is exact
> 
> _
> 
> Don Kelly
> 
>> On 2017-09-08 1:36 AM, Raul Miller wrote:
>> No: integers do not automatically get converted to extended precision.
>> 
>> Integers simply have sufficient precision for this example.
>> 
>> Thanks,
>> 
> 
> --
> 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] Another Quora Problem

2017-08-29 Thread Louis de Forcrand
Stick a pair of parens around the hook, otherwise it executes like any explicit 
sentence!

Louis

> On 29 Aug 2017, at 11:33, Skip Cave <s...@caveconsulting.com> wrote:
> 
> Louis:
> 
> This works:
> 
> +/(#~[:-.2&|)i.43
> 
> 462
> 
> 
> This doesn't:
> 
> +/#~ -.@:(2&|)i.43
> 
> 22
> 
> Skip Cave
> Cave Consulting LLC
> 
>> On Tue, Aug 29, 2017 at 4:17 AM, Louis de Forcrand <ol...@bluewin.ch> wrote:
>> 
>> Also count the verbs in
>> 
>> #~ -. 2&|
>> 
>> With three verbs this evaluates to a fork, so
>> 
>> (#~ -. 2&|) v
>> (#~v) -. 2&|v
>> 
>> which signals a length error because #~ changes the shape of its argument.
>> 
>> What you want is to apply -. mondadically to 2&|, not apply it between #~
>> and 2&|; to do so use a cap [: like so:
>> 
>> #~ [: -. 2&|. (which is a hook with 4 verbs)
>> 
>> This is equivalent to
>> 
>> #~ -.@:(2&|)
>> 
>> Cheers,
>> Louis
>> 
>>> On 29 Aug 2017, at 10:29, Raul Miller <rauldmil...@gmail.com> wrote:
>>> 
>>> You should be using #~ instead of #
>>> 
>>> If you look at your intermediate result without the +/ you will see why.
>>> 
>>> Thanks,
>>> 
>>> --
>>> Raul
>>> 
>>> 
>>>> On Tue, Aug 29, 2017 at 4:04 AM, Skip Cave <s...@caveconsulting.com>
>> wrote:
>>>> There seems to be two basic approaches to this problem:
>>>> 
>>>> 1. Generate the even numbers between 1 & 42, and add them up.
>>>> 2. Use the formula for the sum of an arithmetic progression - e.g.:
>>>> 
>>>> Sum=n(a+b)/2
>>>> *n* = number of numbers in the sequence (here 21)
>>>> *a* = the first number in the sequence (here 2)
>>>> 
>>>> *b* = the last number in the sequence (here 42)
>>>> 
>>>> Generally, I like to approach these kinds of Quora sequence problems
>> using
>>>> a "brute force" approach, and ignore simplifying formulas. In the days
>>>> before modern computers, formulas were developed to make computations on
>>>> sequences like this Quora problem more tractable, particularly when the
>>>> number of terms got large.
>>>> 
>>>> Today, with powerful modern computers and languages, it is often easier
>> to
>>>> simply generate a sequence in it's entirety, and then compute some
>> property
>>>> of that sequence such as it's limit, sum, etc. to get the final result.
>>>> This is particularly true when you have at your fingertips a powerful
>>>> matrix language such as APL or J.
>>>> 
>>>> For me, the obvious approach to this problem is to simply generate the
>>>> sequence of even integers and then sum them, instead of trying to find a
>>>> formula that relates to that specific sequence (in any case, I didn't
>> have
>>>> a clue where to look for such formulas).
>>>> 
>>>> So the plan was: Generate the numbers from 0 to 42, throw out the odd
>>>> numbers (zero doesn't matter in this problem), and then add up what's
>> left:
>>>> 
>>>>   a =:i.43
>>>> 
>>>>   +/(-.2|a)#a
>>>> 
>>>> 462
>>>> 
>>>> 
>>>> My main dissatisfaction was that I was sure that this could be done in a
>>>> single line, but I didn't know how to get the integer sequence on both
>>>> sides of the tally/copy verb, which i wanted to use as a binary selector
>>>> mask.
>>>> 
>>>> Yes, thanks to Raul and others, I now realize that I could have just
>>>> multiplied the first 21 integers by 2 to get all the even integers and
>> then
>>>> sum them, but I wanted to learn how to get the same vector of integers
>> in
>>>> two places in the formula without having to assign that vector to a
>>>> variable.
>>>> 
>>>> Raul showed me how to do that, though he used equality & multiplication
>> to
>>>> generate the selector mask and make the selections.
>>>> 
>>>>   +/(*0=2&|)i.43
>>>> 
>>>> 462
>>>> 
>>>> 
>>>> Raul's multiply by zero trick was cool, but my purist sensibilities
>> still
>>>> wanted to use selection of the even numbers as the most straightforward
>> way
>

Re: [Jprogramming] Another Quora Problem

2017-08-29 Thread Louis de Forcrand
Also count the verbs in

#~ -. 2&|

With three verbs this evaluates to a fork, so

(#~ -. 2&|) v
(#~v) -. 2&|v

which signals a length error because #~ changes the shape of its argument.

What you want is to apply -. mondadically to 2&|, not apply it between #~ and 
2&|; to do so use a cap [: like so:

#~ [: -. 2&|. (which is a hook with 4 verbs)

This is equivalent to

#~ -.@:(2&|)

Cheers,
Louis

> On 29 Aug 2017, at 10:29, Raul Miller  wrote:
> 
> You should be using #~ instead of #
> 
> If you look at your intermediate result without the +/ you will see why.
> 
> Thanks,
> 
> -- 
> Raul
> 
> 
>> On Tue, Aug 29, 2017 at 4:04 AM, Skip Cave  wrote:
>> There seems to be two basic approaches to this problem:
>> 
>> 1. Generate the even numbers between 1 & 42, and add them up.
>> 2. Use the formula for the sum of an arithmetic progression - e.g.:
>> 
>> Sum=n(a+b)/2
>> *n* = number of numbers in the sequence (here 21)
>> *a* = the first number in the sequence (here 2)
>> 
>> *b* = the last number in the sequence (here 42)
>> 
>> Generally, I like to approach these kinds of Quora sequence problems using
>> a "brute force" approach, and ignore simplifying formulas. In the days
>> before modern computers, formulas were developed to make computations on
>> sequences like this Quora problem more tractable, particularly when the
>> number of terms got large.
>> 
>> Today, with powerful modern computers and languages, it is often easier to
>> simply generate a sequence in it's entirety, and then compute some property
>> of that sequence such as it's limit, sum, etc. to get the final result.
>> This is particularly true when you have at your fingertips a powerful
>> matrix language such as APL or J.
>> 
>> For me, the obvious approach to this problem is to simply generate the
>> sequence of even integers and then sum them, instead of trying to find a
>> formula that relates to that specific sequence (in any case, I didn't have
>> a clue where to look for such formulas).
>> 
>> So the plan was: Generate the numbers from 0 to 42, throw out the odd
>> numbers (zero doesn't matter in this problem), and then add up what's left:
>> 
>>a =:i.43
>> 
>>+/(-.2|a)#a
>> 
>> 462
>> 
>> 
>> My main dissatisfaction was that I was sure that this could be done in a
>> single line, but I didn't know how to get the integer sequence on both
>> sides of the tally/copy verb, which i wanted to use as a binary selector
>> mask.
>> 
>> Yes, thanks to Raul and others, I now realize that I could have just
>> multiplied the first 21 integers by 2 to get all the even integers and then
>> sum them, but I wanted to learn how to get the same vector of integers in
>> two places in the formula without having to assign that vector to a
>> variable.
>> 
>> Raul showed me how to do that, though he used equality & multiplication to
>> generate the selector mask and make the selections.
>> 
>>+/(*0=2&|)i.43
>> 
>> 462
>> 
>> 
>> Raul's multiply by zero trick was cool, but my purist sensibilities still
>> wanted to use selection of the even numbers as the most straightforward way
>> to implement the sum of evens.
>> 
>> However, Raul's approach did show me the way. I could use the copy operator
>> to implement the selector mask, instead of multiplication
>> 
>>   +/(#0=2&|)i.43
>> 
>> 462
>> 
>> 
>> That worked, So we should also be able to get the sum of the odd numbers:
>> 
>> 
>>   +/(#2&|)i.43
>> 
>> 441
>> 
>> 
>> Yep. That worked too. So i should also be able use the NOT verb ".-" to
>> invert the selection mask to get the sum of evens like I did in my original
>> attempt:
>> 
>> 
>>+/(#-.2&|)i.43
>> 
>> 43
>> 
>> 
>> K!  What happened? I tried to negate the selection mask, and something
>> went terribly wrong! Maybe I need to isolate the negation:
>> 
>> 
>>+/(#(-.2&|))i.43
>> 
>> |length error
>> 
>> | +/ (#(-.2&|))i.43
>> 
>> 
>> Nope!  What am I doing wrong? How can I simply negate the selection mask,
>> just like I did in my original explicit example?
>> 
>> 
>> 
>> 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

Re: [Jprogramming] Another Quora Problem

2017-08-28 Thread Louis de Forcrand
Not built-in to the language. You could pretend to be the computer and expand 
tacit code yourself while referring to the dictionary, renaming chunks to help 
you.

Otherwise there might be some code somewhere that does this, but I don't know 
of it.

Good luck,
Louis

> On 29 Aug 2017, at 00:00, PR PackRat  wrote:
> 
> Dear Group:
> 
>> On 8/28/17, Jose Mario Quintana  wrote:
>> The tacit translator was my faithful teacher a long time ago and I still
>> use it occasionally, nowadays to understand non-tacit code.
> 
> Is there any translator (or is it impossible?) to go the opposite way,
> that is, tacit to explicit?
> 
> At my basic J level, I write only explicit code, and I would often
> love to know what the various higher level tacit J examples that
> people write mean in explicit terms.
> 
> Harvey  (NOT the hurricane!)
> --
> 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 enclose two columns

2017-08-25 Thread Louis de Forcrand
In general, if you want to apply u along a group of n of axes:

axis=: 2 : 0
u"(#n)@(n&|:)
)

This is I believe very close to the axis operator in APL if you are familiar 
with it:

   ]m=: i.2 3 4
 0  1  2  3
 4  5  6  7
 8  9 10 11

12 13 14 15
16 17 18 19
20 21 22 23
   < axis 0 m
+++-+-+
|0 12|1 13|2 14 |3 15 |
+++-+-+
|4 16|5 17|6 18 |7 19 |
+++-+-+
|8 20|9 21|10 22|11 23|
+++-+-+
   < axis 1 m
+++++
|0 4 8   |1 5 9   |2 6 10  |3 7 11  |
+++++
|12 16 20|13 17 21|14 18 22|15 19 23|
+++++
   < axis 2 m
+---+---+---+
|0 1 2 3|4 5 6 7|8 9 10 11  |
+---+---+---+
|12 13 14 15|16 17 18 19|20 21 22 23|
+---+---+---+
   < axis 0 1 m
+++++
| 0  4  8| 1  5  9| 2  6 10| 3  7 11|
|12 16 20|13 17 21|14 18 22|15 19 23|
+++++
   < axis 0 2 m
+---+---+---+
| 0  1  2  3| 4  5  6  7| 8  9 10 11|
|12 13 14 15|16 17 18 19|20 21 22 23|
+---+---+---+
   < axis 1 0 m
+++-+-+
|0 12|1 13| 2 14| 3 15|
|4 16|5 17| 6 18| 7 19|
|8 20|9 21|10 22|11 23|
+++-+-+

In particular, you want

   < axis 0 i.5 2
+-+-+
|0 2 4 6 8|1 3 5 7 9|
+-+-+

Cheers,
Louis

> On 25 Aug 2017, at 05:54, bill lam  wrote:
> 
>   <"1 |: B
> +---+---+
> |0 2 4 6|1 3 5 7|
> +---+---+
> 
> if this is not what you wanted, then try
> 
>   <@,."1 |: B
> +-+-+
> |0|1|
> |2|3|
> |4|5|
> |6|7|
> +-+-+
> 
> 
> -- 
> regards,
> 
> GPG key 1024D/4434BAB3 2008-08-24
> gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
> gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3
> --
> 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] "diagonals"

2017-08-15 Thread Louis de Forcrand
Yes; I began writing the message but had to leave unexpectedly.
Let me explain what I want for a rank 2 array:

Given the index vector I of an element of the array and its shape, I want
all the elements in lines which are horizontal, vertical, or diagonal,
and which pass through I. In addition, elements on either side of
I must be separated.

I would like the indices of the ones in the right array, but grouped
(in the  # >:@i.@#)@[`(<"1@;@[)`]} [ $ 0:

   10 11 ugly 5 6
┌┬───┬───┬┬───┬───┬┬───┐
│5  7│5 5│6 6│6  7│6 5│4 6│4  7│4 5│
│5  8│5 4│7 6│7  8│7 4│3 6│3  8│3 4│
│5  9│5 3│8 6│8  9│8 3│2 6│2  9│2 3│
│5 10│5 2│9 6│9 10│9 2│1 6│1 10│1 2│
││5 1│   ││   │0 6││0 1│
││5 0│   ││   │   ││   │
└┴───┴───┴┴───┴───┴┴───┘

As you can see, the indices here are grouped in the order
of the output of dirs.

I hope this is a little more clear; it isn’t
very easy to explain :-/

Thanks!
Louis

> On 15 Aug 2017, at 14:43, Raul Miller <rauldmil...@gmail.com> wrote:
> 
> I am having problems understanding what you are asking for.
> 
> I'll try creating some examples which represent my understanding of
> what you seem to be asking for, and maybe that can help you tell me
> where I've gone off track:
> 
> "Given an array index vector i,"
> 
> For example:
>   i=: i.4 5
> 
> "how would you go about finding efficiently all indices (or elements
> at them) of an array for which the index in each dimension is either
> the same as that in i"
> 
> This sounds like all values from i, if I take it literally.
> 
> but, let's say I want column 2 and row 2
> 
>   ($ 2@#:"1 0 ]) i
> 0 0 1 0 0
> 0 0 1 0 0
> 1 1 1 1 1
> 0 0 1 0 0
> 
> The indices would be
> 
>   I.,($ 2@#:"1 0 ]) i
> 2 7 10 11 12 13 14 17
> 
> Except we've now got several conflicting uses of the word index: row
> index, column index, ravel index.
> 
> "or is offset by +/- n, where n is the same for all dimensions, and
> keep them grouped by “direction”?"
> 
> Offset from what? Let's say i represents a 10 by 10 matrix, and that
> want row or column 6, or an offset of 2 from either of those:
> 
>   ($ +./@((6+_2 0 2))@#:"1 0 ]) i.10 10
> 0 0 0 0 1 0 1 0 1 0
> 0 0 0 0 1 0 1 0 1 0
> 0 0 0 0 1 0 1 0 1 0
> 0 0 0 0 1 0 1 0 1 0
> 1 1 1 1 1 1 1 1 1 1
> 0 0 0 0 1 0 1 0 1 0
> 1 1 1 1 1 1 1 1 1 1
> 0 0 0 0 1 0 1 0 1 0
> 1 1 1 1 1 1 1 1 1 1
> 0 0 0 0 1 0 1 0 1 0
> 
> But I don't know which direction the diagonal elements would belong to.
> 
> (And then I hit your examples and realize that I have no idea how any
> of that relates to what I thought you were asking for.)
> 
> Anyways, maybe try again?
> 
> Thanks,
> 
> -- 
> Raul
> 
> 
> On Tue, Aug 15, 2017 at 2:45 PM, Louis de Forcrand <ol...@bluewin.ch> wrote:
>> Hi,
>> 
>> Given an array index vector i, how would you go about
>> finding efficiently all indices (or elements at them) of an
>> array for which the index in each dimension is either the
>> same as that in i, or is offset by +/- n, where n is the same
>> for all dimensions, and keep them grouped by “direction”?
>> 
>> I have a solution but it isn’t very pretty. I will use it to
>> illustrate though, as this is kind of hard to explain:
>> 
>> 
>> ugly=: 4 : '(}.dirs#x) <@}.@}:@(+^:(] -: x | ])^:a:)"1 y'
>> dirs=: (1|.i:1)&([: ,/ ,"0 1/)&(i.1 0)
>> demo=: ugly (#@> # >:@i.@#)@[`(<"1@;@[)`]} [ $ 0:
>> 
>>   6 7 ugly 3 4
>> ┌───┬───┬───┬───┬───┬───┬───┬───┐
>> │3 5│3 3│4 4│4 5│4 3│2 4│2 5│2 3│
>> │3 6│3 2│5 4│5 6│5 2│1 4│1 6│1 2│
>> │   │3 1│   │   │   │0 4│   │0 1│
>> │   │3 0│   │   │   │   │   │   │
>> └───┴───┴───┴───┴───┴───┴───┴───┘
>>   6 7 demo 3 4
>> 0 8 0 0 6 0 0
>> 0 0 8 0 6 0 7
>> 0 0 0 8 6 7 0
>> 2 2 2 2 0 1 1
>> 0 0 0 5 3 4 0
>> 0 0 5 0 3 0 4
>> 
>>   _13 ]\ 5 5 5 ugly 2 2 2
>> ┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐
>> │2 2 3│2 2 1│2 3 2│2 3 3│2 3 1│2 1 2│2 1 3│2 1 1│3 2 2│3 2 3│3 2 1│3 3 2│3 3 
>> 3│
>> │2 2 4│2 2 0│2 4 2│2 4 4│2 4 0│2 0 2│2 0 4│2 0 0│4 2 2│4 2 4│4 2 0│4 4 2│4 4 
>> 4│
>> ├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
>> │3 3 1│3 1 2│3 1 3│3 1 1│1 2 2│1 2 3│1 2 1│1 3 2│1 3 3│1 3 1│1 1 2│1 1 3│1 1 
>> 1│
>> │4 4 0│4 0 2│4 0 4│4 0 0│0 2 2│0 2 4│0 2 0│0 4 2│0 4 4│0 4 0│0 0 2│0 0 4│0 0 
>> 0│
>> └─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘
>>   <"2 ] 5 5 5 demo 2 2 2
>> ┌┬┬─┬───

[Jprogramming] "diagonals"

2017-08-15 Thread Louis de Forcrand
Hi,

Given an array index vector i, how would you go about
finding efficiently all indices (or elements at them) of an
array for which the index in each dimension is either the
same as that in i, or is offset by +/- n, where n is the same
for all dimensions, and keep them grouped by “direction”?

I have a solution but it isn’t very pretty. I will use it to
illustrate though, as this is kind of hard to explain:


ugly=: 4 : '(}.dirs#x) <@}.@}:@(+^:(] -: x | ])^:a:)"1 y'
dirs=: (1|.i:1)&([: ,/ ,"0 1/)&(i.1 0)
demo=: ugly (#@> # >:@i.@#)@[`(<"1@;@[)`]} [ $ 0:

   6 7 ugly 3 4
┌───┬───┬───┬───┬───┬───┬───┬───┐
│3 5│3 3│4 4│4 5│4 3│2 4│2 5│2 3│
│3 6│3 2│5 4│5 6│5 2│1 4│1 6│1 2│
│   │3 1│   │   │   │0 4│   │0 1│
│   │3 0│   │   │   │   │   │   │
└───┴───┴───┴───┴───┴───┴───┴───┘
   6 7 demo 3 4
0 8 0 0 6 0 0
0 0 8 0 6 0 7
0 0 0 8 6 7 0
2 2 2 2 0 1 1
0 0 0 5 3 4 0
0 0 5 0 3 0 4
   
   _13 ]\ 5 5 5 ugly 2 2 2
┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐
│2 2 3│2 2 1│2 3 2│2 3 3│2 3 1│2 1 2│2 1 3│2 1 1│3 2 2│3 2 3│3 2 1│3 3 2│3 3 3│
│2 2 4│2 2 0│2 4 2│2 4 4│2 4 0│2 0 2│2 0 4│2 0 0│4 2 2│4 2 4│4 2 0│4 4 2│4 4 4│
├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│3 3 1│3 1 2│3 1 3│3 1 1│1 2 2│1 2 3│1 2 1│1 3 2│1 3 3│1 3 1│1 1 2│1 1 3│1 1 1│
│4 4 0│4 0 2│4 0 4│4 0 0│0 2 2│0 2 4│0 2 0│0 4 2│0 4 4│0 4 0│0 0 2│0 0 4│0 0 0│
└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘
   <"2 ] 5 5 5 demo 2 2 2
┌┬┬─┬┬┐
│26 0 24 0 25│0  0  0  0 0│8 0 6 0 7│0  0  0  0 0│17 0 15 0 16│
│ 0 0  0 0  0│0 26 24 25 0│0 8 6 7 0│0 17 15 16 0│ 0 0  0 0  0│
│20 0 18 0 19│0 20 18 19 0│2 2 0 1 1│0 11  9 10 0│11 0  9 0 10│
│ 0 0  0 0  0│0 23 21 22 0│0 5 3 4 0│0 14 12 13 0│ 0 0  0 0  0│
│23 0 21 0 22│0  0  0  0 0│5 0 3 0 4│0  0  0  0 0│14 0 12 0 13│
└┴┴─┴┴┘


The different numbers in the arrays represent the different
“directions” I was referring to.

What I need is not necessarily the indices of these positions;
any way to separate them is good.

Louis

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

Re: [Jprogramming] Multidimensional Root Finding with Newton Solver

2017-08-10 Thread Louis de Forcrand
I find it interesting that N-R works for vectors and complex functions (and 
mixes of both). Just replace all those scalar functions by their vector 
equivalents:

vn=: 1 : '- n * u %. u D.1'

I added a scaling factor; it makes the convergence slower, but it fixes 
problems due to precision-loss.

It works reasonably well:

   f=: ^&0 1 - 1 2 ^~ {.
   f vn 0.1^:1e3 ] 0 0
1 1

Louis

> On 10 Aug 2017, at 13:07, Martin  wrote:
> 
> Hi there,
> 
> J looks very interesting. I have no previous experience with array
> languages and, being curious, started to experiment.  Now, I would
> like to solve a system of non-linear equations. I could only examples
> solving single equations like this one:
> 
>  N=: 1 : '- u % u d. 1'   NB. Adverb implementing Newton-Raphson iteration.
>  (_2 + *:) N^:_ ]1NB. Find root of “0 = _2+x^2”, starting guess of 
> “1”.
> 
> Is it also possible to solve a system of equation like the following
> one in a similar elegant manner?
> 
>  f1(x) = a*(1-x1)
>  f2(x) = b*(x2-x1^2)
> 
> Example from 
> https://www.gnu.org/software/gsl/doc/html/multiroots.html#examples
> 
> Thanks for any ideas!
> -Martin
> 
> --
> 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] Fractional parts

2017-08-09 Thread Louis de Forcrand
Why so? Did I miss a non-scalar verb somewhere?

Thanks,
Louis

> On 9 Aug 2017, at 14:47, Raul Miller <rauldmil...@gmail.com> wrote:
> 
> I think you have assumed that the user will use these with "0 or only
> on atomic numbers?
> 
> Thanks,
> 
> -- 
> Raul
> 
> 
>> On Wed, Aug 9, 2017 at 3:39 PM, Louis de Forcrand <ol...@bluewin.ch> wrote:
>> A few handy tests which are good to know:
>> 
>> N=: GI *. 1 0 e.~ * NB. naturals
>> Z=: GI *. R NB. integers
>> R=: = + NB. reals
>> C_R=: + = - NB. pure imaginaries (C-.R)
>> GI=: = <. NB. gaussian integers
>> 
>> These were made to accept any J number. They could be optimised if one knows 
>> that they are working only with real numbers, for example. In that case
>> 
>> 1 0 e.~ *
>> 
>> could be replaced by
>> 
>>> :&0
>> 
>> and the test for reals can be skipped in Z.
>> 
>> In addition, these work with the mathematical definitions of the different 
>> number sets, not with J's internal storage types.
>> 
>> Louis
>> 
>>> On 9 Aug 2017, at 11:42, Skip Cave <s...@caveconsulting.com> wrote:
>>> 
>>> Martin,
>>> 
>>> The original problem I was working on was a post on Quora (
>>> https://goo.gl/NrZde2). I use these Quora math questions to help sharpen my
>>> J skills. I try to see if I can "brute force" the solutions using J, while
>>> most other posters try to solve these things by algebraic manipulation.  My
>>> answer to that question is here: (https://goo.gl/FhdJAg). There are several
>>> Quora problems that I have posted J solutions for, mostly to show how
>>> simple a brute force solution can be when using an array language. You can
>>> find those posts by searching for my name ("Skip Cave") in Quora
>>> 
>>> In this problem all I really needed to do was to find all the results from
>>> the equation that were integers, so I used the 0=1||  scheme to find them.
>>> 
>>> Our discussion on the J forum got me thinking about finding both the
>>> fractional part and the integer part of numbers, and I thought the pair of
>>> verbs (fp, ip) would be a nice addition to the Phrases doc, which is
>>> defined as listing phrases "useful to beginners in learning the language,
>>> and of continuing use to practical programmers."
>>> 
>>> Also, when I obtained the fractional part, I wanted to keep the fact that
>>> the fractional part came from a negative number, hence the attempt to have
>>> negative fractional parts.
>>> 
>>> Skip
>>> 
>>> Skip Cave
>>> Cave Consulting LLC
>>> 
>>>> On Wed, Aug 9, 2017 at 9:35 AM, Martin Kreuzer <i...@airkreuzer.com> wrote:
>>>> 
>>>> From what I've gathered so far is, that people seem to not mind that much,
>>>> when extracting the fractional part from a (negative) float, they use
>>>> 
>>>>  (1&|) _8.11
>>>> 0.89
>>>> 
>>>> or
>>>> 
>>>>  (1

Re: [Jprogramming] Fractional parts

2017-08-09 Thread Louis de Forcrand
A few handy tests which are good to know:

N=: GI *. 1 0 e.~ * NB. naturals
Z=: GI *. R NB. integers
R=: = + NB. reals
C_R=: + = - NB. pure imaginaries (C-.R)
GI=: = <. NB. gaussian integers

These were made to accept any J number. They could be optimised if one knows 
that they are working only with real numbers, for example. In that case

1 0 e.~ *

could be replaced by

>:&0

and the test for reals can be skipped in Z.

In addition, these work with the mathematical definitions of the different 
number sets, not with J's internal storage types.

Louis

> On 9 Aug 2017, at 11:42, Skip Cave  wrote:
> 
> Martin,
> 
> The original problem I was working on was a post on Quora (
> https://goo.gl/NrZde2). I use these Quora math questions to help sharpen my
> J skills. I try to see if I can "brute force" the solutions using J, while
> most other posters try to solve these things by algebraic manipulation.  My
> answer to that question is here: (https://goo.gl/FhdJAg). There are several
> Quora problems that I have posted J solutions for, mostly to show how
> simple a brute force solution can be when using an array language. You can
> find those posts by searching for my name ("Skip Cave") in Quora
> 
> In this problem all I really needed to do was to find all the results from
> the equation that were integers, so I used the 0=1||  scheme to find them.
> 
> Our discussion on the J forum got me thinking about finding both the
> fractional part and the integer part of numbers, and I thought the pair of
> verbs (fp, ip) would be a nice addition to the Phrases doc, which is
> defined as listing phrases "useful to beginners in learning the language,
> and of continuing use to practical programmers."
> 
> Also, when I obtained the fractional part, I wanted to keep the fact that
> the fractional part came from a negative number, hence the attempt to have
> negative fractional parts.
> 
> Skip
> 
> Skip Cave
> Cave Consulting LLC
> 
>> On Wed, Aug 9, 2017 at 9:35 AM, Martin Kreuzer  wrote:
>> 
>> From what I've gathered so far is, that people seem to not mind that much,
>> when extracting the fractional part from a (negative) float, they use
>> 
>>   (1&|) _8.11
>> 0.89
>> 
>> or
>> 
>>   

Re: [Jprogramming] Boxed verbs as alternate gerunds

2017-08-07 Thread Louis de Forcrand
@.] should be used, not @.0 :

   v
|value error: v
   v123
|value error: v123
   v`''@.]
v@.]
   v123`''@.]
v123@.]

I still like the @.] test.

Louis

> On 07 Aug 2017, at 19:26, Jose Mario Quintana  
> wrote:
> 
> No joke was intended, undefined names are regarded as verbs in the context
> of adverbs and conjunctions.  Why? Because it allows for writing verbs in a
> top-down fashion if one so desires.  (Bill, I know you know most of this,
> if not all; but I am putting some context for the potential benefit members
> of the forum who might not.)
> 
> An error thrown by  @.0  does not necessarily mean that the argument is not
> a gerund or that it is a nonsensical gerund; I would assume we both agree
> that even if  v  is undefined  v`''  is still a gerund.  Either way, both
> Roger's and Pascal's tests agree on this,
> 
>   v
> |value error: v
> 
>   gerundYN=: 0 -. @ e. 3 : ('y (5!:0)';'1')"0 :: 0:
>   isgerund =: 0:`(0 -. @ e. 3 : ('y (5!:0)';'1')"0)@.(0 < L.) :: 0:
> 
>   gerundYN v`''
> 1
>   isgerund v`''
> 1
> 
> Yet,
> 
>   v`'' @.0
> |value error: v
> 
> However,
> 
>   v`'' @.0 /
> v/
> 
> So, is the literal noun  'v'  a gerund or not?  A hint follows after
> several blank lines,
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>   v
> |value error: v
> 
>   v123
> |value error: v123
> 
> 
>   gerundYN 'v'
> 1
>   gerundYN 'v123'
> 0
> 
>   isgerund 'v'
> 0
>   isgerund 'v123'
> 0
> 
> What is happening?
> 
> 
> 
> On Sun, Aug 6, 2017 at 8:34 PM, Bill  wrote:
> 
>> I am not sure if I understand your question. If you asked something
>> undefined is a gerund or not. I checked by executing v@.0 '' and the J
>> interpreter said value error. Sounds like an empty array joke to me.
>> 
>> Sent from my iPhone
>> 
>> On 7 Aug, 2017, at 5:23 AM, Jose Mario Quintana <
>> jose.mario.quint...@gmail.com> wrote:
>> 
>>> I am not hoping to change people's minds; nevertheless, I would like to
>>> explain, to some degree, my rationale regarding my current notion of
>> what a
>>> gerund is.
>>> 
>>> The Dictionary is famous (or infamous according to some?) for its
>>> terseness.  It is not really surprising to me that different people have
>>> different understandings even regarding the very important concept of
>>> gerund.  Personally, I use Dictionary as the primary source but
>>> complemented by other official documents, forum information (particularly
>>> opinions and statements from certain people), third party sources, and
>>> first and foremost the "real thing", the interpreter(s) which it is,
>> after
>>> all, where programs and utilities for writing programs, some of which are
>>> very important to me, run.
>>> 
>>> Let me start with the (current version of the) Dictionary, this is how I
>>> perceive it, given its terseness, the statement  "Verbs act upon nouns to
>>> produce noun results..." is generally interpreted as "Verbs act upon
>> nouns
>>> [and only nouns] to produce noun [and only noun] results..." and other
>>> supporting evidence clearly confirm that is the intention.
>>> 
>>> Therefore, assuming that the Dictionary is consistent, then the statement
>>> related to the to the entry Tie (Gerund),
>>> "
>>> More generally, tie produces gerunds as follows: u`v is au,av , where au
>>> and av are the (boxed noun) atomic representations (5!:1) of u and v .
>>> Moreover, m`n is m,n and m`v is m,av and u`n is au,n . See Bernecky and
>> Hui
>>> [12]. Gerunds may also be produced directly by boxing.
>>> "
>>> could be intrepreted as "... tie produces gerunds [and only gerunds]..."
>>> (I know that, actually , tie can produce also nouns which are not
>> gerunds;
>>> just as a verbs can produce words which are not a nouns.)
>>> 
>>> Incidentally, I do not regard foreings as part of the core language
>> either
>>> but they are in the Dictionary, and they are used to illustrate points,
>>> even when discussing a primitive (see (5!:1) above).
>>> 
>>> Furthermore, "Moreover, m`n is m,n and m`v is m,av and u`n is au,n"
>>> suggests that both, the left and right arguments do not have to be verbs.
>>> Indeed, the gerund (produced by)  +`-`* is equivalent to (+`-)`* and
>> (+`-)
>>> is not a verb it is a gerund (i.e, a noun).
>>> 
>>> The last sentence "Gerunds may also be produced directly by boxing" is
>>> quite important in the context of last part of that page,
>>> "
>>> The atomic representation of a noun (used so as to distinguish a noun
>> such
>>> as '+' from the verb +) is given by the following function:
>>>  (ar=: [: < (,'0')"_ ; ]) '+'
>>> +-+
>>> |+-+-+|
>>> ||0|+||
>>> |+-+-+|
>>> +-+
>>> 
>>>  *`(ar '+')
>>> +-+-+
>>> |*|+-+-+|
>>> | ||0|+||
>>> | |+-+-+|
>>> +-+-+
>>> "
>>> 
>>> There, clearly, the right argument (ar '+') of  `  is the atomic
>>> representation of a noun ('+') not a verb.  That is, *`(ar '+') is a
>> gerund
>>> and, for example, G=. (*:`ar 0 1 2) is a gerund well.
>>> 

Re: [Jprogramming] "_1/

2017-08-07 Thread Louis de Forcrand
I see. So negative ranks are sort of placeholders, and are replaced by
positive (effective) ranks internally during evaluation?
Because it could just announce its rank to be negative, and not actually
calculate the effective rank until it is really needed (a lazier effective rank
evaluation if you will):

  x u”_1/ y   <->   x u”_1”_1 _ y   NB. evaluate effective rank here
<->   x u”_1”((0>.(#$x)-1) , _) y   NB. and here
<->   x 4 : ‘x u”((0>.(#$x)-1),(0>.(#$y)-1)) y'”((0>.(#$x)-1) , _) y

instead of

  x u”_1/ y NB. just here
<->   x 4 : ‘x u”((0>.(#$x)-1),(0>.(#$y)-1)) y’/ y

What I mean is that I would’ve made v=: u“r with r<0 report rank r, and if an
operator needs to know the rank of v, then just feed it r and let it deal with
calculating the effective rank.

Of course their are probably implementation limitations which I do not know of.

Thanks for your explanation!

Louis

> On 07 Aug 2017, at 18:29, Raul Miller <rauldmil...@gmail.com> wrote:
> 
> The rank of +"_1 is infinite because the derived verb has to see the
> full ranks of its arguments to figure out what rank to use for the
> inner verb.
> 
> In other words, -"_1 in -"_1 i.3 3 has an effective rank of 1, but in
> -"_ i.3 it has an effective rank of 0.
> 
> Since it can't know what rank to use until after it sees the nouns,
> its announced rank has to be infinite.
> 
> Thanks,
> 
> -- 
> Raul
> 
> 
> On Mon, Aug 7, 2017 at 4:40 PM, Louis de Forcrand <ol...@bluewin.ch> wrote:
>>   +"0/~ i.3
>> 0 1 2
>> 1 2 3
>> 2 3 4
>>   +"_1/~ i.3
>> 0 2 4
>>   +"0 b.0
>> 0 0 0
>>   +"_1 b.0
>> _ _ _
>> 
>> I understand that this is dictionary compliant:
>> 
>> "In general, each cell of x is applied to the entire of y . Thus x u/ y is 
>> equivalent to x u"(lu,_) y where lu is the left rank of u ."
>> 
>>   +"_1 b.0
>> _ _ _
>> 
>> So u"_1/ -: u"_ _ . Wouldn’t it be better though if u"_1/ -: u"_1 _ ,
>> or if (u”_1 b.0) -: _1 _1 _1 (or any other negative rank)?
>> I ran into this while trying to use ,"_1/ , which I can replace by >@{@,&< ,
>> but I still find this strange.
>> 
>> Louis
>> 
>> --
>> 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] "_1/

2017-08-07 Thread Louis de Forcrand
The same observations go for all operators which depend on their argument’s
rank, such as @, &, or &. :

  <@(,"_1)~ i.3
┌───┐
│0 0│
│1 1│
│2 2│
└───┘

Louis

> On 07 Aug 2017, at 16:55, Louis de Forcrand <ol...@bluewin.ch> wrote:
> 
> Yes I guess it could be replaced by
> 
> u”_1”_1 _
> 
> I would guess it is the intended behavior as b.0 reports
> infinite rank, but that is what I find strange.
> 
> Louis
> 
>> On 07 Aug 2017, at 16:47, Xiao-Yong Jin <jinxiaoy...@gmail.com> wrote:
>> 
>> I remembered I had problem with this and ended up specifying both left and 
>> right rank.
>> 
>>  JVERSION
>> Engine: j806/j64avx/darwin
>> Beta-4: commercial/2017-06-27T12:55:06
>> Library: 8.06.03
>> Platform: Darwin 64
>> Installer: J806 install
>> InstallPath: /applications/j64-806
>> Contact: www.jsoftware.com
>>  +"_1 _ b.0
>> _ _ _
>>  +"_1 _/~i.3
>> 0 1 2
>> 1 2 3
>> 2 3 4
>> 
>> I'm not sure if it is the intended behavior.
>> 
>> 
>>> On Aug 7, 2017, at 3:40 PM, Louis de Forcrand <ol...@bluewin.ch> wrote:
>>> 
>>> +"0/~ i.3
>>> 0 1 2
>>> 1 2 3
>>> 2 3 4
>>> +"_1/~ i.3
>>> 0 2 4
>>> +"0 b.0
>>> 0 0 0
>>> +"_1 b.0
>>> _ _ _
>>> 
>>> I understand that this is dictionary compliant:
>>> 
>>> "In general, each cell of x is applied to the entire of y . Thus x u/ y is 
>>> equivalent to x u"(lu,_) y where lu is the left rank of u ."
>>> 
>>> +"_1 b.0
>>> _ _ _
>>> 
>>> So u"_1/ -: u"_ _ . Wouldn’t it be better though if u"_1/ -: u"_1 _ ,
>>> or if (u”_1 b.0) -: _1 _1 _1 (or any other negative rank)?
>>> I ran into this while trying to use ,"_1/ , which I can replace by >@{@,&< ,
>>> but I still find this strange.
>>> 
>>> Louis
>>> 
>>> --
>>> 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] "_1/

2017-08-07 Thread Louis de Forcrand
Yes I guess it could be replaced by

u”_1”_1 _

I would guess it is the intended behavior as b.0 reports
infinite rank, but that is what I find strange.

Louis

> On 07 Aug 2017, at 16:47, Xiao-Yong Jin <jinxiaoy...@gmail.com> wrote:
> 
> I remembered I had problem with this and ended up specifying both left and 
> right rank.
> 
>   JVERSION
> Engine: j806/j64avx/darwin
> Beta-4: commercial/2017-06-27T12:55:06
> Library: 8.06.03
> Platform: Darwin 64
> Installer: J806 install
> InstallPath: /applications/j64-806
> Contact: www.jsoftware.com
>   +"_1 _ b.0
> _ _ _
>   +"_1 _/~i.3
> 0 1 2
> 1 2 3
> 2 3 4
> 
> I'm not sure if it is the intended behavior.
> 
> 
>> On Aug 7, 2017, at 3:40 PM, Louis de Forcrand <ol...@bluewin.ch> wrote:
>> 
>>  +"0/~ i.3
>> 0 1 2
>> 1 2 3
>> 2 3 4
>>  +"_1/~ i.3
>> 0 2 4
>>  +"0 b.0
>> 0 0 0
>>  +"_1 b.0
>> _ _ _
>> 
>> I understand that this is dictionary compliant:
>> 
>> "In general, each cell of x is applied to the entire of y . Thus x u/ y is 
>> equivalent to x u"(lu,_) y where lu is the left rank of u ."
>> 
>>  +"_1 b.0
>> _ _ _
>> 
>> So u"_1/ -: u"_ _ . Wouldn’t it be better though if u"_1/ -: u"_1 _ ,
>> or if (u”_1 b.0) -: _1 _1 _1 (or any other negative rank)?
>> I ran into this while trying to use ,"_1/ , which I can replace by >@{@,&< ,
>> but I still find this strange.
>> 
>> Louis
>> 
>> --
>> 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] "_1/

2017-08-07 Thread Louis de Forcrand
   +"0/~ i.3
0 1 2
1 2 3
2 3 4
   +"_1/~ i.3
0 2 4
   +"0 b.0
0 0 0
   +"_1 b.0
_ _ _

I understand that this is dictionary compliant:

"In general, each cell of x is applied to the entire of y . Thus x u/ y is 
equivalent to x u"(lu,_) y where lu is the left rank of u ."

   +"_1 b.0
_ _ _

So u"_1/ -: u"_ _ . Wouldn’t it be better though if u"_1/ -: u"_1 _ ,
or if (u”_1 b.0) -: _1 _1 _1 (or any other negative rank)?
I ran into this while trying to use ,"_1/ , which I can replace by >@{@,&< ,
but I still find this strange.

Louis

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

Re: [Jprogramming] Jx version 1.0 release

2017-08-06 Thread Louis de Forcrand
temp=: 2 : 0
[: (v^:_1@(4 : 'y`:6  >x')"0 m $~ $) <@v
)

atop=: 2 : 'm temp (v :. ])'

under=: 2 : 0
m temp v : ([: (v^:_1@(4 : 'y`:6&>/x')"0 m $~ $) ,&<)
)

compose=: 2 : 'm under (v :. ])'

rank=:  2 : 'm atop (]"n)'

‘rank’ is “ as Henry suggested for gerunds, and I propose extending
this behaviour to @, &, and &. as described above as well.

In particular,
v0`v1`…`vi under ><->   v0@(0{::]) ; v1@(1{::]) ; … ; vi(i{::]) extended 
cyclically:

   M=: i.3 4 5
   (,:  -`j. under >) ;/M
┌───┬┬───┐
│ 0  1  2  3  4 │20 21 22 23 24  │40 41 42 43 44 │
│ 5  6  7  8  9 │25 26 27 28 29  │45 46 47 48 49 │
│10 11 12 13 14 │30 31 32 33 34  │50 51 52 53 54 │
│15 16 17 18 19 │35 36 37 38 39  │55 56 57 58 59 │
├───┼┼───┤
│  0  _1  _2  _3  _4│0j20 0j21 0j22 0j23 0j24│_40 _41 _42 _43 _44│
│ _5  _6  _7  _8  _9│0j25 0j26 0j27 0j28 0j29│_45 _46 _47 _48 _49│
│_10 _11 _12 _13 _14│0j30 0j31 0j32 0j33 0j34│_50 _51 _52 _53 _54│
│_15 _16 _17 _18 _19│0j35 0j36 0j37 0j38 0j39│_55 _56 _57 _58 _59│
└───┴┴───┘
   
Louis

> On 06 Aug 2017, at 19:31, Jose Mario Quintana <jose.mario.quint...@gmail.com> 
> wrote:
> 
> "
> On my wish list would be something similar for the “each" adverb. While 
> writing
> tacit code I very often find myself  writing
> 
>u@(0{::]) ; v@:(1{::]) etc.
> "
> 
> Louis, I find the points you raised very interesting and they might
> influence Jx v1.1.
> 
> Meanwhile, if you really very often would like to produce,
> 
> v0@(0{::]) ; v1@:(1{::]) ; v2@:(1{::]) ...
> 
> given v0, v1, v2, ...  You could write an (explicit?) adverb, Each for
> instance, such that, for example,
> 
>   v0`v1`v2`v3 Edge
> v0@:(0&({::)) ; v1@:(1&({::)) ; v2@:(2&({::)) ; v3@:(3&({::))
> 
> I prefer, of course,
> 
>   [: v0 v1 v2 v3 Each
> v0@:(0&({::)) ; v1@:(1&({::)) ; v2@:(2&({::)) ; v3@:(3&({::))
> 
> It was very easy to write  Each  tacitly in Jx particularly because I had
> seen similar patterns before.  If you need often the cyclical feature then
> I would expect it to be a matter of adding a minor complication.
> 
> Do you really need the cyclical feature?
> 
> You might also like to read the oblique (/.) entry in the Dictionary and
> other sources; it could help.
> 
> 
> On Fri, Aug 4, 2017 at 1:03 AM, Louis de Forcrand <ol...@bluewin.ch> wrote:
> 
>> I quite like this idea. It’s unfortunate that m”n was previously defined
>> differently,
>> but as you say conflicts would probably be nonexistent, and I’ve often
>> wanted
>> to apply one verb to the first element of an array, another to the second,
>> etc.
>> 
>> On my wish list would be something similar for the “each" adverb. While
>> writing tacit code I very often find myself writing
>> 
>>u@(0{::]) ; v@:(1{::]) etc.
>> 
>> and the readability / terseness of
>> 
>>u`v&.>
>> 
>> would be valuable IMO (albeit perhaps not easy to incorporate correctly
>> into the language).
>> 
>> 
>> I was just about to send this email, but then I thought of this:
>> 
>> For adverbs / conjunctions like @, &, or &. which depend on the rank of
>> their right argument (unlike @:, &:, &.:), a gerund left argument could be
>> extended cyclically over each item of the right argument’s result. Not only
>> would that check one item off my wish list, but if gerund m in m”n proves
>> to
>> be unacceptable, it could be replaced by
>> 
>>m@(]”n)
>> 
>> This would create no incompatibilities apart from code relying on errors
>> thrown by those operators.
>> 
>> Louis
>> 
>>> On 03 Aug 2017, at 01:51, Henry Rich <henryhr...@gmail.com> wrote:
>>> 
>>> The argument for gerund"n is this:
>>> 
>>> All partitioning modifiers (/. / ;.n etc,) support cyclic gerunds.  The
>>> anomalous case is " which is the most basic partitioning modifier of all.
>>> It should have been defined to support cyclic gerunds.
>>> 
>>> The proposal is to put it right without breaking any code.  m"n when m
>>> resembles a gerund and n is not _ will be very rare, perhaps nonexistent,
>>> in actual code.  For new code, m"_"n will work for any n.
>>> 
>>> Henry Rich
>>> 
>>> On Thu, Aug 3, 2017 at 3:07 AM, 'Pascal 

Re: [Jprogramming] Fractional parts

2017-08-06 Thread Louis de Forcrand
ip would be best implemented as

   ip=: * * <.@|

as it would return an integer result.

Louis

> On 06 Aug 2017, at 12:17, Skip Cave  wrote:
> 
> All, Thanks for the help.
> 
> Here's some real numbers from a problem I'm working on:
> Calculate some values from this equation:
>v=:2%(3r19-%1 2 3 245 246 247 248)
> v
>_2.375 _5.84615 _11.4 13.0028 13.0014 13 12.9986
> Raul's first suggestion:
>1|v
> 0.625 0.153846 0.6 0.0027933 0.00139082 0 0.998621
> More precision, but signs are wrong on the negative numbers.
> 
> Nolaig's suggestion:
> (- <.) v
> 0.625 0.153846 0.6 0.0027933 0.00139082 1.77636e_15 0.998621
> Negative signs are still wrong, and the 6th entry should be zero. Looks
> like a compare tolerance problem.
> 
> Pascal's solution:
> 
>   1 (| |)v
> 
> 0.375 0.846154 0.4 0.0027933 0.00139082 0 0.998621
> Still has the negatives wrong.
> 
> Martin's solution:
> fp=.**1||
> 
>   fp v
> 
> _0.375 _0.846154 _0.4 0.0027933 0.00139082 0 0.998621
> Negatives are right, zeroes are right. This fractional part verb needs to
> be in the documentation as part of the numbers chapter.
> 
> Also the integer part verb: ip=.]-**1||should be included in the
> numbers section as well.
>   ip v
> 
> _2 _5 _11 13 13 13 12
> 
> Skip
> 
> Skip Cave
> Cave Consulting LLC
> 
> On Sun, Aug 6, 2017 at 6:42 AM, Raul Miller  wrote:
> 
>> 1&| does work, actually.
>> 
>> And, if you want an offset of -1 on that result when the original
>> value was negative, you can use (1&| - 0&>)
>> 
>> Thanks,
>> 
>> --
>> Raul
>> 
>> On Sun, Aug 6, 2017 at 3:19 AM, Martin Kreuzer 
>> wrote:
>>> In easy steps (and for further reference) ...
>>> 
>>> From these test data (two floats, two integers, different signs), to get
>> the
>>> fractional parts
>>> 
>>>   v=. 2.25 _8.11 16 _3
>>> 
>>> simply taking the Residue (when dividing by 1) doesn't work (error at
>>> negative float position)
>>> 
>>>   1|v
>>> 0.25 0.89 0 0
>>> 
>>> So first get Magnitude
>>> 
>>>   | v
>>> 2.25 8.11 16 3
>>> 
>>> then take Residue
>>> 
>>>   1 | (| v)
>>> 0.25 0.11 0 0
>>> 
>>> then get the sign right (see Raul's remark below)
>>> 
>>>   (*v) * (1 | | v)
>>> 0.25 _0.11 0 0
>>> 
>>> and put it as verb (fp), written as a fork
>>> 
>>>   fp=. * * 1||
>>>   fp v
>>> 0.25 _0.11 0 0
>>> 
>>> -M
>>> 
>>> 
>>> At 2017-08-06 02:14, you wrote:
>>> 
 Eh... but that's wrong.  You can't add any integer to 0.542857 to get
 _0.542857.
 
 If you want signed fractions, you'd need something like (*@] * (| |))
 
 Thanks,
 
 --
 Raul
 
 
 On Sat, Aug 5, 2017 at 10:01 PM, 'Pascal Jasmin' via Programming
  wrote:
> combining other answers we get the cute:
 
> 1 (| |)  _0.542857 _1.1875 1.96552 2.92308 4.13043 5.7 7.82353 10.8571
> 15.5455 23.75
 
 
 
 
> 
> From: Bill 
> To: "programm...@jsoftware.com" 
> Sent: Saturday, August 5, 2017 8:30 PM
> Subject: Re: [Jprogramming] Fractional parts
 
 
 
> this also depends on what do you expect for negative numbers.
 
> Sent from my iPhone
 
> On 6 Aug, 2017, at 7:35 AM, Skip Cave 
>> wrote:
 
>> Oops! i meant:
>> 
>> How does one find the fractional parts of a vector of floating point
>> numbers?
>> 
>> 0.542857 1.1875 1.96552 2.92308 4.13043 5.7 7.82353 10.8571 15.5455
>> 23.75
>> 41.8 114 247
>> 
>> i want:
>> 0.542857 0.1875 0.96552 0.92308 0.13043 0.7 0.82353 0.8571 5.5455
>> 0.75
>> 0.8
>> 0 0
>> 
>> (Last two integers have zero fractional part.)
>> 
>> 
>> Skip Cave
>> Cave Consulting LLC
>> 
>> On Sat, Aug 5, 2017 at 6:30 PM, Skip Cave 
>> wrote:
>> 
>>> How does one find the fractional parts of a vector of floating point
>>> numbers?
>>> 
>>> 0.542857 1.1875 1.96552 2.92308 4.13043 5.7 7.82353 10.8571 15.5455
>>> 23.75
>>> 41.8 114 247
>>> 
>>> i want:
>>> 0.542857 0.1875 0.96552 0.92308 0.13043 0.7 0.82353 0.8571 5.5455
>> 0.75
>>> 0.8
>>> 114 247
>>> 
>>> 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 

Re: [Jprogramming] Jx version 1.0 release

2017-08-03 Thread Louis de Forcrand
I quite like this idea. It’s unfortunate that m”n was previously defined 
differently,
but as you say conflicts would probably be nonexistent, and I’ve often wanted
to apply one verb to the first element of an array, another to the second, etc.

On my wish list would be something similar for the “each" adverb. While
writing tacit code I very often find myself writing

u@(0{::]) ; v@:(1{::]) etc.

and the readability / terseness of 

u`v&.>

would be valuable IMO (albeit perhaps not easy to incorporate correctly
into the language).


I was just about to send this email, but then I thought of this:

For adverbs / conjunctions like @, &, or &. which depend on the rank of
their right argument (unlike @:, &:, &.:), a gerund left argument could be
extended cyclically over each item of the right argument’s result. Not only
would that check one item off my wish list, but if gerund m in m”n proves to
be unacceptable, it could be replaced by

m@(]”n)

This would create no incompatibilities apart from code relying on errors
thrown by those operators.

Louis

> On 03 Aug 2017, at 01:51, Henry Rich  wrote:
> 
> The argument for gerund"n is this:
> 
> All partitioning modifiers (/. / ;.n etc,) support cyclic gerunds.  The
> anomalous case is " which is the most basic partitioning modifier of all.
> It should have been defined to support cyclic gerunds.
> 
> The proposal is to put it right without breaking any code.  m"n when m
> resembles a gerund and n is not _ will be very rare, perhaps nonexistent,
> in actual code.  For new code, m"_"n will work for any n.
> 
> Henry Rich
> 
> On Thu, Aug 3, 2017 at 3:07 AM, 'Pascal Jasmin' via Programming <
> programm...@jsoftware.com> wrote:
> 
>> the best solution I've seen,
>> 
>> 
>> isgerund =: 0:`(0 -.@e. 3 : ('y (5!:0)';'1')"0)@.(0 < L.) :: 0:
>> 
>> 
>> tests that each "box" can be passed to 5!:0 without error.
>> 
>> 
>> From: Bill 
>> To: "programm...@jsoftware.com" 
>> Sent: Wednesday, August 2, 2017 9:01 PM
>> Subject: Re: [Jprogramming] Jx version 1.0 release
>> 
>> 
>> 
>> J interpreter must know when a noun is a gerund, so is it possible to add
>> a new primitive to test for gerund? Or is there already J script to test
>> for gerund?
>> 
>> Sent from my iPhone
>> 
>> On 3 Aug, 2017, at 3:36 AM, Henry Rich  wrote:
>> 
>>> I expect to make some more improvements to dyad u"n, and eventually to
>>> rewrite the monad to match the dyad.  My availability to work on this
>> will
>>> be intermittent for a while.  The 8.06 code as is works, and fixes a
>>> long-standing bug reported by Martin Neitzel.
>>> 
>>> I have suggested using m"n, where n is not _, to implement a cyclic
>> gerund
>>> m.  If m doesn't look like a gerund, it would be treated as a simple
>> noun.
>>> While this is not strictly compatible, I think it very unlikely that it
>>> would break any existing code.  I think m"n was wrongly defined and that
>>> this is the correct definition.  My opinion is not universally shared so
>> I
>>> haven't acted on it.
>>> 
>>> Henry Rich
>>> 
>>> On Wed, Aug 2, 2017 at 5:03 PM, Thomas Costigliola 
>> wrote:
>>> 
 You can try removing the conditional statement enclosing that line, but
 for now I would say the patch is broken under Clang. Since the rank code
 was completely rewritten in J805 and J806 and ":: is based on the J804
>> rank
 with some unfinished updates Henry was working on, the real solution is
>> to
 rewrite ":: based on the new rank code. But that should wait until the
>> code
 is stable. Does anyone anticipate more changes?
 
 On a more philosophical note, ":: implements gerund left arguments that
 apply to the items cyclically. The reason for adding a new primitive and
 not extending ": is because it breaks using ": to define constant
 functions. If someone has any ideas to make them play nicely together
>> then
 they can be merged into a single primitive. The issue is that there is
>> no
 distinction between a noun and gerund.
 
 Regards,
 -Thomas
 
 
 On 08/02/2017 11:52 AM, bill lam wrote:
 
> Yes, I use Clang and have -Werror -Wextra in CFLAGS.
> Sometimes vs2013 is much less tolerant.
> 
> Ср, 02 авг 2017, Thomas Costigliola написал(а):
> 
>> That looks like Henry's code taken from cr.c at some older version. It
>> compiles fine for me in GCC and Visual Studio 2013. It is in the
>> implementation of "::, which seems to be working in my tests, so that
>> code
>> never gets hit. Are you using Clang? It's much less tolerant of code
>> like
>> that.
>> 
>> Regards,
>> -Thomas
>> 
>> On 08/02/2017 11:21 AM, bill lam wrote:
>> 
>>> When I tried to compile, but this line in best.c failed.
>>> 
>>>   *((I*)0)=0;  // scaf
>>> 
>>> 

Re: [Jprogramming] Boxed verbs as alternate gerunds

2017-08-03 Thread Louis de Forcrand
Just wondering why

isgerund=: 3 : 0 :: 0
y@.]
1
)

isn't an acceptable test for “gerundality”?

I also kind of agree with Bill, in the sense that J doesn’t seem to have been
designed from the ground up (or halfway up for that matter) to facilitate
programmatically building code / functions with gerunds. Gerunds seem
to have been designed more for @. conditionals and sending multiple verbs
to adverbs like }., and using foreigns to manipulate them just seems kind
of “hacky” to me.

This of course doesn’t mean that writing such code is impossible;
just that doing so leads to highly incomprehensible code (at least to the 
casual J
programmer; sorry, but I haven’t the faintest idea how most of your wicked tacit
wizardry works Pepe!) There are other languages such as Lisp whose lists and
highly regular syntax are designed specifically around that, or Haskell where
currying means that any function taking more than one argument is a higher-
order function returning another function; and J and APL’s syntaxes have other
fortes, notably terseness and remarkable idiomatic qualities.

I feel that a big part of this comes from being able to write code that does a 
lot
in a small space, with few parentheses, and with relatively simple parsing 
rules;
and without the current noun-verb-adverb hierarchy, one of those three qualities
would be lessened.

Adding first-class verbs would kind of blur that hierarchy, and while they are 
interesting
to have in unofficial interpreters I believe that the official interpreter 
should stay
lean, efficient, relatively consistent, but especially practical to use for the 
average
J programmer. So the question is wether the “generality” or “completeness” added
by first-class verbs is worth the losses in other areas.

All that to say that I agree with Bill that gerunds as they are now have been 
designed
to be created with the tie conjunction, and while they are not perfect, they are
an acceptable compromise.

Louis

> On 03 Aug 2017, at 19:31, Bill  wrote:
> 
> From my understanding, the reference shows the atomic representation of 
> gerund. It does not advocate this a way to construct a gerund. moreover it is 
> "foreign" conjunction.
> 
> numbers can be converted from strings using foreign conjunction but it 
> doesn't mean J encourages writing numbers using this method.
> 
> IMO foreign conjunction is not a part of J core.
> 
> 
> Sent from my iPhone
> 
> On 4 Aug, 2017, at 5:33 AM, Jose Mario Quintana 
>  wrote:
> 
>> "
>> In J dictionary, only tie conjunction
>> on verbs was mentioned to produce a gerund.
>> "
>> 
>> I am afraid you might not be the only one who has reached such conclusion.
>> Nevertheless, in my opinion, it is a misconception that a gerund can only
>> be a list (of atomic representations) of verbs.  Why?  See [0] in the
>> context of [1].
>> 
>> [0] Atomic
>>   http://www.jsoftware.com/help/dictionary/dx005.htm#1
>> 
>> [1] [Jprogramming] how to test for a gerund  Roger Hui
>>   http://www.jsoftware.com/pipermail/programming/2010-April/019178.html
>> 
>> Mind you  gerundYN  is not bulletproof.
>> 
>> 
>> On Thu, Aug 3, 2017 at 5:46 AM, bill lam  wrote:
>> 
>>> I am thinking of the opposite. In J dictionary, only tie conjunction
>>> on verbs was mentioned to produce a gerund. Boxed verbs had not been
>>> mentioned. Atomic representation of boxed verbs looks like that of
>>> gerund and therefore can work as gerund. IMO this is a backdoor
>>> provided by J implementation.
>>> 
>>> Metadata could be attached to "real" gerunds that have ancestors which
>>> were  results of verb`verb. All other nouns without this DNA would be
>>> regarded as non-gerund.
>>> 
>>> Just my 2 cents.
>>> 
>>> On Thu, Aug 3, 2017 at 3:57 PM, Marshall Lochbaum 
>>> wrote:
 Can I just point out that it's not too late to add some (documented) way
 to box verbs/adverbs/conjunctions? These could be treated as gerunds by
 everything that currently uses gerunds, and the interpreter can just
 throw an error if anything attempts to actually unbox them. They are
 much harder to confuse than the current gerunds, and will have far
 better performance.
 
 This sounds like a radical divergence from the way J works now, but I
 don't think it is in practice. Programmers would use some new
 conjunction to replace (`), and provided they don't inspect the
 structure of gerunds nothing else changes. I suppose there would need to
 be a way to check what class of object a box contains, because unboxing
 to check the type is not allowed. Gerunds would remain useful for
 programmers who want to inspect functions or build them from scratch,
 but would otherwise become obselete.
 
 Marshall
>> --
>> For information about J forums see 

Re: [Jprogramming] Everyone giving dollars to random others

2017-07-19 Thread Louis de Forcrand
NB. tacit
run=: upd rec
upd=: [ ((({~ 0{::]) + 1{::])`(0{::])`[} - 2{::]) ~.@] ; ] (+//. ; ]) 1 <: [

NB. explicit
RUN=: UPD rec
UPD=: 4 : 0
 b -~ x u}~ (x {~ u=. ~.y) + y +//. b=. x >: 1
)
   
rec=: ((] + ] >: i.@[) (?@$ <:))@#


Slower on short vectors, faster on larger ones (j805):

   1e2 ts 'tick^:1e4#~20'
0.0408952 3840
   1e2 ts 'run^:1e4#~20'
0.0802917 4864
   1e2 ts 'RUN^:1e4#~20'
0.0636084 7040
   
   10 ts 'tick^:1e4#~100'
0.243663 23552
   10 ts 'run^:1e4#~100'
0.12502 11904
   10 ts 'RUN^:1e4#~100'
0.104644 14848

Probably because of =/.

Louis

> On 19 Jul 2017, at 18:37, Rob Hodgkinson  wrote:
> 
> Thanks Mike it formats and reads perfectly… nice job, Rob
> 
>> On 20 Jul 2017, at 8:02 am, 'Mike Day' via Programming 
>>  wrote:
>> 
>> This took me much longer than a lunch-break,  partly because we
>> were away in France,  and I was experimenting with J701 on my
>> iPad when Liz would let me.
>> 
>> I came up with a number of variants, of which the following is best.
>> It's slower and uses more space than Raul's for small problem-sizes,
>> but is perhaps better for larger problems,  eg n > 100 or so.
>> 
>> NB. a Boolean verb for whether a player donates,  which,
>> NB. of course, depends on whether he has any money:
>> 
>>  donation =: 1 & <.
>> 
>> NB. This verb lists the indexes of the random donee (? player donated to)
>> NB. for each player,  whether of not that player CAN donate.
>> NB. It assumes that its single argument is i.n where n is the number
>> NB. of players,  which is why its name ends in i (!):
>> 
>>  idoneei=:(#|(+?&.<:@#~@#))
>> 
>> NB.  The idea is to concatenate
>> NB.   (the old state minus donation) and (donation), namely
>> NB.   ((-,  ])donation)
>> NB.  and sum them as ordered with this left-hand key:
>> NB.   (i.n) concatenated with (idonee),  namely
>> NB.   (, idoneei)@(i.@#)
>> 
>> NB.  Here it is,  with a fix, f.
>> 
>> new =: ((,idoneei)@(i.@#) +//. ((-,  ])donation )) f.
>> 
>> NB. time & space:
>>  ts =: 6!:2 , 7!:2@]
>> 
>> NB. where my version is ok:
>>  ts'orig ^:5000 #~200'   NB. Xiao-Yong Jin's original suggestion
>> 5.72563 22912
>>  ts'tick ^:5000 #~200'   NB. Raul's revised version
>> 1.57339 77824
>>  ts'new ^:5000 #~200'NB. The best I could manage
>> 0.922963 20992
>> 
>> NB. and where it isn't so good:
>>  ts'orig ^:5000 #~10'  NB. Xiao-Yong Jin
>> 0.341718 6272
>>  ts'tick ^:5000 #~10'  NB. Raul M
>> 0.0445439 3840
>>  ts'new  ^:5000 #~10'  NB. Mike D
>> 0.0676198 4864
>> 
>> Sorry for this late posting,  but it wasn't convenient to
>> write up and send until home and with laptop to hand.
>> 
>> Thanks,
>> Mike
>> 
>> NB. prepared in notepad, copied to Thunderbird, and trying
>> to force fixed width - hope it displays reasonably.
>> 
>> 
>> 
>> On 11/07/2017 19:33, Devon McCormick wrote:
>>> Reading the page referenced, I see where I was confused.  The problem
>>> starts out as 100 people each with $100, but then solves a variant of it
>>> for 45 people with $45 each, possibly so the animation is legible.  It's
>>> not clear why they even mention the first set of numbers.
>>> 
>>> On Mon, Jul 10, 2017 at 8:37 PM, Raul Miller  wrote:
>>> 
 Oops, I did not think about that "reflexive giving" wart.
 
 Here's a fix for my version:
 
   tick=: (0 >. <:) + i.@# +/@:(=/)~ I.@:* (] + <:) +/@:* ?@# <:@#
   require 'stats'
   stddev"1 tick^:(i.10) 45#45
 0 0.977008 1.18705 1.73205 2.01133 2.15322 2.46798 2.86832 2.97719 3.1334
   tick^:1]20#20
 3 20 1 15 10 38 6 8 23 24 11 90 33 67 5 13 7 20 1 5
 
 Thanks,
 
 --
 Raul
 
 On Mon, Jul 10, 2017 at 7:50 PM, 'Pascal Jasmin' via Programming
  wrote:
> 
> The number of $ available each round is the number of people with >&0.
 The number of potential recipients is the population.  This simplification
 though means its possible for someone to pay himself.
> 
> A correction to your version,
> 
> /:~@(-&1`]@.(=&0)"0 (#/.~@] + ~.@]{[)`(~.@])`[} >&0 # (?@#~@#@]`]`[} ]
 I.@:= i.@#)@?@#~@#)^:21000 #~10
> That assumption would increase the likelihood of eventual
 "superconcntration"  but that doesn't seem to happen.
> As soon as some have 0, the rest have a "negative return" expectation
 each turn.
> 
> 
> 
> 
> From: Xiao-Yong Jin 
> 
> To: "programm...@jsoftware.com" 
> 
> Sent: Monday, July 10, 2017 3:43 PM
> 
> Subject: [Jprogramming] Everyone giving dollars to random others
> 
> 
> 
> 
> I thought this is a good lunch break exercise.
> 
> 
> 
> http://www.decisionsciencenews.com/2017/06/19/counterintuitive-
 problem-everyone-room-keeps-giving-dollars-random-others-
 youll-never-guess-happens-next/
> 
> 
> Quote: 

Re: [Jprogramming] Request for comments: multiple assignment

2017-07-19 Thread Louis de Forcrand
Sorry; I did digress from multiple assignment.

Louis

> On 19 Jul 2017, at 09:31, Raul Miller <rauldmil...@gmail.com> wrote:
> 
> I believe that this discussion was about something different.
> 
> Thanks,
> 
> -- 
> Raul
> 
>> On Wed, Jul 19, 2017 at 3:45 AM, Louis de Forcrand <ol...@bluewin.ch> wrote:
>> K supports first-class verbs; one can make an array of verbs, index one out, 
>> and apply it to something using the same syntax as for normal function 
>> application.
>> This is feasable in J, but only by using a special "apply" verb (perhaps 
>> gurus know another way?).
>> Not trying to go full tacit,
>> 
>> apply=: 4 : 0
>> x`:6 y
>> )
>> 
>> for example.
>> 
>> While this is more clunky, we must remember that:
>> 1) K function application looks like this:
>> user_defined_function[arg1;arg2;arg3;etc.]
>> 2) K does not support tacit programming like J does. More specifically it 
>> does not support trains. J would not be able to do this if there were no 
>> noun / function / operator hierarchy:
>> f ; g
>> would that be a list of f and g or the train as we know it? The hierarchy 
>> allows paren-free parsing rules and infix as well:
>> f @ g instead of @[f;g]
>> 
>> All in all, clunky first-class verbs are a price I am (and most Jers I 
>> assume are) willing to pay in order to get trains. Like you say, a little 
>> inconsistency can be very practical.
>> 
>> Louis
>> 
>>> On 18 Jul 2017, at 20:23, Raul Miller <rauldmil...@gmail.com> wrote:
>>> 
>>> Specifically, what you call "first class verbs" are, according to the
>>> dictionary, supposed to be trains.
>>> 
>>> That this glitch seems useful says something, I think, about the value
>>> of inconsistency.
>>> 
>>> Thanks,
>>> 
>>> --
>>> Raul
>>> 
>>> 
>>> On Tue, Jul 18, 2017 at 6:52 PM, Jose Mario Quintana
>>> <jose.mario.quint...@gmail.com> wrote:
>>>> Louis, call me Pepe (which is the nickname for Jose); that is how friends
>>>> call me.
>>>> 
>>>> Even if first-class verbs are not in compliance with the J Dictionary,
>>>> official interpreters allow them but one has to wrestle with the
>>>> interpreters.  Using first-class verbs, one can operate on verbs [0] in a
>>>> similar way one can operate on nouns [1].  Jx extensions make their use
>>>> more pleasant and goes beyond first-class verbs; Jx also facilitates to
>>>> pass verbs, adverbs and conjunctions to verbs, adverbs and conjunctions to
>>>> produce verbs, adverbs and conjunctions.
>>>> 
>>>> [0] Tacit (unorthodox) version
>>>>   https://rosettacode.org/wiki/First-class_functions#Tacit_.
>>>> 28unorthodox.29_version
>>>> [1] Tacit (unorthodox) version
>>>>   https://rosettacode.org/wiki/First-class_functions/Use_
>>>> numbers_analogously#Tacit_.28unorthodox.29_version
>>>> 
>>>> 
>>>> On Tue, Jul 18, 2017 at 12:36 AM, Louis de Forcrand <ol...@bluewin.ch>
>>>> wrote:
>>>> 
>>>>> I’d guess is that by “unstable” he meant “currently being modified".
>>>>> In any case, thanks for the link Jose (what should I call you? Pepe?).
>>>>> If there was one thing I could add to J it would be better support for
>>>>> first-class verbs (arrays of verbs, passing verbs as arguments), if only
>>>>> for the beauty of it, but I know this is neither easy nor practical in
>>>>> reality.
>>>>> However trying out your new version of Jx is; I’ll take a look at it if 
>>>>> you
>>>>> release it. In the meantime I’ll look into your J701 version when I have
>>>>> the time!
>>>>> 
>>>>> Louis
>>>>> 
>>>>>> On 17 Jul 2017, at 20:21, HenryRich <henryhr...@gmail.com> wrote:
>>>>>> 
>>>>>> Unstable?  If you have a bug in J8.06, please post it at
>>>>>> 
>>>>>> http://code.jsoftware.com/wiki/System/Interpreter/Bugs
>>>>>> 
>>>>>> I don't see any bugs that are new in 8.06, and plenty that are fixed
>>>>> from previous versions.
>>>>>> 
>>>>>> Henry Rich
>>>>>> 
>>>>>>> On 7/17/2017 7:06 PM, Jose Mario Quintana wrote:
>>>>>>> Louis

Re: [Jprogramming] Request for comments: multiple assignment

2017-07-19 Thread Louis de Forcrand
K supports first-class verbs; one can make an array of verbs, index one out, 
and apply it to something using the same syntax as for normal function 
application.
This is feasable in J, but only by using a special "apply" verb (perhaps gurus 
know another way?).
Not trying to go full tacit,

apply=: 4 : 0
 x`:6 y
)

for example.

While this is more clunky, we must remember that:
1) K function application looks like this:
user_defined_function[arg1;arg2;arg3;etc.]
2) K does not support tacit programming like J does. More specifically it does 
not support trains. J would not be able to do this if there were no noun / 
function / operator hierarchy:
f ; g
would that be a list of f and g or the train as we know it? The hierarchy 
allows paren-free parsing rules and infix as well:
f @ g instead of @[f;g]

All in all, clunky first-class verbs are a price I am (and most Jers I assume 
are) willing to pay in order to get trains. Like you say, a little 
inconsistency can be very practical.

Louis

> On 18 Jul 2017, at 20:23, Raul Miller <rauldmil...@gmail.com> wrote:
> 
> Specifically, what you call "first class verbs" are, according to the
> dictionary, supposed to be trains.
> 
> That this glitch seems useful says something, I think, about the value
> of inconsistency.
> 
> Thanks,
> 
> -- 
> Raul
> 
> 
> On Tue, Jul 18, 2017 at 6:52 PM, Jose Mario Quintana
> <jose.mario.quint...@gmail.com> wrote:
>> Louis, call me Pepe (which is the nickname for Jose); that is how friends
>> call me.
>> 
>> Even if first-class verbs are not in compliance with the J Dictionary,
>> official interpreters allow them but one has to wrestle with the
>> interpreters.  Using first-class verbs, one can operate on verbs [0] in a
>> similar way one can operate on nouns [1].  Jx extensions make their use
>> more pleasant and goes beyond first-class verbs; Jx also facilitates to
>> pass verbs, adverbs and conjunctions to verbs, adverbs and conjunctions to
>> produce verbs, adverbs and conjunctions.
>> 
>> [0] Tacit (unorthodox) version
>>https://rosettacode.org/wiki/First-class_functions#Tacit_.
>> 28unorthodox.29_version
>> [1] Tacit (unorthodox) version
>>https://rosettacode.org/wiki/First-class_functions/Use_
>> numbers_analogously#Tacit_.28unorthodox.29_version
>> 
>> 
>> On Tue, Jul 18, 2017 at 12:36 AM, Louis de Forcrand <ol...@bluewin.ch>
>> wrote:
>> 
>>> I’d guess is that by “unstable” he meant “currently being modified".
>>> In any case, thanks for the link Jose (what should I call you? Pepe?).
>>> If there was one thing I could add to J it would be better support for
>>> first-class verbs (arrays of verbs, passing verbs as arguments), if only
>>> for the beauty of it, but I know this is neither easy nor practical in
>>> reality.
>>> However trying out your new version of Jx is; I’ll take a look at it if you
>>> release it. In the meantime I’ll look into your J701 version when I have
>>> the time!
>>> 
>>> Louis
>>> 
>>>> On 17 Jul 2017, at 20:21, HenryRich <henryhr...@gmail.com> wrote:
>>>> 
>>>> Unstable?  If you have a bug in J8.06, please post it at
>>>> 
>>>> http://code.jsoftware.com/wiki/System/Interpreter/Bugs
>>>> 
>>>> I don't see any bugs that are new in 8.06, and plenty that are fixed
>>> from previous versions.
>>>> 
>>>> Henry Rich
>>>> 
>>>>> On 7/17/2017 7:06 PM, Jose Mario Quintana wrote:
>>>>> Louis, a Jx interpreter implements extensions to the language.  It
>>> supports
>>>>> tacit programming full-heartedly and embraces first-class verbs.  There
>>> are
>>>>> publicly available patches for Jx extensions, as well as, a pre-built 32
>>>>> bit Windows dll and Pre-built 32 and 64 bit Linux libs at
>>>>> 
>>>>> http://www.2bestsystems.com/foundation/j/jx0/index.html
>>>>> 
>>>>> but it is an early version of Jx based on the J701 source.  Jx has
>>> evolved
>>>>> (e.g., the primitives =.. and =:: were added afterwards) and J's core
>>>>> engine has evolved rapidly as well; it has been very difficult to catch
>>> up.
>>>>> ("Be careful what you wish for.")  :)
>>>>> 
>>>>> The current unreleased version of Jx is based on the unstable official
>>> J806
>>>>> beta source and there are some relatively minor Jx glitches.  We were
>>>>> planning to wait for the of

Re: [Jprogramming] Request for comments: multiple assignment

2017-07-17 Thread Louis de Forcrand
I’d guess is that by “unstable” he meant “currently being modified".
In any case, thanks for the link Jose (what should I call you? Pepe?).
If there was one thing I could add to J it would be better support for
first-class verbs (arrays of verbs, passing verbs as arguments), if only
for the beauty of it, but I know this is neither easy nor practical in reality.
However trying out your new version of Jx is; I’ll take a look at it if you
release it. In the meantime I’ll look into your J701 version when I have
the time!

Louis

> On 17 Jul 2017, at 20:21, HenryRich <henryhr...@gmail.com> wrote:
> 
> Unstable?  If you have a bug in J8.06, please post it at
> 
> http://code.jsoftware.com/wiki/System/Interpreter/Bugs
> 
> I don't see any bugs that are new in 8.06, and plenty that are fixed from 
> previous versions.
> 
> Henry Rich
> 
> On 7/17/2017 7:06 PM, Jose Mario Quintana wrote:
>> Louis, a Jx interpreter implements extensions to the language.  It supports
>> tacit programming full-heartedly and embraces first-class verbs.  There are
>> publicly available patches for Jx extensions, as well as, a pre-built 32
>> bit Windows dll and Pre-built 32 and 64 bit Linux libs at
>> 
>> http://www.2bestsystems.com/foundation/j/jx0/index.html
>> 
>> but it is an early version of Jx based on the J701 source.  Jx has evolved
>> (e.g., the primitives =.. and =:: were added afterwards) and J's core
>> engine has evolved rapidly as well; it has been very difficult to catch up.
>>  ("Be careful what you wish for.")  :)
>> 
>> The current unreleased version of Jx is based on the unstable official J806
>> beta source and there are some relatively minor Jx glitches.  We were
>> planning to wait for the official J806 to become stable and resolve the Jx
>> glitches but I might decide instead to release a current version, as is,
>> soon.
>> 
>> 
>> On Mon, Jul 17, 2017 at 7:40 AM, Louis de Forcrand <ol...@bluewin.ch> wrote:
>> 
>>> A lot has been said on these forums about Jx and Unbox.
>>> They are unofficial J interpreters (with extensions to the language), are
>>> they not?
>>> Are they publicly available? I couldn't find anything about them on Google
>>> except older messages in the forum archives, but then again unfortunately
>>> this language's name makes it sometimes hard to look up on the web.
>>> 
>>> Thanks!
>>> Louis
>>> 
>>>> On 16 Jul 2017, at 15:37, Raul Miller <rauldmil...@gmail.com> wrote:
>>>> 
>>>> Sure, and the biggest problem here is the use of globals for arguments.
>>>> 
>>>> The verbs themselves can be pure, but all we're really doing is
>>>> rearranging the deck chairs.
>>>> 
>>>> Thanks,
>>>> 
>>>> --
>>>> Raul
>>>> 
>>>> 
>>>> On Sun, Jul 16, 2017 at 3:33 PM, Jose Mario Quintana
>>>> <jose.mario.quint...@gmail.com> wrote:
>>>>> At least we agree, I think, on one thing " in explicit programming
>>>>> [typically] names refer to arguments while in tacit programming they do
>>>>> not."  Thus, is not just a matter of tacit aesthetics, there are some
>>>>> consequences which might be difficult to evade:
>>>>> 
>>>>>   ('`u v') =: +/`*:
>>>>>   u@:v f.
>>>>> +/@:*:
>>>>> 
>>>>>   ('`u v') =:: +/`*:  NB. Jx
>>>>> ┌───┬──┐
>>>>> │┌─┬───┐│*:│
>>>>> ││/│┌─┐││  │
>>>>> ││ ││+│││  │
>>>>> ││ │└─┘││  │
>>>>> │└─┴───┘│  │
>>>>> └───┴──┘
>>>>>   u@:v f.
>>>>> +/@:*:
>>>>> 
>>>>>   ('`u v') is +/`*: NB.
>>>>> |domain error
>>>>> |   (m)=:y
>>>>>   is
>>>>> 1 : '(m)=:y'
>>>>> 
>>>>> So, assuming I understood the intended use of your adverb  is, I am
>>> afraid
>>>>> your adverb cannot be used without typical limitations.
>>>>> 
>>>>> 
>>>>> 
>>> 
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
> 
> 
> ---
> This email has been checked for viruses by AVG.
> http://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] largest rectangle problem

2017-06-25 Thread Louis de Forcrand
Here is Mike’s version with 2<./\ inserted (and >./i* replaced by i*>./ since
i is positive):

cs1=: 3 : 0
 m=. >./y
 for_i. }.>:i.n=. #y do.
  m=. m>.q=. i*>./y=. 2<./\y
  if. (m*i)>:n*q do. break. end.
 end.
 m
)

   1e3 ts'cs1 qq'
0.00107603 29440
   qqq=: 1e4?.1e6
   ts'cs1 qqq'
0.045429 398080
   ts'cs qqq'
0.180366 397440

Real fast!
Louis

> On 25 Jun 2017, at 14:47, Louis de Forcrand <ol...@bluewin.ch> wrote:
> 
> Let V be a vector of real numbers, and V[i] its ith component.
> Then
> 
> min( V[i] … V[j+1] ) = min( min( V[i] … V[j] ), min( V[i+1] … V[j+1] ) ).
> 
> This version is based on that:
> 
>   ms=: #\ >./ . * [: >./@> # 2&(<./\&.>)&< ]
>   1e3 ts 'ms qq'
> 0.00491435 5.74234e6
> 
> Incorporating this in Mike's explicit version with an early stopping condition
> could lead to even faster runtimes!
> 
> Cheers,
> Louis
> 
>> On 25 Jun 2017, at 11:00, 'Mike Day' via Programming 
>> <programm...@jsoftware.com> wrote:
>> 
>> There must be something about breakfast.
>> A loopy stopping condition has just presented itself.  Others might see a 
>> tacitisation:
>> 
>> cs =: 3 : 0
>> 
>> m =. >./y
>> 
>> for_i. }.>:i.n =. #y do.
>> 
>> m =. m >. q =. >./ i ([ * <./\) y
>> 
>> if. (m * i) >: n * q do. break. end.
>> 
>> end.
>> 
>> m
>> 
>> )
>> 
>> q holds the maximum area at "width" i . No subsequent area
>> 
>> can be greater than q*n%i where n is the maximum width, so
>> 
>> stop if that is no greater than the current maximum, m.
>> 
>> It's twice as fast and uses slightly less space than c, the loopy verb
>> 
>> without an early stopping condition:
>> 
>> ts'c qq'
>> 
>> 0.014258 21632
>> 
>> ts'cs qq'
>> 
>> 0.0044897 21504
>> 
>> ts'C qq' NB. Raul's best tacit version - so far...
>> 
>> 0.00803071 289920
>> 
>> Now for lunch,
>> 
>> Mike
>> 
>> 
>> On 24/06/2017 20:09, Raul Miller wrote:
>>> True, except that if you did not have the inner >./ the "0 1 would not help.
>>> 
>>> 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

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

Re: [Jprogramming] largest rectangle problem

2017-06-25 Thread Louis de Forcrand
Let V be a vector of real numbers, and V[i] its ith component.
Then

min( V[i] … V[j+1] ) = min( min( V[i] … V[j] ), min( V[i+1] … V[j+1] ) ).

This version is based on that:

   ms=: #\ >./ . * [: >./@> # 2&(<./\&.>)&< ]
   1e3 ts 'ms qq'
0.00491435 5.74234e6

Incorporating this in Mike's explicit version with an early stopping condition
could lead to even faster runtimes!

Cheers,
Louis

> On 25 Jun 2017, at 11:00, 'Mike Day' via Programming 
>  wrote:
> 
> There must be something about breakfast.
> A loopy stopping condition has just presented itself.  Others might see a 
> tacitisation:
> 
> cs =: 3 : 0
> 
> m =. >./y
> 
> for_i. }.>:i.n =. #y do.
> 
> m =. m >. q =. >./ i ([ * <./\) y
> 
> if. (m * i) >: n * q do. break. end.
> 
> end.
> 
> m
> 
> )
> 
> q holds the maximum area at "width" i . No subsequent area
> 
> can be greater than q*n%i where n is the maximum width, so
> 
> stop if that is no greater than the current maximum, m.
> 
> It's twice as fast and uses slightly less space than c, the loopy verb
> 
> without an early stopping condition:
> 
> ts'c qq'
> 
> 0.014258 21632
> 
> ts'cs qq'
> 
> 0.0044897 21504
> 
> ts'C qq' NB. Raul's best tacit version - so far...
> 
> 0.00803071 289920
> 
> Now for lunch,
> 
> Mike
> 
> 
> On 24/06/2017 20:09, Raul Miller wrote:
>> True, except that if you did not have the inner >./ the "0 1 would not help.
>> 
>> 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] Complex residue

2017-06-23 Thread Louis de Forcrand
Thanks for the quick answers (and quick bug-fixing for that matter).

Louis

> On 23 Jun 2017, at 14:25, Henry Rich  wrote:
> 
> After reflection it seems clear that this is a bug in the implementation, so 
> I have fixed it for the next release, to match the Dictionary.
> 
> Henry Rich
> 
>> On 6/22/2017 9:32 PM, Henry Rich wrote:
>> I admit that the definition as it is implemented is less pretty than the one 
>> in Ye Dic.  It would be easy to change the code to match the Dictionary 
>> definition - I just don't know if that would break existing code.  Is that 
>> something we could thrash out here?
>> 
>> Does anyone use complex residue?  Would they care if we changed the code to 
>> match the Dictionary definition?
>> 
>> Henry Rich
>> 
>>> On 6/22/2017 6:49 PM, Raul Miller wrote:
>>> Yeah... over time, I've probably argued at least three sides of this 
>>> issue...
>>> 
>> 
>> 
>> ---
>> This email has been checked for viruses by AVG.
>> http://www.avg.com
>> 
>> --
>> For information about J forums see http://www.jsoftware.com/forums.htm
> 
> --
> For information about J forums see http://www.jsoftware.com/forums.htm

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

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-03 Thread Louis de Forcrand
How about
   1 0 1 0 1 0 (#~ ((-: & 0 1 0)"1 @: ({~ & z)))~ z
?
You can then "simplify":

First the hook (and {~)
([ #~ -:&0 1 0"1@:(z&{)@])~
([ #~ -:&0 1 0"1@:(z&{)@])~

Then ~ can be "distributed" over the resulting fork:
[~ #~ -:&0 1 0"1@:(z&{)@(]~)
] #~ -:&0 1 0"1@:(z&{)@[

You can keep going;
From bonding to forks:
] #~ (] -: 0 1 0"_)"1@:(z { ])@[
Composition and -: commutativity:
] #~ (0 1 0 -: ])"1@:(z { ]@[)
Because 1=#$0 1 0:
] #~ (0 1 0 -:"1 ])@:(z { [)
Trains:
] #~ (0 1 0 -:"1 ]@:(z { [))
] #~ 0 1 0 -:"1 ]@:(z { ])
] #~ 0 1 0 -:"1 z { [

Can't get it any simpler.

Cheers,
Louis

> On 4 Jun 2017, at 03:45, Michael Rice  wrote:
> 
>   z (#~ ((-: & 0 1 0)"1 @: ({~ & z))) 1 0 1 0 1 0

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

Re: [Jprogramming] J for iPad

2017-05-26 Thread Louis de Forcrand
Hi,

Is this applicable to all devices running iOS?
Thank you very much for the warning in any case.

Louis

> On 26 May 2017, at 11:43, Kip Murray  wrote:
> 
> My iPad Air now has iOS version 10.3.2 so I can no longer use J on my iPad.
> --Kip Murray
> 
> -- 
> Sent from Gmail Mobile
> --
> 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] Difference between jqt and JHS

2017-04-15 Thread Louis de Forcrand
Hi Linda,

If you go to
http://www.jsoftware.com/mailman/listinfo
and choose your forum, you can then enter your email and subscription password 
in order to change subscription options. One of them is wether or not to 
recieve your own messages.

Cheers,
Louis

> On 15 Apr 2017, at 21:38, Linda A Alvord  wrote:
> 
> Thanks for your answer, Bill.
> 
>  For the last week, I know people have answered my emails, but I have not 
> been getting the original.  Is there something that I might have done to 
> prevent them being returned to Outlook?
> 
> Linda
> 
> -Original Message-
> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
> Of bill lam
> Sent: Saturday, April 15, 2017 9:17 PM
> To: Programming forum
> Subject: Re: [Jprogramming] Difference between jqt and JHS
> 
> jhs should run none of wd related stuff. Hypothetically, a wd emulator for 
> jhs could be written, but it doesn't fit into jhs design. If wd is wanted, 
> one should run jqt instead.
> 
>> On 16 Apr, 2017 9:05 am, "Linda A Alvord"  wrote:
>> 
>> I took an example from one of Cliff's lab.  It works in jqt,  but wd 
>> is not available in JHS so it will not work there.
>> 
>> 
>> 
>> load '~addons/graphics/fvj4/dwin.ijs'
>> 
>> _1 _1 1 1 dwin 'Object window'
>> 
>> 0 0 100 100 dwin '200 random quadralaterals'
>> 
>> (?200 3$256) dpoly ?200 4 2$100
>> 
>> 
>> 
>> Linda
>> 
>> --
>> 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] matching & cancelling transactions

2017-04-13 Thread Louis de Forcrand
Hi Bo,
This is cool.

As for the way you suggest using it here, isn't it equivalent to (without the 
first six rows of your data):

(~.@[ ,. +//.)/@|:
?

Louis

> On 12 Apr 2017, at 21:57, 'Bo Jacoby' via Programming 
>  wrote:
> 
> Hi Joe!
> My favorite datastructure is ORDINAL FRACTIONS - the algebra of data 
> 
> |  
> |   
> |   
> |   ||
> 
>   |
> 
>  |
> |  
> ||  
> ORDINAL FRACTIONS - the algebra of data
> This paper was submitted to the 10th World Computer Congress, IFIP 1986 
> conference, but rejected by the referee  |   |
> 
>  |
> 
>  |
> 
> 
> Your data are coded like this
> 10 Joe
> 20 Bob
> 30 Jane
> 01 blue
> 02 red
> 03 purple
> 11 1
> 11 -1
> 11 1
> 22 1
> 22 1
> 22 3
> 22 -1
> 22 -1
> 33 5
> 33 -2
> 33 2
> (Written with double CRs because the mail program has a history of deleting 
> my CRs).
> Summation gives the result
> 10 Joe
> 20 Bob
> 30 Jane
> 01 blue
> 02 red
> 03 purple
> 11 1
> 22 3
> 
> 33 5
> I have not done the summation in J, but I'd like to do it.
> Perhaps this helps you.
> Bo.
> 
> 
> 
>Den 0:04 torsdag den 13. april 2017 skrev chris burke 
> :
> 
> 
> Incidentally, for production code, I suggest starting by removing any sales
> not matched in returns and vice versa, so that the matching algorithm is
> applied only to potential matches.
> 
>> On Wed, Apr 12, 2017 at 2:53 PM, chris burke  wrote:
>> 
>> Great.
>> 
>> In case you need more complicated handling of the "gray area"
>> transactions, I believe they would be relatively few in number, so most of
>> the time you could do the matching efficiently, then check for any keys
>> with returns preceding sales. For those, setting aside the first such
>> return and repeating should clear them quickly.
>> 
>> Timing should be well under 1 second for a million records.
>> 
>>> On Wed, Apr 12, 2017 at 1:57 PM, Joe Bogner  wrote:
>>> 
>>> Just for completeness, I added a line that incorporates the sequence check
>>> into the cancel logic. Works great
>>> 
>>> NB. hui progressive index
>>> NB. http://code.jsoftware.com/wiki/Essays/Progressive_Index-Of
>>> oc=: i.~ (] - {) /:@/:
>>> pi=: #@[ ({. i.&(,.oc) }.) [ i. ,
>>> 
>>> NB. argument is 3-col table of seq,key,qty
>>> NB. result is the unmatched transactions
>>> matchtrans=: 3 : 0
>>> msk=. 0<{:"1 y
>>> sales=. msk#y
>>> returns=. (-.msk)#y
>>> ndx=. (}."1 sales) pi | }."1 returns
>>> cancels=. ndx<#sales
>>> NB. ensure cancel is after sale
>>> cancels =. cancels *. (({."1 (<<(cancels)#ndx){sales) < ({."1
>>> (cancels#returns)))
>>> ((<<>> )
>>> 
>>> 
 On Wed, Apr 12, 2017 at 4:14 PM, Joe Bogner  wrote:
 
 Chris, this looks promising. Thanks for sharing. It's nearly instant on
>>> a
 million rows.
 
 Which row had a return before a transaction? seq 10 was an example of a
 partial return. The hypothetical customer returned 2 out of the 5
>>> purchased
 prior. I added that example since technically per the original spec it
 wouldn't be cancelled out in this pass.  It's a gray area so I may be
>>> able
 to use this approach, especially since I don't see how to incorporate
>>> the
 time element into the progressive index.
 
 Thanks again
 
 
 On Wed, Apr 12, 2017 at 3:52 PM, chris burke 
>>> wrote:
 
> This might be done by comparing matrices of sales and returns. The
> function
> below seems to be close to what you want. It doesn't exactly match your
> example, but your example has cases where returns are made before the
> transactions. Was this intentional?
> 
> The code should run faster than a looping solution.
> 
> Code:
> 
> NB. hui progressive index
> NB. http://code.jsoftware.com/wiki/Essays/Progressive_Index-Of
> oc=: i.~ (] - {) /:@/:
> pi=: #@[ ({. i.&(,.oc) }.) [ i. ,
> 
> NB. argument is 3-col table of seq,key,qty
> NB. result is the unmatched transactions
> matchtrans=: 3 : 0
> msk=. 0<{:"1 y
> sales=. msk#y
> returns=. (-.msk)#y
> ndx=. (}."1 sales) pi | }."1 returns
> cancels=. ndx<#sales
> ((<< )
> 
> Example:
> 
> dat=: ".;._2 (0 : 0)
> 1 1 1
> 2 1 _1
> 3 1 1
> 4 2 1
> 5 2 1
> 6 2 3
> 7 2 _1
> 8 2 _1
> 9 3 5
> 10 3 _2
> 11 3 2
> )
> 
> matchtrans dat
> 3 1 1
> 6 2 3
> 9 3 5
> 
> 
> On Wed, Apr 12, 2017 at 9:35 AM, Joe Bogner 
>>> wrote:
> 
>> I have a problem I'm trying to solve in different languages. I have a
>> solution in SQL and also in kdb which largely resembles the SQL
> solution.
>> I'm curious what a J solution would look like. More specifically, I'm
>> interested in picking the brains of others here to see if 

Re: [Jprogramming] matching & cancelling transactions

2017-04-13 Thread Louis de Forcrand
Here is a more space-efficient version. Effectively the same, except it works 
on different customers seperately. Note that ac and ac2 work on records where 
orders from different clients may appear in any order, while ac1 expects all 
orders from a single client to be grouped together:

ac1=: [: ; <@c/./@|:
ac2=: (/:@/:@(i.~)@[ { [: ; <@c/.)/@|:
c=: +/"1@s@p1   NB. s is the same
p1=: * * |:@=@:|


Not quite as fast, but still about twice as fast as applycredits, and they use 
much less space than ac.

Cheers,
Louis

> On 13 Apr 2017, at 07:12, Joe Bogner <joebog...@gmail.com> wrote:
> 
> Thanks Bo, Louis
> 
> Louis -  I will study your solution. J reports 'out of memory' on a million
> rows. It is 6x faster than the larger data set too. Good solution!
> 
>> On Thu, Apr 13, 2017 at 3:31 AM, Louis de Forcrand <ol...@bluewin.ch> wrote:
>> 
>> Try this. On my phone, it runs almost 6 times faster than your version on
>> your small example data, but uses more space (maybe sparse matrices would
>> be faster?), with:
>>   1e3 timespacex 'applycredits'
>> 0.000630182 4608
>> vs
>>   1e3 timespacex 'ac t'
>> 0.000131279 6400
>> 
>> Of course this extra space could be a big slowdown on larger data. At
>> least it's more J-ish:
>> 
>> ac=: +/"1@s@p
>> s=: [: u&.(,&0) d&.(0&,)
>> u=: [: +/\.^:_1 (0<.+)/\.   NB. u -: d&.(-@|.)
>> d=: [: +/\ ^:_1 (0>.+)/\.&.|.
>> p=: |:@=@:| * [: * {:"1
>> 
>> t=: (}."1 /: {."1) ".;._2 data
>> ac t
>> 
>> It works on a minimal form of your data where records are sorted by their
>> index, and results are in the form:
>> 0: ok
>> 1: cancelled
>> _1: credit
>> 
>> Louis
>> 
>>> On 12 Apr 2017, at 21:57, 'Bo Jacoby' via Programming <
>> programm...@jsoftware.com> wrote:
>>> 
>>> Hi Joe!
>>> My favorite datastructure is ORDINAL FRACTIONS - the algebra of data
>>> 
>>> |
>>> |
>>> |
>>> |   ||
>>> 
>>>  |
>>> 
>>> |
>>> |
>>> ||
>>> ORDINAL FRACTIONS - the algebra of data
>>> This paper was submitted to the 10th World Computer Congress, IFIP 1986
>> conference, but rejected by the referee  |   |
>>> 
>>> |
>>> 
>>> |
>>> 
>>> 
>>> Your data are coded like this
>>> 10 Joe
>>> 20 Bob
>>> 30 Jane
>>> 01 blue
>>> 02 red
>>> 03 purple
>>> 11 1
>>> 11 -1
>>> 11 1
>>> 22 1
>>> 22 1
>>> 22 3
>>> 22 -1
>>> 22 -1
>>> 33 5
>>> 33 -2
>>> 33 2
>>> (Written with double CRs because the mail program has a history of
>> deleting my CRs).
>>> Summation gives the result
>>> 10 Joe
>>> 20 Bob
>>> 30 Jane
>>> 01 blue
>>> 02 red
>>> 03 purple
>>> 11 1
>>> 22 3
>>> 
>>> 33 5
>>> I have not done the summation in J, but I'd like to do it.
>>> Perhaps this helps you.
>>> Bo.
>>> 
>>> 
>>> 
>>>   Den 0:04 torsdag den 13. april 2017 skrev chris burke <
>> cbu...@jsoftware.com>:
>>> 
>>> 
>>> Incidentally, for production code, I suggest starting by removing any
>> sales
>>> not matched in returns and vice versa, so that the matching algorithm is
>>> applied only to potential matches.
>>> 
>>>> On Wed, Apr 12, 2017 at 2:53 PM, chris burke <cbu...@jsoftware.com>
>> wrote:
>>>> 
>>>> Great.
>>>> 
>>>> In case you need more complicated handling of the "gray area"
>>>> transactions, I believe they would be relatively few in number, so most
>> of
>>>> the time you could do the matching efficiently, then check for any keys
>>>> with returns preceding sales. For those, setting aside the first such
>>>> return and repeating should clear them quickly.
>>>> 
>>>> Timing should be well under 1 second for a million records.
>>>> 
>>>>> On Wed, Apr 12, 2017 at 1:57 PM, Joe Bogner <joebog...@gmail.com>
>> wrote:
>>>>> 
>>>>> Just for completeness, I added a line that incorporates the sequence
>> check
>>>>> into the cancel logic. Works great
>>>>> 
>>>>> NB. hui progressive index
>>>>> NB. http://code.jsoftware.com/wiki/Essa

Re: [Jprogramming] matching & cancelling transactions

2017-04-13 Thread Louis de Forcrand
Try this. On my phone, it runs almost 6 times faster than your version on your 
small example data, but uses more space (maybe sparse matrices would be 
faster?), with:
   1e3 timespacex 'applycredits'
0.000630182 4608
vs
   1e3 timespacex 'ac t'
0.000131279 6400

Of course this extra space could be a big slowdown on larger data. At least 
it's more J-ish:

ac=: +/"1@s@p
s=: [: u&.(,&0) d&.(0&,)
u=: [: +/\.^:_1 (0<.+)/\.   NB. u -: d&.(-@|.)
d=: [: +/\ ^:_1 (0>.+)/\.&.|.
p=: |:@=@:| * [: * {:"1

t=: (}."1 /: {."1) ".;._2 data
ac t

It works on a minimal form of your data where records are sorted by their 
index, and results are in the form:
 0: ok
 1: cancelled
_1: credit

Louis

> On 12 Apr 2017, at 21:57, 'Bo Jacoby' via Programming 
>  wrote:
> 
> Hi Joe!
> My favorite datastructure is ORDINAL FRACTIONS - the algebra of data 
> 
> |  
> |   
> |   
> |   ||
> 
>   |
> 
>  |
> |  
> ||  
> ORDINAL FRACTIONS - the algebra of data
> This paper was submitted to the 10th World Computer Congress, IFIP 1986 
> conference, but rejected by the referee  |   |
> 
>  |
> 
>  |
> 
> 
> Your data are coded like this
> 10 Joe
> 20 Bob
> 30 Jane
> 01 blue
> 02 red
> 03 purple
> 11 1
> 11 -1
> 11 1
> 22 1
> 22 1
> 22 3
> 22 -1
> 22 -1
> 33 5
> 33 -2
> 33 2
> (Written with double CRs because the mail program has a history of deleting 
> my CRs).
> Summation gives the result
> 10 Joe
> 20 Bob
> 30 Jane
> 01 blue
> 02 red
> 03 purple
> 11 1
> 22 3
> 
> 33 5
> I have not done the summation in J, but I'd like to do it.
> Perhaps this helps you.
> Bo.
> 
> 
> 
>Den 0:04 torsdag den 13. april 2017 skrev chris burke 
> :
> 
> 
> Incidentally, for production code, I suggest starting by removing any sales
> not matched in returns and vice versa, so that the matching algorithm is
> applied only to potential matches.
> 
>> On Wed, Apr 12, 2017 at 2:53 PM, chris burke  wrote:
>> 
>> Great.
>> 
>> In case you need more complicated handling of the "gray area"
>> transactions, I believe they would be relatively few in number, so most of
>> the time you could do the matching efficiently, then check for any keys
>> with returns preceding sales. For those, setting aside the first such
>> return and repeating should clear them quickly.
>> 
>> Timing should be well under 1 second for a million records.
>> 
>>> On Wed, Apr 12, 2017 at 1:57 PM, Joe Bogner  wrote:
>>> 
>>> Just for completeness, I added a line that incorporates the sequence check
>>> into the cancel logic. Works great
>>> 
>>> NB. hui progressive index
>>> NB. http://code.jsoftware.com/wiki/Essays/Progressive_Index-Of
>>> oc=: i.~ (] - {) /:@/:
>>> pi=: #@[ ({. i.&(,.oc) }.) [ i. ,
>>> 
>>> NB. argument is 3-col table of seq,key,qty
>>> NB. result is the unmatched transactions
>>> matchtrans=: 3 : 0
>>> msk=. 0<{:"1 y
>>> sales=. msk#y
>>> returns=. (-.msk)#y
>>> ndx=. (}."1 sales) pi | }."1 returns
>>> cancels=. ndx<#sales
>>> NB. ensure cancel is after sale
>>> cancels =. cancels *. (({."1 (<<(cancels)#ndx){sales) < ({."1
>>> (cancels#returns)))
>>> ((<<>> )
>>> 
>>> 
 On Wed, Apr 12, 2017 at 4:14 PM, Joe Bogner  wrote:
 
 Chris, this looks promising. Thanks for sharing. It's nearly instant on
>>> a
 million rows.
 
 Which row had a return before a transaction? seq 10 was an example of a
 partial return. The hypothetical customer returned 2 out of the 5
>>> purchased
 prior. I added that example since technically per the original spec it
 wouldn't be cancelled out in this pass.  It's a gray area so I may be
>>> able
 to use this approach, especially since I don't see how to incorporate
>>> the
 time element into the progressive index.
 
 Thanks again
 
 
 On Wed, Apr 12, 2017 at 3:52 PM, chris burke 
>>> wrote:
 
> This might be done by comparing matrices of sales and returns. The
> function
> below seems to be close to what you want. It doesn't exactly match your
> example, but your example has cases where returns are made before the
> transactions. Was this intentional?
> 
> The code should run faster than a looping solution.
> 
> Code:
> 
> NB. hui progressive index
> NB. http://code.jsoftware.com/wiki/Essays/Progressive_Index-Of
> oc=: i.~ (] - {) /:@/:
> pi=: #@[ ({. i.&(,.oc) }.) [ i. ,
> 
> NB. argument is 3-col table of seq,key,qty
> NB. result is the unmatched transactions
> matchtrans=: 3 : 0
> msk=. 0<{:"1 y
> sales=. msk#y
> returns=. (-.msk)#y
> ndx=. (}."1 sales) pi | }."1 returns
> cancels=. ndx<#sales
> ((<< )
> 
> Example:
> 
> dat=: ".;._2 (0 : 0)
> 1 1 1
> 2 1 _1
> 3 1 1
> 4 2 1
> 5 2 1
> 6 2 3
> 7 2 _1
> 

Re: [Jprogramming] type/domain of an argument

2017-04-03 Thread Louis de Forcrand
A few useful shortcuts:

isBoxed=: 0 < L.
isChar=: {.@, e. a."_
isInt=: = <.
isReal=: = +

Louis

> On 2 Apr 2017, at 14:43, 'Pascal Jasmin' via Programming 
>  wrote:
> 
> datatype or 3!:0
> 
> 
> datatype 3 4.1 0
> 
> 
> 
> 
> 
> From: Herbert Weissenbaeck // Privat 
> To: programm...@jsoftware.com 
> Sent: Sunday, April 2, 2017 8:33 AM
> Subject: [Jprogramming] type/domain of an argument
> 
> 
> 
> quick beginner's question:
> 
> how can i test whether an x or y argument is an array of int or an array of 
> float or an array of char or of any other type (to avoid domain errors and 
> handle different types differently in functions)?
> 
> thank you
> 
> herbert
> 
> 
> --
> 
> 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] Fast derivative of Softmax function

2017-02-27 Thread Louis de Forcrand
You probably know about it, but I'll mention it anyway: there's a primitive 
partial derivative operator in J. I think it would do exactly what you want 
(numerically), and it's probably reasonably fast. It's not too hard to use 
either:

dsoftmax=: sm D.1

Louis

> On 27 Feb 2017, at 10:20, 'Pascal Jasmin' via Programming 
>  wrote:
> 
> one optimization is removing the rank"0 _, so that the function not need to 
> be reparsed for each x
> 
> untested.
> 
> 
> dsoftmax=: 4 : 0
> rx=. ''
> for_i. x do.
> smx=. i softmax y
> for_j. i.#vals do.
> if. j_index. = i_index. do. rx=. rx , smx * (1 - smx)
> else.  rx=. rx ,(j softmax y)* (0 - smx) end.
> end. end.
> rx
> )
> 
> 
> - Original Message -
> From: 'Jon Hough' via Programming 
> To: Programming Forum 
> Sent: Monday, February 27, 2017 3:09 AM
> Subject: [Jprogramming] Fast derivative of Softmax function
> 
> Given an array, we can calculate the softmax function
> https://en.wikipedia.org/wiki/Softmax_function
> 
> a =: 0.5 0.6 0.23 0.66
> sm=:(] % +/ )@:^ NB. softmax
> 
> sm a 
> 0.247399 0.273418 0.188859 0.290325
> 
> The (partial) derivative of softmax is a little more complicated:
> 
> If the array is of length N, we need an NxN matrix of partial derivatives 
> where (in pseudo code)
> 
> derivatives[i,j] = sm (array[i] )  *( 1 - sm(array[j])   if i == j
> or
> derivatives[i,j] =  -1 * sm (array[i] )  * ( sm(array[j])   if i != j
> 
> ( see here for the reasoning: 
> http://eli.thegreenplace.net/2016/the-softmax-function-and-its-derivative/ )
> 
> My implementation of the partial derivatives is this:
> 
> 
> NB. x value is index, y value is the whole array
> dsoftmax=: 4 : 0
> idx=. x
> vals=. y
> smx=. idx softmax vals
> rx=. ''
> for_j. i.#vals do.
>  if. j = idx do. rx=. rx , smx * (1 - smx)
>  elseif. 1 do. rx=. rx ,(j softmax vals)* (0 - smx) end.
> end.
> rx
> )
> 
> 
> Then, for example using above array a,
> 
> (i.# a) dsoftmax"0 _  a
> 
> gives the values, in a 4x4 matrix.
> 
> This is quite slow. I have tried to do this without iterating and branching, 
> but cannot figure out a way to do it.
> Any help appreciated.
> 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

  1   2   >