> I am curious what applications there are that really need a user-specified
> comparison function (rather than just a sort key, like dyadic /: takes).
There must some applications out there with some sort of smart string
ordering that couldn't be reduced to array ordering. And of course in a
This is a stable algorithm because it only ever changes the order of
elements if one's less than the pivot and the other isn't. The problem
it has is that if elements compare equal but don't match then it'll
never get down to an array where ~.y has length 1. You get a stack error
on (<&:*qs _1 2
You can get a three-result comparison from a boolean c by using it
twice, (c-c~). See https://www.jsoftware.com/papers/50/50_00.htm . If
this fails to distinguish elements then they are equivalent under the
ordering, so a stable algorithm has to maintain their input order.
It's my opinion that
I don't know how you'd choose the points to sample, but once you have
them a soft-margin SVM solves for the boundary.
https://en.wikipedia.org/wiki/Support_vector_machine
Marshall
On Wed, Apr 05, 2023 at 03:44:49AM -0700, Elijah Stone wrote:
> I know not the first thing about linear programming
Interesting problem! I think this works: for starting permutation p,
keep two lists. At step i,
- l is {~^:i p, that is, the index 2^i steps further along the cycle
- m is the minimum index among those less than 2^i steps ahead.
Initially l is p and m is i.#p . To update, simultaneously replace
Regarding other ways to solve polynomials, I've found that the Aberth
method is fast and accurate, and it can be implemented with array
operations since it works on all roots at once. For example roots from a
random 20-coefficient polynomial takes about 1ms. Bini's "Numerical
Computation of
Tried out my own Laguerre implementation from here:
https://github.com/mlochbaum/bqn-libs/blob/master/polynomial.bqn#L80-L113
I remember I used J as a reference for this, but I think I ended up
following this one in Julia:
integer and float. I don't see why it changed so much.
>
> There is still a sizable niche for small-range integer sort at all lengths,
> but the range decreases with length.
>
> Henry Rich
>
> On 2/3/2023 9:59 PM, Marshall Lochbaum wrote:
> > In case it helps, I t
In case it helps, I took the following measurement with bencharray.
Looks like the parts other than those plateaus in the middle have gotten
faster since 9.03, although they were still steps up before. The input
ranges from -2^31 to 1-~2^31.
ng 0+16+32+... etc and then there are 6 ways to combine the
> accumulators.
>
> With AVX512 everything changes again.
>
> Henry Rich
>
> On 1/9/2023 8:32 PM, Marshall Lochbaum wrote:
> > Well, true, I'm not in favor of rearranging +/ either. The dangers of
> > floating
Well, true, I'm not in favor of rearranging +/ either. The dangers of
floating point don't include nondeterminism, unless you make them.
However, I also think matrix products have it worse. Numbers with widely
varying exponents are a bit of an edge case. But when you're multiplying
a few large
on, Jan 9, 2023, 8:24 PM Marshall Lochbaum wrote:
>
> > The matrices in my example are integral.
> >
> > Marshall
> >
> > On Mon, Jan 09, 2023 at 05:20:49PM -0800, Elijah Stone wrote:
> > > I've thought in the past that it would be nice to have a mode fo
of parallel architecture.)
>
> On Mon, 9 Jan 2023, Marshall Lochbaum wrote:
>
> > I don't think you'd want to reorder matrix multiplications as that can
> > change the results by an arbitrary amount. Here's an example where
> > multiplic
I don't think you'd want to reorder matrix multiplications as that can
change the results by an arbitrary amount. Here's an example where
multiplication on one side cancels but not on the other side.
(+/ .*&.>/ , +/ .*&.>~/@:|.) 1e6 1e7;(1e13+=i.2);1 _1
┌┬──┐
It's not just Fibonacci numbers. This is equivalent to a general method
for computing continued fractions convergents in linear time, using
matrix multiplication. There's a nice explanation of why it works in
here:
https://perl.plover.com/classes/cftalk/INFO/gosper.txt
And a J version, with
a flipped
> version, as well as a function which takes two objects and produces a rank-1
> array whose sole two elements are those objects.
These functions are ∾⟜<, <⊸∾, and ⋈ in order.
Marshall
On Wed, Jun 15, 2022 at 08:53:20PM -0700, Elijah Stone wrote:
> On Wed, 15 Jun 2022, Marshall L
(and transpose ⍉ is missing its analogue, K's flip).
Marshall
On Wed, Jun 15, 2022 at 04:49:50PM -0700, Elijah Stone wrote:
> On Wed, 15 Jun 2022, Marshall Lochbaum wrote:
>
> > my opposition to J's flat array model (I think it's almost always worse
> > than BQN's based model) i
ch that kpnd is equivalent to * kd. This way one could do Kronecker sums
> > > (+kp) or Kronecker versions of whatever rank 0 dyad you'd like.
> > >
> > > Now to find an application for these verbs... Always nice to have a pretty
> > > solution waiting to meet it
t' via Programming, <
> programm...@jsoftware.com> wrote:
>
> > Hi everyone,
> >
> > In this episode we explore monadic and dyadic transpose and the ways it is
> > interpreted in APL, BQN and J.
> >
> > H
I have a .wav reader/writer here:
https://github.com/mlochbaum/JSound/blob/master/wav.ijs
It only works on fairly basic files, and I'm not maintaining it any
more, but it could be worth a try.
Marshall
On Sun, Apr 03, 2022 at 02:19:48PM -0400, J. Patrick Harrington wrote:
> I have been
All of these solutions except F# and Raku end up calling GMP for this
(which uses Miller-Rabin; so does J). I think F# uses the following .NET
library, while Raku appears to eventually call an npm package
jsbi-is-prime?
I believe this should be the expected result. Calling $ on a list gives
a one-element list, which gives the result of ^: gets a leading 1 in the
shape. The value of that list's one element is 1 for the first example
and 0 in the second, causing the difference in ranks.
Marshall
On Sun, Dec 05,
This definition isn't consistent with I. on a rank 1 argument, since it
returns a shape l,1 array:
($#:I.@,) 0 0 1 1
2
3
If I. combined the two, functions written with the high-rank version
would usually fail in this case. Better to make the programmer remember
an idiom than to provide an
While I don't think arrays will ever be as elegant for merge sort as
quicksort, I did recently find a strategy for merging sorted arrays
using binary searches. Here's a version that works if the two sides
don't share any elements:
o =. (+i.@#)@:I.
'addfhk' ,`(o~,o)`,} 'bcceg'
abccddefghk
:43PM -0700, Roger Hui wrote:
> The recent work on bit arrays in Dyalog APL is the source of numerous
> serious and subtle bugs. I am not speaking on any official capacity.
>
>
>
> On Mon, Aug 2, 2021 at 2:56 PM Marshall Lochbaum
> wrote:
>
> > Is (64-bit) J still
Is (64-bit) J still using 8 bytes for all its non-boolean integers and
floats? If so I think that mostly explains the difference. You can't
gain that much performance by turning 8 bits to 1 when you're still
regularly dealing with 64-bit values. The biggest advantage for bit
arrays in Dyalog was
s this match your understanding of your writeup?
>
> Thanks,
>
> --
> Raul
>
> On Mon, Jul 26, 2021 at 5:23 PM Marshall Lochbaum
> wrote:
> >
> > I'm the inventor(?) of structural Under. I won't comment on whether it
> > makes sense for J but can offer
I'm the inventor(?) of structural Under. I won't comment on whether it
makes sense for J but can offer a little more context.
The operation is well defined: here's a specification with proof. It's
pretty difficult because it needs to support arbitrary paths into a
nested array, but would be much
vector does not use
> boxing -- this expression probably has worse performance on
> sufficiently long depth vectors than pv_flat, but the < character
> there is <: which is decrement, not box.
>
> Thanks,
>
> --
> Raul
>
> On Sat, May 29, 2021 at 11:50 AM Marshall Lo
It's possible to convert depths to parent indices without boxes, by
sorting a depth list with twice the input size. The idea is to list each
depth twice, with the first instance representing it as a child entry,
and the second, which is increased by one, representing it as a parent
entry. After
t them has consumed countless hours and years of the lives
> of many, many people.
>
> Thanks,
>
> --
> Raul
>
> On Wed, Apr 14, 2021 at 10:28 AM Marshall Lochbaum
> wrote:
> >
> > The difference is that in the languages you list, an associative array
> >
The difference is that in the languages you list, an associative array
is mutable. A mutable object can be shared, and changes to one copy are
reflected in others. Immutable data is easier to reason about, making it
a better default, but mutability is essentially required to implement
many
a f^:n b is defined to be a^:n b. It's that simple.
Marshall
On Sun, Oct 18, 2020 at 06:09:27PM -0400, Raul Miller wrote:
> I am not sure what I would write there -- I do not feel I have an
> adequate understanding of the reasoning behind the current
> implementation (nor potential future
Possibly more complicated than you're looking for, but I added some
comments to an old (and not very good) counterpoint melody generator and
pushed it here:
https://github.com/mlochbaum/JSound/blob/master/counterpoint.ijs
The repository as a whole has tools for synthesis and mixing as well as
a
Here, |. should be called three times, and for each call the left
argument is a scalar and the right argument is a row or vector. This
suggests using rank 0 1, and it turns out that works:
(-i.#M) |."0 1 M
1 1 1 1 0 0 0 0
0 1 1 1 1 0 0 0
0 0 1 1 0 0 0 0
Probably a better way to approach this
:04:00PM +0100, Rudolf Sykora wrote:
> Dear Marshall and Henry,
>
>
> Marshall Lochbaum writes:
> > Although a matrix product will execute faster, if I want to write tensor
> > code that is straightforward, and extends to multiple contracted axes, I
> > would
Here is a way to permute the axes of an array that you might find easier
to work with:
A =. i. 2 3 4 5
$ ('ijkl'i.'ljik') |: A
5 3 2 4
The idea is that we start with A, which has axes ijkl, and want to
shuffle them around to get ljik. So we look up each of the letters ljik
in ijkl, which
Assuming you want all fills to come before the corresponding element,
you can use:
1j2 #&.|. data
a b r a c a d a b r a
I agree that fill-before is a reasonable interpretation for a negative
imaginary part, although I doubt J's complex replicate, or APL's expand,
are really the
floor
'rgb' viewmat (sct%%:2)"_ tolf gshow
NB. Proposed tolerant floor
'rgb' viewmat ((0,sct)*+/&.:*:@:[)tolf eqg gshow
NB. Another interesting model
'rgb' viewmat (-(]*[:(,~-@-.)|@-/@[)sct*+/&.:*:@:[)tolf
witheq(([:+./|@:-<:sct*>.&:|)0 0.5j0.5+]) gshow
Marshall
On
I think you have plenty of cause for confusion here. As far as I'm
aware, there is no source which clearly and correctly documents the
behaviour of J's tolerant complex floor. It's also a poor design in my
opinion: in particular it fails to satisfy the desirable property that
if c=z for a complex
Listed under "Requests" here:
https://code.jsoftware.com/wiki/System/Interpreter/Requests#Support_inverse_for_I._y
Forum discussions:
http://www.jsoftware.com/pipermail/general/2006-April/026874.html
http://www.jsoftware.com/pipermail/programming/2010-September/020281.html
Dyalog stores code points directly using 1-, 2-, or 4-byte unsigned
integers. The type for a given array has to fit all the characters, and
we try to choose the smallest possible. I'm not sure how good our
surrogate pair handling is, but I think they are supposed to be combined
into single
Two instructions but one of them's slow. I found the test
a+b == (a>b?a:b) on unsigned integers to be slightly faster in a loop
with independent iterations and significantly faster when a loop
dependency is introduced. However, a solution with two branches was
usually faster than either.
I loaded
This is a perfectly good use of the forums in my book. At the very
least, we've had similar posts before and no one's complained.
Overall your program looks pretty good to me. It's not leveraging the
Full Power of J™, but it's a great start. You know what I. does!
There are some ways to use
There's no clean way to do it. If the result of the first invocation of
f has the same type as the rest of the list elements, you can do
f/ _2 (}. , f0/@:{.) l
and if it has a different type you can check whether the right argument
has this type (like your "signature structure", but implicit).
The associative lists that Andrew is talking about (also called maps or
dictionaries) are essentially the same as JSON objects (more precisely,
JSON objects are maps whose keys are strings). There's no need for them
to be used in a particularly low-level way, although the primitives used
to
And for computing large Cantor sets really fast, you can use a recursive
method:
c0 =. 3 :', */&1 0 1^:y 1'
c1 =. 3 :', (*/~(3^y-2^l)&{.) , */~^:(l=.<.2^.y) 1 0 1'
(c0 -: c1) 18
1
10 (6!:2) 'c0 18'
1.22999
10 (6!:2) 'c1 18'
0.0728543
The J solution makes it easy to figure this
Without any comments, and only the knowledge that it computes
Pythagorean triples, I was able to read and understand that code
completely in about four minutes. Reading line two right to left, I
decided the result was the primitive triples with sum less than or equal
to y just before getting to
The reason J has no nullary (niladic, in APL terminology) functions is
that the syntax doesn't support it very well. How do you know when to
evaluate a niladic function? If f is a regular (monadic or dyadic,
depending on context) functions and nil is niladic, is (f@:nil) the same
as ([: f nil)?
There is a way: you transpose the argument array, apply the desired
operation, then possibly transpose the result (as Brian's answer
indicates). An efficient implementation would do this under the covers
anyway for nearly all of the column-wise operations that can't be
implemented using rank.
The
t value will
> ever leak in, in some J version.
>
> Thanks,
>
> --
> Raul
>
> On Thu, Nov 9, 2017 at 1:40 PM, Marshall Lochbaum <mwlochb...@gmail.com>
> wrote:
> > Actually, the domain error thing gives me an idea:
> >
> > numeric =: (1[[:+''($,
Actually, the domain error thing gives me an idea:
numeric =: (1[[:+''($,)]) :: 0:
numeric i.3 5
1
numeric <2 3
0
numeric 'abcd'
0
Reshape to scalar, attempt to apply complex conjugate, and then return
1. If conjugate failed, return 0. You could skip the reshape, yielding
((1[+) ::
I doubt you'll find a much faster J solution than:
,(+/~10&*)/ 4#,:>:i.6
or the uglier but slightly quicker
,+// (10<.@^i._4)*/>:i.6
Marshall
On Tue, Oct 03, 2017 at 03:16:41PM -0500, Skip Cave wrote:
> Another interesting Quora problem:
>
> Given the integers from 1000 to , remove all
rshall
On Sun, Sep 24, 2017 at 09:14:28AM +0100, Marshall Lochbaum wrote:
> Try
>
> rng =: ] #~ 1=I.
>
> it's about half as fast because I. is not very well-optimized.
>
> Marshall
>
> On Sun, Sep 24, 2017 at 02:29:31AM -0500, Skip Cave wrote:
> > Here's a fu
Try
rng =: ] #~ 1=I.
it's about half as fast because I. is not very well-optimized.
Marshall
On Sun, Sep 24, 2017 at 02:29:31AM -0500, Skip Cave wrote:
> Here's a function I came up with to select numbers in a vector which are
> within some range.
>
> Find all the numbers between 10 & 100 in
onal
> mathematics. In any case are you saying that if code is rarely used then it
> is acceptable for it to deliver the wrong answer? I reiterate my previous
> point that a wrong answer is still wrong even when delivered efficiently.
>
> Regards, Rob
>
>
> > On 7
Primality testing is a much less common use case than you think, and in
fact I'm not aware of any use for extended-precision integers outside of
recreational mathematics (I guess you can count cryptography, but anyone
using extended-precision integers instead of large fixed-width integers
for that
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
No, the brief answer is that Jsoftware does not believe that unicode
identifiers are a good addition to the language. While it's certainly
possible for such identifiers to become confusing if exotic characters
are used, they are supported in Unbox (https://github.com/iocane/unbox,
a fork of J
Does this scheme support easily assigning a default value to a variable,
that is, assigning only if the name is currently unused? This is a
common case for me and I'm just now realizing that the "default" option
doesn't really do that.
See https://github.com/mlochbaum/JSound/blob/master/wav.ijs
All (I.)s used in my post refer to the monad. I meant that the monadic
verb given by binding my dyadic verb to a left argument (which must be
(i.n) for a large enough n) is a mostly-inverse to (I.). It's probably
best to ignore my informal discussion if you plan on implementing this.
There's a
> 102 30
> 104 31
> 106 19
> 108 10
> 110 4
> 112 3
> 114 3
> 116 2
> 118 2
> 120 2
> 122 3
> 124 4
> 126 11
> 128 23
> 130 28
> 132 33
> 134 43
> 136 46
> 138 57
> 145 23
> 150 2
>
>
>
> On Tue, Jun 27, 2017 at 4:20 A
My answer was intended to help you find the optimal threshold to use.
You are trying to interpret it as a way to measure how good a given
threshold is. It turns out that the computations you did contain that
information, but my method is much faster than checking each individual
threshold.
The
A common strategy that may work for you is just to ignore the spacial
data and perform some sort of clustering (like k-means, with k=2) on the
intensities. Then classify pixels according to which cluster they fall
in.
An approach that does use this data, and which I expect would be much
slower
Pascal's answer is fairly good, but this touches on an important change
and I think the mailing list should get a more comprehensive
description:
J's arrays are immutable in normal use. When you write (2 (7}) a), J
makes a new copy of (a), changes the value at index 2 to a 7, and
returns that
Perhaps easier to see with more formal/expressive verbs:
in =. 1 :'[,'' '',u,'' '',]' NB. String to infix function
('f0'in)`('f1'in)`('f2'in)/ 'abcde'
a f0 b f1 c f2 d f0 e
The verbs in the gerund are arranged from left to right starting at the
beginning of the array, while application (as
I'm assuming there are a lot of missing newlines in your sample output,
and it should actually be a shape 3 5 5 array. Here's a solution which
uses rank many times:
(3 5 5$0) ]"0"1 0"2 1 i.5
0 0 0 0 0
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
0 0 0 0 0
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
0
_1|.-.@]) [:>/\.&.|. 2 =/\ ,&_1
mergerow $0
$mergerow $0
0
Marshall
On Tue, Jun 07, 2016 at 06:12:54PM -0400, Marshall Lochbaum wrote:
> Unpredictable behavior? The second version of mergerow seems like it
> should give exactly the same results as the first. Any problems it
>
Since Dan and Raul seem to have given up the quest for fewer characters,
here's 21:
v;._1 ' Spoiler follows ... ...'
S p o i l e r
S p o i l e
S p o i l
S p o i
S p o
S p
S
f o l l o w s
f o l l o w
f o l l o
f o l l
March 16, 2016 7:41 AM
> Subject: Re: [Jprogramming] A clever way to find the maximum possible integer
>
>
> 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, 201
J's architecture is not set up for tail call elimination and it would be
very difficult to implement.
I would just use an explicit while loop for functions that need to do
something random until a condition is met. It's not very natural to use
(?) to determine control flow in a tacit function
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
Although it's perhaps not as important early on as Henry's excellent
advice, I would like to advocate for good use of whitespace and grouping
in J programming. Putting less space around parts which are evaluated
first (generally adverbs) and more around those which are evaluated last
makes it a
Maybe "reading order"? Left-to-right, top-to-bottom as displayed by J.
It's probably worth noting for those looking for more specificity that
(,) is equivalent to (,/^:_), at least if the rank is greater than zero.
Marshall
On Thu, Mar 10, 2016 at 06:58:09PM -0500, Henry Rich wrote:
> You're
For CSV/JSON loading and storing, I think the best approach would be to
write C functions that convert these formats to and from J nouns. A J
noun is the type A from jtype.h (line 41), and you can use that header
or pieces of it directly. Then just call the shared library from J. This
could be
The best rational approximations to a number can be obtained from its
continued fraction representation. Simply truncating the continued
fraction gives a smaller list of approximants which are accurate
relative to the size of their denominators, and truncating and possibly
reducing the last number
I finally got unicode identifiers working with full test compliance.
Every unicode character is treated as an alphabetic, and invalid UTF-8
gives a spelling error.
]π2 =. 1p2
9.8696
%: π2
3.14159
Do you want this in unbox's master branch? If so I'll send a pull
request. The code is at
Over here:
https://github.com/iocane/unbox
It's a fork of J which (as the name suggests) is open to more
adventurous experiments than the version distributed by Jsoftware.
Marshall
On Tue, Mar 08, 2016 at 03:55:18PM -0500, Devon McCormick wrote:
> I guess I missed it but "Unbox" is...?
>
> On
Using sort instead of amend makes it easy to turn this into a tacit
verb:
x=: 5 6 ?@$ 100
x -: ($x) ([ $ (/:&; ./) #@>) : ([ $ (/:&; Assuming you know the shape of the original argument:
>
>x=: 5 6 ?@$ 100
>x -: (;$x)} 5 6$0
> 1
>
> Deriving the shape of the original x from the
If u is (+/@:*:), then (u D. 1) returns a vector, not a matrix. From
your first email it looked like you wanted to find a zero of
(+/@:*: D. 1), that is, minimize (+/@:*:). multinewt works for that
case:
+/@:*: D. 1 multinewt (<5) 3 4
3 4
_0.142552 _0.0529989
0.00158427
dify.
>
> Henry Rich
>
> On 2/6/2016 4:38 PM, Marshall Lochbaum wrote:
> >Based on the recent discussions about integers and floats, I decided to
> >make a general tool to convert between various J types. It's hosted
> >here:
> >
> >https://github.com
Based on the recent discussions about integers and floats, I decided to
make a general tool to convert between various J types. It's hosted
here:
https://github.com/mlochbaum/JScripts/blob/master/Misc/typecast.ijs
The script defines typecast, a verb to convert between types while
maintaining J
|asf|||4|+-+-+|||@|+--+-+|| |
> |+-+---+|| ||/|\ ||+:|+||| |
> | || |+-+-+||| |+--+-+|| |
> | |+-+-+|+-+--+| |
> +---+-+------+-+
>
> '/\' toG
> +-+
> |+-+-+|
> ||4|+-+-+||
> || ||/|\|||
> || |+-+-+||
> |+-+-+|
> +-+
>
> 3 toG
> +-+
> |+
I certainly agree that Dan's requested feature shouldn't be J's default
behavior. The result of an arithmetic operation should follow from the
behavior of the relevant datatype (here, IEEE float) and the type
conversion rules.
I sent an email about the problem of coercion to integer a month ago;
4>:3!:0)^:_ ]_1
Marshall
On Wed, Feb 03, 2016 at 07:30:22PM -0500, Raul Miller wrote:
> On Wed, Feb 3, 2016 at 5:19 PM, Marshall Lochbaum <mwlochb...@gmail.com>
> wrote:
> > I sent an email about the problem of coercion to integer a month ago; my
> > recommendation wa
It's not surprising at all if you know a little bit about how the verbs
in question work. Dyad (,) creates a new array and copies its arguments
into it. Thus computing (a,b,c) requires the steps:
- Copy b and c into new array t1 (2e6 copy operations)
- Copy a and t1 into new array t2 (3e6 copy
(y i. y){/:/:y'
> >>>>> g=: 13 :'((f x)>: (( ~.y)i.x){(#/.~y),0: y)#x'
> >>>>> A g B
> >>>>> cab
> >>>>> f
> >>>>> ([: /: /:) - i.~ { [: /: /:
> >>>>> g
> >>>>> [ #~ ([: f
gt;>>> f
> >>>>([: /: /:) - i.~ { [: /: /:
> >>>> g
> >>>>[ #~ ([: f [) >: ([ i.~ [: ~. ]) { ([: #/.~ ]) , [: 0: ]
> >>>>
> >>>>Linda
> >>>>
> >>>>-Original Message
That's a very cool solution, and much quicker than the one based on
progressive index-of. Instead of taking the occurrence count of both x
and y, it just takes the count for x and compares it to the total number
of occurrences in y, given by (#/.~).
Here's a comparison of the two methods. It
I don't see an answer there. It's important for users to be able to
clone, rather than just download, the repository, so that they are able
to update it easily and quickly. Then people who want to use the latest
J source can stay up to date and test out changes before they are
published in an
Roger got it first, but I wrote a little more than he did, so here it
is:
This is a very difficult problem in J, and a reasonably good candidate
for a language primitive. This essay describes a very similar problem
whose solution is slightly more powerful:
_
> >. roundA _ 234234.3 __
>
> - Original Message -
> From: Marshall Lochbaum <mwlochb...@gmail.com>
> To: programm...@jsoftware.com
> Sent: Thursday, January 14, 2016 2:56 PM
> Subject: [Jprogramming] Round to nearest integer: harder than it seems
>
> Here's
; increment, i.e. "1" for whole numbers or "0.05" for nickels, as this is
> intuitive and flexible.
>
> On Thu, Jan 14, 2016 at 7:01 PM, Marshall Lochbaum <mwlochb...@gmail.com>
> wrote:
>
> > Actually, you're off by one on the low end--a quirk of two'
Here's something I spent far too long on, and consequently thought was
worth sharing. I can turn it into an essay on the J wiki if people want
that.
Recently I ran into the problem of rounding a J floating point number to
an integer, and forcing the result to have integer type. This seems like
a
raints you
> leave values in whatever format they arrived in.
>
> Anyways... interesting chain of thought...
>
> Thanks,
>
> --
> Raul
>
> On Thu, Jan 14, 2016 at 7:01 PM, Marshall Lochbaum <mwlochb...@gmail.com>
> wrote:
> > Actually, you're off
I've used (00) a few times to make an empty array a given shape
(usually followed by an invocation of }). However, (0$~$) is not much
longer and I find that it better explains what I am trying to do.
Marshall
On Sun, Aug 09, 2015 at 02:45:11PM -0400, Raul Miller wrote:
Conciseness?
I guess
That's pretty clever. I like using
(#~2|i.@#) : (;:'a b c d'),].p:p:p:i.4 4
│a │b │c │d │
│13 │19 │43 │71 │
│163 │193 │293 │359 │
│463 │619 │743 │971 │
│1091│1181│1423│1601│
although now that it's come up, I realize (_2{:\}: : ...) is a little
shorter. Either way, it lets you
Note that (#~/@:|:) is a much faster inverse.
Marshall
On Mon, Jun 29, 2015 at 04:22:08PM +, 'Pascal Jasmin' via Programming wrote:
pretty much the same as the rosettacode solution, but focused on an internal
representation rather than outputting a string
torle =: (1 ,~ 2(~:/\)) ({. ,
Short answer: there is no efficient way (and I find this to be a huge
problem).
The most recent thread on this topic is here:
http://jsoftware.com/pipermail/programming/2015-February/041005.html
Marshall
On Tue, Jun 23, 2015 at 01:53:36AM +, Marshall Bockrath-Vandegrift wrote:
Hi all,
In fact there are just two values: the one with index returned by I. and
the one before it. The following version returns a single value,
breaking ties by choosing the smaller element:
nearest =: ] (] {~ [: / |@-) (_,~[) {~ (,~:)@:I.
1 5 8 9 nearest 4
5
1 5 8 9 nearest _3
1
1 5 8 9
1 - 100 of 156 matches
Mail list logo