develooper Front page | perl.perl6.language | Postings from May 2005

Re: reduce metaoperator on an empty list

Thread Previous | Thread Next
From:
Edward Cherlin
Date:
May 19, 2005 02:46
Subject:
Re: reduce metaoperator on an empty list
Message ID:
200505190250.29771.cherlin@pacbell.net
On Wednesday 18 May 2005 17:57, Matt Fowles wrote:
> All~
>
> What does the reduce metaoperator do with an empty list?

Here is the last answer from Ken Iverson, who invented reduce in 
the 1950s, and died recently.
file:///usr/share/j504/system/extras/help/dictionary/intro28.htm
Identity Functions and Neutral

The monads 0&+ and 1&* are identity functions, and 0 and 1 are 
said to be identity elements or neutrals of the dyads + and * 
respectively. Insertion on an empty list yields the neutral of 
the dyad inserted. For example:

   +/ i.0         +/''           +/0{. 2 3 5
0              0              0

   */i.0          */''           */0{. 2 3 5
1              1              1

> my @a;
> [+] @a; # 0? exception?
> [*] @a; # 1? exception?
> [<] @a; # false?
> [||] @a; # false?
> [&&] @a; # true?
>
> Also if it magically supplies some correct like the above, how
> does it know what that value is?
>
> Thanks,
> Matt

The page
file:///usr/share/j504/system/extras/help/dictionary/d420.htm
gives examples, unfortunately not easily readable ones.

"If y has no items (that is, 0=#y), the result of u/y is the 
neutral or identity element of the function u. A neutral of a 
function u is a value e such that x u e ↔ x or e u x ↔ x, for 
every x in the domain (or some significant sub-domain such as 
boolean) of u .  This definition of insertion over an argument 
having zero items extends partitioning identities of the form 
u/y ↔ (u/k{.y) u (u/k}.y) to the cases k e. 0,#y .

"The identity function of u is a function ifu such that ifu y ↔ 
u/y if 0=#y ."

[The following table is greatly simplified by listing identity 
elements rather than identity functions. Some are only left 
identities, and some only right identities.]

Identity element 	For
 
0				<  >  +  -  +.  ~:  |  (2 4 5 6 b.)
1 				=  <:  >:  *  %  *.  %:  ^  !  (1 9 11 13 b.)
_				<.
__				>.
''			 	,
[and a few more that I will not explain here]

Glossary
J	Description
+.	or
~:	objects are identical
|	remainder, defined so that 0|N is N
b.	Boolean functions from table 
<:	less than or equal, restricted to Booleans here 
		(1<:0 is 0, 1<:1 is 1)
>:	greater than or equal, restricted to Booleans here
*	times, restricted to Booleans here
%	divide
*.	and
%:	root
^	exponential
!	combinations
<.	minimum
>.	maximum
''	empty vector, list of length 0
,	catenate, join lists
_	infinity
__	negative infinity

So (_ <. N) is N, as is (__ >. N).
All of these functions are defined in detail but quite tersely in 
the J Dictionary, indexed on the page
file:///usr/share/j504/system/extras/help/dictionary/vocabul.htm
For examuple, the Boolean function b. is defined on the page 
file:///usr/share/j504/system/extras/help/dictionary/dbdotn.htm

-- 
Edward Cherlin
Generalist & activist--Linux, languages, literacy and more
"A knot! Oh, do let me help to undo it!"
--Alice in Wonderland
http://cherlin.blogspot.com

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About