Re: [Jprogramming] (no subject)

2017-11-23 Thread Roger Shepherd
10#.40#1x

datatype 10#.40#1x
extended

Sent from Mail for Windows 10

From: 'Skip Cave' via Programming
Sent: Thursday, November 23, 2017 3:17 AM
To: programm...@jsoftware.com
Subject: [Jprogramming] (no subject)

I want to greate an integer with all ones:

   ".10#'1'

11


   datatype ".10#'1'

integer


   ".15#'1'

111

   datatype ".15#'1'

integer


   ".20#'1'

1.1e19


NB. Drat! it seitched to floating.


datatype ".20#'1'

floating

NB. So I need to use extended precision:

 x:".20#'1'

0656


NB. Uh oh! something is wrong. Not all ones!


datatype x:".20#'1'

rational


NB. Rational? What happened to extended precision?

NB. So how do I create an integer with say, 50 onres?


x:".50#'1'

0805019569335803527359330256945152


NB. Nope!



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

2017-11-19 Thread Roger Shepherd
I have probably lost track of the various goals and contexts in play here, but 
“enumerating k-sets” may fit somewhere and be useful.
Pick a positive integer k. For that k, there is an enumeration of all k-sets, 
so KSet[N] = CharacteristicInteger ( of Nth k-set in lexicographical order).
So, say, for N=25.
For k=1, KSet[25 (25!1)] = 33554432 (2^25)
For k=2, KSet[25 (2!7 + 1!4)] = 144 (2^7+2^4)
For k=3, KSet[25 ((3!6)+(2!3)+(1!2))] = 76 ((2^6)+(2^3)+(2^2))

The algorithm is well known and lends itself to creating a “random” k-set.
https://en.wikipedia.org/wiki/Combinatorial_number_system
 
Sent from Mail for Windows 10

From: Linda Alvord
Sent: Friday, November 3, 2017 2:28 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Oops, this should be better:


   comb4=: 13 :'|.I.(x=+/"1#:i.2^y)##:i.2^y'
   comb4
[: |. [: I. ([ = [: +/"1 [: #: [: i. 2 ^ ]) # [: #: [: i. 2 ^ ]
   #3 comb4  5
10
   
Linda


-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Raul Miller
Sent: Thursday, November 2, 2017 2:54 AM
To: Programming forum 
Subject: Re: [Jprogramming] Partitions

No, you did not test your work.

   #3 comb 5
10
   #3 comb4 5
56

Probably the simplest way to approach what I think you are trying to do 
involves expanding the part in parenthesis independent of the rest of it.

And, personally, when I am working on a line of J code, I like to have a little 
test rig so that I can quickly see when I have gone astray.
Doing that here (and clipping out my mistakes), then adding comments gets me 
this:

First, I set up a test rig with the original expression:

   #3 ([ ((= +/"1) |.@:I.@# ]) 2 #:@i.@:^ ]) 5
10

Then, I rephrase the outer part as an explicit expression for 13 :

  #3 (13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y') 5
10

Since that worked, I take a look at what 13 : gave me

   13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y'
[ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]

Next, I try that out in my test rig:

   #3 ([ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]) 5
10

So, now that I have that, I do a rephrase of the inner part for another 13 :

   # 3([ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ]) 5
10

And, since that works, I take a look at what it gave me:

   [ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ] [ ([: |. [: I. ] #~ [ = [: 
+/"1 ]) [: #: [: i. 2 ^ ]

And, voila, I've got another variation that I can use in a word definition:

   comb4a=: [ ([: |. [: I. ] #~ [ = [: +/"1 ]) [: #: [: i. 2 ^ ]

That's a bit ugly, but ascii is ugly (but, also, standardized and - thus - 
widely available).

So, we can try that out and see it in operation:

   3 comb4a 5
0 1 2
0 1 3
0 1 4
0 2 3
0 2 4
0 3 4
1 2 3
1 2 4
1 3 4
2 3 4

Also... note that when working with "real life" mechanisms (not just J), having 
some sort of test rig to make sure that what you are doing behaves like you 
think it does can be an invaluable time saver. (The alternative - putting a lot 
of work into something, only to find out that it doesn't work and that you have 
to start over again - is sometimes necessary but not always attractive.)

(Well, that, and remember that this approach is slower than the stock comb 
implementation when y > 10 - so mostly I would just do require'stats' and then 
use that comb implementation.)

Then again, now that we have this variation, we could also try to reconstruct 
an explicit expression which does the same thing. For that we want to merge 
these two examples:

   #3 (13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y') 5
   # 3([ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ]) 5

Perhaps something like:
   #3 (13 :'|.I.(x = +/"1 t) # t=. #:i. 2^y') 5
10

(But I would not blindly enshrine results just because they were generated by 
an automated mechanism - such things can be useful tools, of course, but if you 
abandon your own understanding that's not good.)

I hope this helps,

--
Raul

On Wed, Nov 1, 2017 at 11:55 PM, Linda Alvord  wrote:
> This is another way to get to Raul's ideas in a tacit soluion:
>
> comb4=: 13 :'|.I.(x=+/"1#:i.x^y)##:i.x^y'
>2 comb4 4
> 0 1
> 0 2
> 0 3
> 1 2
> 1 3
> 2 3
>comb4
> [: |. [: I. ([ = [: +/"1 [: #: [: i. ^) # [: #: [: i. ^
>
> Linda
>
>
> -Original Message-
> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On 
> Behalf Of Lippu Esa
> Sent: Wednesday, November 1, 2017 5:53 PM
> To: 'programm...@jsoftware.com' 
> Subject: Re: [Jprogramming] Partitions
>
> Thank you, Raul! I knew that there would be a tacit solution. But comb is 
> better with big y as you said.
>
> Esa
>
> -Original Message-
> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On 
> Behalf Of Raul Miller
> Sent: Wednesday, November 1, 2017 11:26 PM
> To: Programming forum 
> Subject: Re: [Jprogramming] Partitions
>
> comb3 performs well for y<10, but bogs down (compared to 

Re: [Jprogramming] Partitions

2017-11-07 Thread Roger Shepherd
Here is at least one reference, with linked references to others:
http://www3.cs.stonybrook.edu/~algorith/implement/ruskey/implement.shtml


Sent from Mail for Windows 10

From: Raul Miller
Sent: Tuesday, November 7, 2017 10:13 AM
To: Programming forum
Subject: Re: [Jprogramming] Partitions

This book: 
https://math.dartmouth.edu/news-resources/electronic/kpbogart/ComboNoteswHints11-06-04.pdf

Thanks,

-- 
Raul


On Tue, Nov 7, 2017 at 8:38 AM, Erling Hellenäs
 wrote:
> Like this?
>
> "Generate Set Partitions - K Subsets
>
> Generate all set partitions with k subsets from an original set with n
> unique items.
> J definition created by Erling Hellenäs from a Frank Ruskey algorithm."
>
> Followed by the two programs.
>
> The book in the reference list and the reference number after "algorithm".
> I did not find a published book with this name.
>
> /Erling
>
> Den 2017-11-07 kl. 14:23, skrev Raul Miller:
>>
>> Depends on the text?
>>
>> But I don't think we have a full collection of partition routines to
>> adequately address the various partitioning concepts ennumerated in
>> the book linked from
>> http://jsoftware.com/pipermail/programming/2017-October/049377.html
>>
>> 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] Partitions

2017-10-26 Thread Roger Shepherd
In addition to the 12-fold way of Rota, there is the classification by a 
20-fold way due to Kenneth Bogart of Dartmouth.
When necessary, reference to a classification can help communicate when one 
problem is being specified and another is being solved for.
There are extreme conditions (empty this and excess that) where convenient, 
generally applicable solution formulas are at least a little bit wrong.
The following is from 
https://math.dartmouth.edu/news-resources/electronic/kpbogart/ComboNoteswHints11-06-04.pdf
On page 76 is Table 3.2: The number of ways to distribute k objects to n 
recipients, with restrictions on how the objects are received
The Twenty-fold Way: A Table of Distribution Problems k objects and conditions 
n recipients and mathematical model for distribution on how they are received 

Ignore this if I am the only one confused by the properties of the various 
programs/solutions being offered here.

Sent from Mail for Windows 10

From: Erling Hellenäs
Sent: Thursday, October 26, 2017 8:57 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Hi all !

I didn't find any way to improve Esas solution.

I wanted to measure mine so I made it into a program. I improved it 
slightly.

parE =: 4 : 0
NB. All combinations of all items
v=.}.comb i.y
NB. Select combinations with less than or equal to 1+y-x items
v1=.((#&> v)<:1+y-x)#v
NB. All combinations in all buckets
v2=. > , ,&.>//>x#<<"0 v1
NB. Select combinations with one and only one of each number
v3=.(((i.y)-:[:/:~[:;]) "1 v2) # v2
NB. The idea here is to normalize the representation so that
NB. the copies are adjacent.
NB. Sort buckets within each combination after first item in each bucket
v31=.(([: /: [: {.&.> ]){])"1 v3
NB. Sort buckets within each combination after number of items in each 
bucket
v4=.(([: /: [: #&.> ]){])"1 v31
NB. Remove duplicates, sort to show nicely
/:~ ~.v4
)


    ts'4 parE 6'
2.6112 7.66842e8


Cheers,

Erling Hellenäs


Den 2017-10-26 kl. 10:38, skrev Erling Hellenäs:
> Hi all !
>
> I analysed Esa Lippus solution. The printout is long, but here is the 
> code and my explanations.
>
> par2=: 4 : 0
> a=.(y#x) #: i. x^y
> sort ~.((x=#@~."1 a)#a)  )
> sort=: /:~
> 3 par2 5
> x=:3
> y=:5
> NB. All combinations of y elements
> [a=:(y#x) #: i. x^y
> NB. Select the combinations in which the y elements
> NB. are distributed over x buckets
> [v=: ((x=#@~."1 a)#a)
> NB. Pack the elements in each bucket combination.
> [w=:v  NB. Sort to display nicely
> sort ~. w
>
> Cheers,
>
> Erling Hellenäs
>
>
> Den 2017-10-26 kl. 07:07, skrev 'Skip Cave' via Programming:
>> Lippu,
>>
>> Yes, your par2 is MUCH faster than Raul's nparts. If I have some time, I
>> will put together a time/space test for all the proposed solutions.
>>
>> Skip
>>
>> Skip Cave
>> Cave Consulting LLC
>>
>> On Wed, Oct 25, 2017 at 1:58 PM, Lippu Esa  wrote:
>>
>>> Hello,
>>>
>>> I get the following with the partition verb I posted last Thursday 
>>> (J8.06
>>> and 4 core 2.9GHz CPU and 16GB RAM):
>>>
>>> par2=: 4 : 0
>>> a=.(y#x) #: i. x^y
>>> sort ~.((x=#@~."1 a)#a) >> )
>>>
>>>     ts '#5 par2 8'
>>> 4.15977615 151821824
>>>     ts '# 6 par2 8'
>>> 2.55073168 358252032
>>>
>>> Esa
>>>
>>> -Original Message-
>>> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On
>>> Behalf Of 'Skip Cave' via Programming
>>> Sent: Wednesday, October 25, 2017 8:12 PM
>>> To: programm...@jsoftware.com
>>> Subject: Re: [Jprogramming] Partitions
>>>
>>> Raul got it right with his nparts verb. In my original example of 
>>> par, I
>>> constructed the required output of par by hand. In that process, I
>>> overlooked the majority of the possible combinations of the ways that 5
>>> items could be separated into 3 containers. That caused confusion in 
>>> the
>>> various attempts to implement what I proposed. I wasn't very 
>>> thorough in
>>> vetting my example output, and Mike valiantly tried to point out the 
>>> flaws
>>> in my proposal. Raul showed how much I missed clearly in my par example
>>> when he demonstrated:
>>>
>>>     #3 nparts 5
>>> 25
>>>     #3 par 5
>>> 6
>>>
>>> Rob also pointed out the issue in his posts. Erling's v7 verb got to 
>>> the
>>> same result as Raul's nparts.
>>>
>>> The number of possible partitions of n objects grows rapidly with n:
>>>
>>>  #3 nparts 5
>>>
>>> 25
>>>
>>>  #3 nparts 6
>>>
>>> 90
>>>
>>>  #3 nparts 7
>>>
>>> 301
>>>
>>>  #3 nparts 8
>>>
>>> 966
>>>
>>>
>>>
>>> Increasing the number of partitions reduces the number of 
>>> combinations but
>>> significantly increases execution time with Raul's nparts :
>>>
>>>
>>>     #4 nparts 8
>>>
>>> 1701
>>>
>>>     #5 nparts 8
>>>
>>> 1050
>>>
>>>     #6 nparts 8
>>>
>>> 266
>>>
>>>
>>> The 5 #nparts 8  took over 30 seconds to run on my i7 laptop. The #6 
>>> nparts
>>> 8 took about 3 minutes.
>>>
>>>
>>> Is there a more computationally efficient way to calculate the 
>>> partitions?
>>>
>>>
>>> Skip
>>> 

Re: [Jprogramming] "n-volume" of an "n-sphere"

2017-08-23 Thread Roger Shepherd
Is there something specifically wrong with common sources of definitions such 
as 
http://dictionary.sensagent.com/N-sphere/en-en/

Just checking 

Sent from Mail for Windows 10

From: Jimmy Gauvin
Sent: Wednesday, August 23, 2017 9:20 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] "n-volume" of an "n-sphere"

Even in Mathworld it is not clear that disk is in common usage.

from http://mathworld.wolfram.com/Ball.html we have :

The [image: n]-ball, denoted [image: B^n], is the interior of a sphere
 [image: S^(n-1)], and
sometimesalso called the [image: n]-disk
. (Although physicists often use
the term "sphere " to mean the
solid ball, mathematicians definitely do not!)

and from http://mathworld.wolfram.com/Disk.html we have :

The [image: n]-disk for [image: n>=3] is called a ball
, and ...



On Wed, Aug 23, 2017 at 6:50 AM, R.E. Boss  wrote:

> The question is "Is an n-disk a well-established mathematical term?".
>
> A disc originally had only meaning in 3 dimensions, being " a circular
> flat object", e.g. a cd or compact disc;  http://dictionary.cambridge.
> org/dictionary/english/disc.
> Also: a disk is normally "a flat, circular device that is used for storing
> information"; http://dictionary.cambridge.org/dictionary/english/disk.
>
> You reference to mathworld is not supported by other references on that
> page, so is probably a private generalization of mr. Weisstein. In any case
> not convincing.
> I respond with https://www.encyclopediaofmath.org/index.php/Disc where a
> disc is defined as "The part of the plane bounded by a circle and
> containing its centre." So they stick to the 2-dimensional case.
> Also a topological disc is 2-dimensional https://www.
> encyclopediaofmath.org/index.php/Disc,_topological.
> Another reference is https://www.wikiwand.com/en/Disk_(mathematics) which
> states "In geometry, a disk (also spelled disc)[1] is the region in a plane
> bounded by a circle. "
>
> Your reference to math.stackexchange is also an instance of one person
> using this term once, not convincing at all.
>
> John Lee in his book explicitly states on the pages indicated:
> "In the case n=2, we sometimes call B^2 the (open) unit disk.
> (...)
> We sometimes call B^2 the closed unit disk." (where this B has a superbar,
> which is not copied)
> So he also restricts a disk to 2 dimensions.
>
> Finally, your reference concerning CW-complexes. Perhaps in that, rather
> restricted area of mathematics it seems disk is used as synonym for ball,
> see also  https://www.wikiwand.com/en/CW_complex.
>
> My final conclusion is that an n-disk is NOT a well-established
> mathematical term, apart from n=2 and, which I cannot decide, perhaps in
> the area of CW-complexes.
>
>
> R.E. Boss
>
>
> > -Original Message-
> > From: Programming [mailto:programming-boun...@forums.jsoftware.com]
> > On Behalf Of Murray Eisenberg
> > Sent: maandag 21 augustus 2017 17:56
> > To: programm...@jsoftware.com
> > Subject: Re: [Jprogramming] "n-volume" of an "n-sphere"
> >
> > To the contrary, “n-disk” is a well-established mathematical term, for
> > arbitrary dimension n = 1, 2, 3, 4,  See, for example,
> > http://mathworld.wolfram.com/Disk.html
> > 
> > (which, alas, mangles the distinction between “disk” and “ball”).
> >
> > [Often, for emphasis or disambiguation, the terms “closed n-disk” or
> “closed
> > n-ball” are used for the set of points in Euclidean n-space of distance
> at most
> > r from a given point; and then “open n-ball” for the set of points of
> distance
> > strictly less than r. (And, in fact, the terms “disk” and “ball” are
> well-
> > established even, more generally, for arbitrary metric spaces.)]
> >
> > For a typical recent instance of the usage, see:
> >
> > https://math.stackexchange.com/questions/24785/the-n-disk-dn-
> > quotiented-by-its-boundary-sn-1-gives-sn
> >  > quotiented-by-its-boundary-sn-1-gives-sn>
> >
> > The usage is defined in many sources. See, e.g.:
> >
> > John Lee, Introduction to Topological Manifolds, 2nd ed., pages 21-22.
> >
> > Soren Hansen, "CW complexes”, page 1
> > (https://www.math.ksu.edu/~hansen/CWcomplexes.pdf
> > ).
> >
> >
> > > On21 Aug 2017 11:15:20 +,"R.E. Boss"  > > wrote:
> > >
> > > AFAIR disk is not a mathematically defined term for high dimensions.
> > > Ball is as you defined it, where one can argue whether the distance is
> > "strictly less" or " at most" r.
> > > Sphere is the definition where the distance is equal to r.
> > >
> > >
> > > R.E. Boss
> > >
> > >
> > >> -Original Message-
> > >> From: Programming [mailto:programming-
> > 

Re: [Jprogramming] Fractional parts

2017-08-09 Thread Roger Shepherd
Continued fractions come immediately to mind as an application, per 
http://code.jsoftware.com/wiki/Essays/Continued_Fractions
Suggestions here might be suitable to remove restrictions mentioned in that 
essay.

Continued fractions themselves are applied in at least the ways stated in
https://math.stackexchange.com/questions/585675/what-are-the-applications-of-continued-fractions

I am working a bit with Diophantine equations, so they seem like a natural tool 
to me.


Sent from Mail for Windows 10

From: Skip Cave
Sent: Wednesday, August 9, 2017 1:09 PM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Fractional parts

Markus,

Actually, yes, I looked at using extended precision, and here's what
happened:

v=:2%(3r19-%x:1 2 3 245 246 247 248)

​v
_19r8 _76r13 _57r5 4655r358 9348r719 13 9424r725​

   fp=. * * 1||

fp v

_3r8 _11r13 _2r5 1r358 1r719 0 724r725

ip=: * * <.@|

ip v

_2 _5 _11 13 13 13 12


So our original definitions would work with extended precision, but the
fractional parts would be rational rather than decimal. Extended precision
still keeps the negative signs on the fractions.


I'm not so sure about Martin's approach with extended precision:

mfp1 =: 1&| NB. Martin's first suggestion for fractional part

mfp1 v

5r8 2r13 3r5 1r358 1r719 0 724r725

mfp2 =: 

Re: [Jprogramming] determine the cycle

2016-08-25 Thread Roger Shepherd
Pardon the interruption, but are you taking advantage of the well known
depth first search, rooted tree growing search that produces a complete
basis for all cycles in a connected graph? From there you can go on to
various exchange system (matroids) if you've a mind to. There's a lot of
work done and documented in this area. J routines could be organized to
deal with linear bases and basis exchange methods. Just an observation.


On Thursday, August 25, 2016, R.E. Boss  wrote:

> Given the edges in a graph which is a cycle, like
>edges
> 1  2
>  3  1
>  2  4
>  4  5
>  5  6
>  6  7
>  7  8
>  9  8
> 10  9
> 11 10
> 11 12
> 12 13
> 14 15
> 15 16
> 17  3
> 18 17
> 18 19
> 20 19
> 20 21
> 21 22
> 22 14
> 16 23
> 13 24
> 25 24
> 26 25
> 23 26
> Vertices of the graph are represented by >:i.26
> Question is how to determine in an elegant way the sequence of vertices
> along the cycle, which is
> 1 2 4 5 6 7 8 9 10 11 12 13 24 25 26 23 16 15 14 22 21 20 19 18 17 3 1
>
>
> R.E. Boss
>
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm



-- 
Sent from Gmail Mobile
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] A clever way to find the maximum possible integer

2016-03-19 Thread Roger Shepherd
What should I read to anticipate the effects if 33 b. and similar verbs on
extended integers?
Thanks for any pointers.


On Monday, March 14, 2016, Marshall Lochbaum  wrote:

> I just stumbled across the following snippet. Platform independent,
> constant time (for those with 2048-bit processors, naturally), and only
> nine characters!
>
>33 b.~ _1
> 9223372036854775807
>
> The verb (33 b.), not often used in J, is the unsigned shift operator,
> like C's (<<). When the left operand x is positive, it has the same
> effect as multiplying y by (2^x). If x is negative and y is positive, it
> is the same as division by (2^-x) followed by rounding down. However, if
> x and y are both negative, then y is shifted as an unsigned integer: all
> of its bits are moved right by (|x), and (|x) zeros are added on the
> left.
>
> If y is _1, then its two's complement representation is all ones.
> Shifting right by one leaves a number represented by a zero and then all
> ones--the largest possible positive integer.
>
> If you want both the maximum and minimum integers:
> MIN_INT =: <:- MAX_INT =: 33 b.~ _1
>
> Marshall
> --
> For information about J forums see http://www.jsoftware.com/forums.htm



-- 
Sent from Gmail Mobile
--
For information about J forums see http://www.jsoftware.com/forums.htm