Four bit adder: Difference between revisions

J: the natural implementation
(Embed images, rather than link them.)
(J: the natural implementation)
Line 86:
return 0;
}</lang>
 
=={{header|J}}==
 
<lang j>and=: *.
or=: +.
not=: -.
xor=: (and not) or (and not)~
hadd=: and ,"0 xor
add=: ((({.,0:)@[ or {:@[ hadd {.@]), }.@])/@hadd</lang>
 
Example use:
<lang j> 1 1 1 1 add 0 1 1 1
1 0 1 1 0</lang>
 
 
===Glossary===
~: xor
{. first
}. rest
{: last
[ left
] right
0: function which always has the result 0
, combine sequences
 
===Meta glossary===
u v w verbs such as and or or not
x y nouns such as 1 or 0
u@v function composition
u/ reduction
u"0 u applies to the smallest elements of its argument
 
Also:
x (u v) y
produces the same result as
x u v y
 
while
x (u v w) y
produces the same result as
(x u y) v (x w y)
 
See also: "A Formal Description of System/360” by Adin Falkoff
6,962

edits