[Jprogramming] Sum of empty vector

Oleg Kobchenko olegykj at yahoo.com
Mon Jul 10 02:18:41 HKT 2006


>From Insert in Dictionary:
 
    If y has no items (that is, 0=#y), the result of u/y is the 
    neutral or identity element of the function u.
 
Basic Characteristics (b.) gives the identity functions
 
   b=. 3 : '".y,'' b. 1'''
   (,. b&.>) +`*`+.`*.`>.`<.
+--+----------+
|+ |0 $~ }.@$ |
+--+----------+
|* |1 $~ }.@$ |
+--+----------+
|+.|0 $~ }.@$ |
+--+----------+
|*.|1 $~ }.@$ |
+--+----------+
|>.|__ $~ }.@$|
+--+----------+
|<.|_ $~ }.@$ |
+--+----------+
   +/0 2 3$0
0 0 0
0 0 0
   >./0 2 3$0
__ __ __
__ __ __

If you were to implement Insert, it would use
the identity element as initializer:
 
ins=: 1 : 0
  ".'id=.',u b. 1
  r=. id y
  for_i. |.y do. r=. i u r end.
)
 
   + ins 1 2 3
6
   + ins ''
0
   + ins i.3 4
12 15 18 21
   +/ i.3 4
12 15 18 21
   + ins 3 4$0
0 0 0 0
   +/ 3 4$0
0 0 0 0


----- Original Message ----
From: Anssi Seppälä <anssi.seppala at enease.fi>
To: Programming forum <programming at jsoftware.com>
Sent: Sunday, July 9, 2006 12:23:00 PM
Subject: [Jprogramming] Sum of empty vector


Working with practical statistics and samples that can be also empty 
I find  that J follows a kind of logic that is uncomfortable. Taking 
a empty vector 0$0 (empty sample) :

    +/0$0    NB. sum of empty sample is zero !
0

    (+/ % #) 0$0    NB. mean of empty sample is also zero !
0

I wonder why (+/0$0)  could not be 0$0 instead of 0 ?

Anssi

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


More information about the Programming mailing list