An example using /:@/: (rank), basically from Fractals, Visualization and J
4th ed. section 5.6
load '~addons/graphics/fvj4/raster.ijs'
load '~addons/graphics/fvj4/povkit.ijs'
cile
$@] $ ((/:@/:@] <.@:* (% #)) ,)
cile uses /:@/:
replace a plus table with 5 levels:
5 cile +/~i.10
0 0 0 0 0 0 1 1 1 2
0 0 0 0 0 1 1 1 2 2
0 0 0 0 1 1 1 2 2 3
0 0 0 1 1 1 2 2 3 3
0 0 1 1 2 2 2 3 3 3
1 1 1 2 2 2 3 3 4 4
1 1 2 2 3 3 3 4 4 4
1 2 2 3 3 3 4 4 4 4
2 2 3 3 3 4 4 4 4 4
2 3 3 3 4 4 4 4 4 4
a small plasma cloud with 3 levels:
3 cile 0.6 plasma 3
2 1 1 0 1 1 1 1 2
1 1 0 1 1 0 1 2 2
1 1 2 0 0 0 0 0 1
1 2 2 1 0 0 0 0 0
2 1 1 2 2 1 1 0 0
1 2 2 2 2 1 1 0 0
2 2 2 1 2 0 1 0 0
2 2 2 2 0 1 2 0 0
2 2 2 2 1 0 0 0 0
5{.P256
255 0 0
255 5 0
255 10 0
255 15 0
255 20 0
P256 is a palette of 256 fully saturated colors
View a plasma cloud (256 levels) with hurst exponent 0.6:
view_image P256; 256 cile 0.6 plasma 9
Funny story: I wrote cile during a power outage (took about an hour). I
wrote it on a scrap of paper that was used as a coffee coaster by a
colleague and that stained it. I was stunned when power returned and cile
did what I wanted and my colleague didn't share my amazement at the scrap
of paper.
Best: Cliff
On Sun, Jan 8, 2023 at 10:56 PM Omar Antolín Camarena <[email protected]>
wrote:
> Let me start by saying I loved your interview on the Array Cast!
>
> One example of /: I coincidentally noticed today is the following
> definition of lexicographic order for strings:
>
> lex_le =: 0 1 -: /:@(,&<)
>
> I was about to program it in a much more complicated way when I suddenly
> remembered J aready knows how to sort everything if you just box it! Note
> that its correctness in the case of equality depends on /: being a stable
> sort. (Note also that it defines a total order on all nouns, of any rank
> and data type, not just strings; J's "secret" total order on all nouns!)
>
> Another neat thing about grade up is that ({ /:) is a special combination:
> x ({ /:) y gives you the x-th smallest item of y without fully sorting y.
> The description in NuVoc stops short of saying that it uses the Quickselect
> [1] algorithm with a random pivot, but it sure makes it sound like it does.
> It seems to be limited to y that are 1-dimensional with numeric entries,
> sadly (or maybe I'm misunderstanding the phrase "y is an integer or
> floating-point list").
>
> A third, somewhat tongue-in-cheek answer is that you can regard the dyadic
> sort up case, namely x /: y, as just shorthand for (/: y) { x, so really
> any example of grade up should count as a examples of using grade up (/:)
> and indexing ({).
>
> A fourth, perhaps less essential example, that I've come across is while
> using inverted tables: I sometimes need to sort several sets of columns by
> one of the columns. Say I have one table of student grades with columns for
> student_number, name, homework1, homework2, exam1 and exam2 (each column a
> separate J variable, which I find is the most convenient way of working
> with tabular data) and I want tables in order of student_number (because
> that's the order the system where I enter the grades wants) of homeworks
> and exams separately. I could of course do:
>
> homework =: (name ,. <"0 homework1,. homework2) /: student_number
> exam =: (name ,. <"0 exam1,. exam2) /: student_number
>
> which sorts student_number twice but I sometimes just keep a few orders
> around, to look at data various ways:
>
> by_student_number =: /: student_number
> by_exam_total =: \: exam1 + exam2
> ...
> homework =: by_student_number { name ,. <"0 homework1,. homework2
> exam =: by_student_number { name ,. <"0 exam1,. exam2
>
> --
> Omar
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm