Hi all !

I never understood why J programmers prefer -@:-@:-@:- ] over [: - [: - [: - [: - ]. The @: is replaced by the code in o below. The resulting code to parse in the first example will be(the third line):
o=: 2 : '[: u v'

-o-o-o- ]

([: ([: ([: - -) -) -) ]

These are not normal brackets, these are single verbs. Each pair of brackets is a redundant creation of a single verb.
The difference in performance is nowadays small though.
When you create a tacit program, you usually put the operations in execution order. You then have a strawman, the second notation. You say that the program is curried. Then you decurrie it, you make the f(g(h(i(x))) composition execute starting with f. Very much more complicated, it seems, but if you only remember that the result is the same as the corresponding strawman, you are OK. You can get away without understanding how it works. Well, and you save a lot of blanks. The blanks which by convention are required between verbs.
All clear?

Cheers,

Erling Hellenäs

On 2017-10-15 22:05, Erling Hellenäs wrote:
J programmers are a special kind of programmers who create built in functions to save a blank. One of the few rules of J programming used to be to separate verbs by a blank.
Without separation:
1+1
>:1
With separation:
1 + 1
>: 1
One blank shorter.
/Erling

On 2017-10-15 21:38, 'Mike Day' via Chat wrote:
Not only Bayes - here's the shared Birthday Paradox,  sometimes used to impress or
amaze classes at school.   It's classical stats,  I think!

Probability of two or more children in a sample of 22 or 23 sharing a birthday,
assuming no leap-day birthdays,  no twins,  etc.

Required probability =
(1 - probability of no-one sharing a birthday)  =
    1 * prob second different from first
       * prob third different from first two....
    = 1 (364/365) (363/365) ...
    = (1 - 0%365) (1 - 1%365) (1 - 2%365) ...

     * &. -. / 365%~ i.22     NB.  for 22 -  not quite 50-50
0.475695

    * &. -. / 365%~ i.23     NB. for 23 - just over 50-50
0.507297

   */ &.: -.   also works and is faster,  but is more of a variant from Raul's example
eg
    */ &.: -. 365%~i.23

0.507297



Perhaps redundancy is the reason for Linda Alvord's objection to @ and @:  ?

Mike





On 15/10/2017 17:04, Raul Miller wrote:
It's interesting to note how J includes a fair bit of redundancy

For example, we have - but we also have <: (which is -&1) and we have
-. (which is 1&-). Why do we have these?

Primarily, for educational contexts. It can be useful when teaching
people to have specific words for commonly used operations.

The underlying principle here, I think, is one of giving people
multiple perspectives when relaying a concept. I think the hope is
that at least some of it will "stick".

But, also, for example, using -. for logical negation segues easily
into bayesian probability. There, we do not simply have 1 and 0 for
true and false, but we have a whole range of probabilities in between.
We can keep using -. for logical negation (it becomes the probability
of the event NOT happening), but we have to switch from *. to * for
combing events.

If A and B are independent probability variables then A*B is the
probability that both are true. Similarly, if A and B are logical
variables, then A*B is true if and only if both A and B are true. We
can use * for logical AND. But the corresponding OR statement would be
*&.-.

And J does not define that "bayesian OR" as a primitive, perhaps in
part to emphasize the need for understanding its derivation, perhaps
in part because it's only 5 characters already to get the
implementation and perhaps in part to emphasize the divide between
probability and logic.

Anyways, without -. we would instead need *&.(1&-) which is just a bit
more unwieldy (but which, ok, would still work).

Food for thought, perhaps...

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

Reply via email to