Calling J from Python

H

hg

Bjoern said:
The only one I see at the moment is that they're both some kind of
programming languages.


Sure.

Mh, just looking at some "advanced" J source taken from
wikipedia.org makes me feel sick:

| Here's a J program to calculate the average of a list of numbers:
| avg=: +/ % #
| avg 1 2 3 4
| 2.5

In the meantime, do you now have an answer to why we should care?

Regards,


Björn


Be nice !
 
B

Bjoern Schliessmann

Gosi said:
J is in many ways similar to Python.

The only one I see at the moment is that they're both some kind of
programming languages.
J has very many advanced operations.

Sure.

Mh, just looking at some "advanced" J source taken from
wikipedia.org makes me feel sick:

| Here's a J program to calculate the average of a list of numbers:
| avg=: +/ % #
| avg 1 2 3 4
| 2.5

In the meantime, do you now have an answer to why we should care?

Regards,


Björn
 
S

skip

Gosi> J is in many ways similar to Python.

Gosi> J has very many advanced operations.

Gosi> http://www.jsoftware.com/

Doesn't look like open source of any variety. If a person uses Python with
various add-ons (RPy, numpy, matplotlib, etc) why would they want to switch
to a closed source product?

Skip
 
D

Diez B. Roggisch

Gosi said:
J is in many ways similar to Python.

J has very many advanced operations.

What exactly do you call "similar to python" when the following is a program
written in it? Compared to that, even Perl is a wonder of readability...

m =: >@(0&{)
v =: >@(1&{)
h =: >@(2&{)
qu =: >@(3&{)
z =: i.@0:
ret =: |.@}:
init =: z;z;z;i.
f1m =: (m,{.@qu);v;h;}.@qu
f5m =: (z;(v,{:mad:m);h;qu,ret@m) @ (f1m^:5)
f1h =: (z;z;(h,{:mad:v);(qu,ret@v)) @ (f5m^:12)
f12h =: (z;z;z;qu,ret@h,{:mad:h) @ (f1h^:12)
perm =: qu @ f12h @ init
ord =: *./ @ (#&>"_) @ C.
days =: -: @ ord @ perm


http://www.jsoftware.com/jwiki/Essays/The_Ball_Clock_Problem


Diez
 
D

Dennis Lee Bieber

Mh, just looking at some "advanced" J source taken from
wikipedia.org makes me feel sick:

| Here's a J program to calculate the average of a list of numbers:
| avg=: +/ % #
| avg 1 2 3 4
| 2.5
That looks like some variation of APL
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
D

Dennis Lee Bieber

What exactly do you call "similar to python" when the following is a program
written in it? Compared to that, even Perl is a wonder of readability...

m =: >@(0&{)
v =: >@(1&{)
h =: >@(2&{)
qu =: >@(3&{)
z =: i.@0:
ret =: |.@}:
init =: z;z;z;i.
f1m =: (m,{.@qu);v;h;}.@qu
f5m =: (z;(v,{:mad:m);h;qu,ret@m) @ (f1m^:5)
f1h =: (z;z;(h,{:mad:v);(qu,ret@v)) @ (f5m^:12)
f12h =: (z;z;z;qu,ret@h,{:mad:h) @ (f1h^:12)
perm =: qu @ f12h @ init
ord =: *./ @ (#&>"_) @ C.
days =: -: @ ord @ perm
I retract my APL comment... APL is clean compared to that...

Are there /any/ keywords in that language? Apparently {, } are
operators and delimiter pairs.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
A

Alexander Schmolck

Gosi> J is in many ways similar to Python.

Gosi> J has very many advanced operations.

Gosi> http://www.jsoftware.com/

Doesn't look like open source of any variety. If a person uses Python with
various add-ons (RPy, numpy, matplotlib, etc) why would they want to switch
to a closed source product?

You wouldn't, if for nothing else because python has far better scientific
libraries. If you've got an interest in programming languages as such J (or
some other APL) is worth a look though; it's also handy for quick mathematical
experimentation (J's array primitives are more expressive than what numpy
offers and python doesn't support rationals, so it's not just concise due to
perl-style crypticness). For example I once wrote this (slow) code to display
part of a mandelbrot fractal:

load'viewmat'
viewmat+/2&>:|((j.~/~(%~i:)99)&+@:*:)^:(i.32)0

It'll likely require you more typing in python, but then you'd need to do such
things quite a lot for seeing an amortization in terms of less time spent with
your PC; I think most people will find they need a seizable learning
investment to get anywhere with J and python already is very expressive for
the kind of things J is good at.

'as
 
L

Larry Bates

Bjoern said:
The only one I see at the moment is that they're both some kind of
programming languages.


Sure.

Mh, just looking at some "advanced" J source taken from
wikipedia.org makes me feel sick:

| Here's a J program to calculate the average of a list of numbers:
| avg=: +/ % #
| avg 1 2 3 4
| 2.5

In the meantime, do you now have an answer to why we should care?

Regards,


Björn
And why is that superior to this:

def avg(l):
return float(sum(l))/len(l)
2.5


Which can actually be read and debugged in the future!

-Larry
 
R

Robin Becker

Dennis said:
That looks like some variation of APL

my colleague informs me that it is indeed associated with some of the same
people if not with Mr Iverson.
 
A

Alexander Schmolck

Robin Becker said:
my colleague informs me that it is indeed associated with some of the same
people if not with Mr Iverson.

The late Ken Iverson designed both J and APL (he has also written an number of
freely downloadable math books using J, see jsoftware.com).

'as
 
A

Alexander Schmolck

Larry Bates said:
And why is that superior to this:

def avg(l):
return float(sum(l))/len(l)
2.5

Apart from being less to type and it is superior in that it's generalizes much
better, e.g:

avg&.^. NB. geomtric mean
avg&.% NB. harmonic mean
avg M NB. column mean of matrix M
avg"1 M NB. row mean of matrix M

'as
 
L

Laurent Pointal

Diez said:
m =: >@(0&{)
v =: >@(1&{)
h =: >@(2&{)
qu =: >@(3&{)
z =: i.@0:
ret =: |.@}:
init =: z;z;z;i.
f1m =: (m,{.@qu);v;h;}.@qu
f5m =: (z;(v,{:mad:m);h;qu,ret@m) @ (f1m^:5)
f1h =: (z;z;(h,{:mad:v);(qu,ret@v)) @ (f5m^:12)
f12h =: (z;z;z;qu,ret@h,{:mad:h) @ (f1h^:12)
perm =: qu @ f12h @ init
ord =: *./ @ (#&>"_) @ C.
days =: -: @ ord @ perm


http://www.jsoftware.com/jwiki/Essays/The_Ball_Clock_Problem


Diez

Why dont they call it "smiley" ?

Operators: :) :) :eek:) :-$ *<¦:O) XD -_- +_+ ^_^ *_* !_!
_< =_= o_o X_X -_o ;) $_$ <_< >_> o_0
<_>< ?_? '_' O.O $.$ T.T ._. u.u >-<" =] {-_-}


(source: http://en.wikipedia.org/wiki/Smiley )
 
B

Bjoern Schliessmann

Alexander said:
Apart from being less to type

Cool. Less to type.
and it is superior in that it's
generalizes much better, e.g:

avg&.^. NB. geomtric mean
avg&.% NB. harmonic mean
avg M NB. column mean of matrix M
avg"1 M NB. row mean of matrix M

Is there any regularity in this? If it is, it's not obvious at all.

Regards,


Björn
 
A

Alexander Schmolck

Bjoern Schliessmann said:
Cool. Less to type.

Yes. Readability is more important in many context, but for something designed
for interactive experimentation and exploration little typing is absolutely
essential. Would you use a calculator that would require Java-style
boilerplate to add two numbers?

I'd also venture that readability and typing ease are typically closely
positively correlated (compare python to C++) and although I would not claim
that J is particularly readable I'm also not an expert user (I doubt I would
even then, but I'm sure it *does* make a difference).
Is there any regularity in this? If it is, it's not obvious at all.

Sure. ``f&.g`` is like ``(f o g) o g^-1`` in common mathemetical notation.
``^.`` is log and ``%`` is inversion/division. Making ``&.`` (it's called
"under") available as a convenient abstraction is IMO one really useful
innovation of J.

As for the remaing two: it's similar to numpy in that one and the same
function can normally operate on arrays of different dimensions (including
scalars). In numpy you'd also write stuff like ``mean(M, axis=1)``, it's not
exactly the same, although the axis abstraction comes from APL (another cool
idea), J introduces a slightly different approach. The ``"1`` means "operate
on cells of rank 1" (i.e. vectors), rather than "operate along a certain
axis". For dyadic (2-argument) functions you can also specify different left
and right rank, so you could write the outerproduct v'w thus: ``v *"0 1 w``
(multiply each 0-cell (i.e scalar) of v with each 1-cell (i.e. vector, there
is only one) of w). Unlike the linear algebra notation this readily
generalizes to more than 1 dimensional objects.

BTW I don't think J is an ideal language, not even for numerical computing --
there are plenty of things I'd do differently and that includes measures that
would IMO greatly aid readability (like getting rid of "ambivalence"[1]). But
I have little doubt that, no matter what its flaws may be, APL (and J is
really just an updated, ASCII-based APL) is one of the most innovative and
important programming languages ever conceived. Anyone interested in the
design of programming language for scientific computing ought to take a look
at at least a look at it or one of its descendants.

'as

Footnotes:
[1] Basically almost every J function has a completely different meaning
depending on whether you use it as a unary or binary function (just as
conventionally "-" is abusively used for both substraction and negation).
 
J

John Salerno

Alexander said:
Would you use a calculator that would require Java-style
boilerplate to add two numbers?

This isn't a Java newsgroup, so your metaphor is irrelevant. People use
Python because it *isn't* Java and does not succumb to the problem you
seem to be accusing it of.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top